{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "990ef513",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\tHAC-T\t\t|\t\tDBSCAN\n",
      "size\ttime\tnclust\tndist\t|\ttime\tnclust\tndist\n",
      "1K\t0.2119\t82\t300909\t|\t0.8139\t82\t1046895\n",
      "2K\t0.6231\t163\t900364\t|\t3.4345\t163\t4187002\n",
      "3K\t1.2171\t230\t1705648\t|\t7.3685\t231\t9257878\n",
      "4K\t1.8754\t285\t2717129\t|\t13.6456\t285\t16694273\n",
      "5K\t2.7707\t335\t3921455\t|\t20.6999\t336\t25877733\n",
      "6K\t3.8819\t390\t5447225\t|\t29.3395\t391\t37019158\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 17424 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from pylib.tlsh_lib import *\n",
    "from pylib.hac_lib  import *\n",
    "import time\n",
    "\n",
    "# (tlist, labelList) = tlsh_csvfile(\"dataDir/mb_10K.csv\")\n",
    "\n",
    "print(\"\\t\\tHAC-T\\t\\t|\\t\\tDBSCAN\")\n",
    "print(\"size\\ttime\\tnclust\\tndist\\t|\\ttime\\tnclust\\tndist\")\n",
    "\n",
    "largeK = 7\n",
    "hac_time = [0] * (largeK)\n",
    "dbs_time = [0] * (largeK)\n",
    "\n",
    "for size in range(1, largeK):\n",
    "    datafile = \"dataDir/mb_\" + str(size) + \"K.csv\"\n",
    "    (tlist, labelList) = tlsh_csvfile(datafile)\n",
    "    if (tlist is not None):\n",
    "        hac_resetDistCalc()\n",
    "        tic = time.perf_counter()\n",
    "        hac_res = HAC_T(datafile, CDist=30, step3=0, outfname=\"tmp.txt\")\n",
    "        toc = time.perf_counter()\n",
    "        hac_nDistCalc = hac_lookupDistCalc()\n",
    "        hac_time[size] = toc-tic\n",
    "        htime          = f\"{hac_time[size]:0.4f}\"\n",
    "        hac_nclusters = max(hac_res)\n",
    "        \n",
    "        outfile = \"dataDir/mb_\" + str(size) + \"K_hac-t_out.txt\"\n",
    "        outputClusters(outfile, tlist, hac_res, labelList, quiet=True)\n",
    "        \n",
    "        resetDistCalc()\n",
    "        tic = time.perf_counter()\n",
    "        dbs_res = runDBSCAN(tlist, eps=30, min_samples=2, algorithm='auto')\n",
    "        toc = time.perf_counter()\n",
    "        dbs_nDistCalc = lookupDistCalc()\n",
    "        dbs_time[size] = toc-tic\n",
    "        dtime          = f\"{dbs_time[size]:0.4f}\"\n",
    "        dbs_nclusters = max(dbs_res.labels_)\n",
    "        \n",
    "        outfile = \"dataDir/mb_\" + str(size) + \"K_dbscan_out.txt\"\n",
    "        outputClusters(outfile, tlist, dbs_res.labels_, labelList, quiet=True)\n",
    "        \n",
    "        print( str(size) + \"K\\t\" +\n",
    "                htime + \"\\t\" + str(hac_nclusters) + \"\\t\" + str(hac_nDistCalc) + \"\\t|\\t\"\n",
    "              + dtime + \"\\t\" + str(dbs_nclusters) + \"\\t\" + str(dbs_nDistCalc)  )\n",
    "    # end if\n",
    "# end for\n",
    "\n",
    "srange = [x for x in range(0, largeK*1000, 1000)]\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "line1, = plt.plot(srange, hac_time,  label='HAC-T')\n",
    "line2, = plt.plot(srange, dbs_time,  label='DBSCAN')\n",
    "plt.legend(handles=[line1, line2], loc='upper left')\n",
    "plt.xlabel('Size dataset', fontsize=15)\n",
    "plt.ylabel('time (sec)', fontsize=15)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "765b8c79",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c1d9e09",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
