{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e0489aae-14a0-4e47-98fe-0ebbf904d94c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from quasinet.qnet import qdistance, load_qnet\n",
    "import joblib\n",
    "#import cognet.util\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from io import BytesIO, StringIO\n",
    "import pickle\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c6288388-6edb-4d05-8ae8-71776cd81d77",
   "metadata": {},
   "outputs": [],
   "source": [
    "#qnet_ = joblib.load(\"https://zenodo.org/record/5781768/files/gss_2018.joblib\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2fff8539-0d2d-479a-9187-4b49f159f6ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "# loading qnet object from zenodo\n",
    "url = 'https://zenodo.org/record/5781768/files/gss_2018.joblib'\n",
    "url_file = BytesIO(requests.get(url).content)\n",
    "Z_qnet = joblib.load(url_file)\n",
    "# import org.apache.commons.io.FileUtils\n",
    "\n",
    "# FileUtils.copyURLToFile(url, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b1735156-cc35-4ac9-97f6-c89e9e72f357",
   "metadata": {},
   "outputs": [],
   "source": [
    "Z_qnet = load_qnet(url_file)\n",
    "#Z_qnet = joblib.load(url_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3ce78eb3-2e1b-4d52-9ef7-7267d12b90f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# loading qnet object from local repo\n",
    "L_qnet = load_qnet(\"../../../cognet_scratch/Qnets/gss_2018.joblib\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "067a3d2f-431a-4cc9-9931-79ea6707b002",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>local</th>\n",
       "      <th>zenodo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>wrkstat</td>\n",
       "      <td>wrkstat</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HRS1</td>\n",
       "      <td>HRS1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HRS2</td>\n",
       "      <td>HRS2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>evwork</td>\n",
       "      <td>evwork</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>wrkslf</td>\n",
       "      <td>wrkslf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1029</th>\n",
       "      <td>wtss</td>\n",
       "      <td>wtss</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1030</th>\n",
       "      <td>wtssnr</td>\n",
       "      <td>wtssnr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1031</th>\n",
       "      <td>wtssall</td>\n",
       "      <td>wtssall</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1032</th>\n",
       "      <td>vstrat</td>\n",
       "      <td>vstrat</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1033</th>\n",
       "      <td>vpsu</td>\n",
       "      <td>vpsu</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1034 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        local   zenodo\n",
       "0     wrkstat  wrkstat\n",
       "1        HRS1     HRS1\n",
       "2        HRS2     HRS2\n",
       "3      evwork   evwork\n",
       "4      wrkslf   wrkslf\n",
       "...       ...      ...\n",
       "1029     wtss     wtss\n",
       "1030   wtssnr   wtssnr\n",
       "1031  wtssall  wtssall\n",
       "1032   vstrat   vstrat\n",
       "1033     vpsu     vpsu\n",
       "\n",
       "[1034 rows x 2 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# testing for similarity\n",
    "pd.DataFrame({'local':L_qnet.feature_names,\n",
    "              'zenodo':Z_qnet.feature_names})\n",
    "# for qnet_ in [L_qnet, Z_qnet]:\n",
    "#     qdist = qdistance(qnet_.samples[1], qnet_.samples[2], qnet_, qnet_)\n",
    "#     print('-------------------------------------------')\n",
    "#     print(qdist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "441d674d-3da4-4d6e-82d5-fde49862b520",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "qnet-dev",
   "language": "python",
   "name": "qnet-dev"
  },
  "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.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
