{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as numpy\n", "import os\n", "import sumolib\n", "import copy\n", "from tqdm import tqdm\n", "from datetime import datetime" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1704410400\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
node_idstart_unixphas_Aphas_Bdurationinc_edge_Ainc_edge_Bout_edge_Aout_edge_Bmove_Amove_B
0i117044068401137-571542810_01571542797_02.99-571542797_02.99571542810_0184
1i117044068402293-571542810_01-571542810_01-571542797_02.99571543469_0183
2i117044068403340571543469_02NaN-571542797_02.99NaN518
3i917044068501146571510152_02571510152_01-571510152_01571510152_01.6562
4i9170440685022114NaNNaNNaNNaN1718
....................................
477i617044102004423571500585_02571500585_02571511538_01571500535_0183
478i217044102201140-571542809_01571542811_02571542811_01571542809_0184
479i217044102202225571542811_02-571542809_01571542107_01571542809_0173
480i217044102203371NaNNaNNaNNaN1718
481i217044102204434-571542809_01571542107_02571542811_01571542809_0151
\n", "

482 rows × 11 columns

\n", "
" ], "text/plain": [ " node_id start_unix phas_A phas_B duration inc_edge_A \\\n", "0 i1 1704406840 1 1 37 -571542810_01 \n", "1 i1 1704406840 2 2 93 -571542810_01 \n", "2 i1 1704406840 3 3 40 571543469_02 \n", "3 i9 1704406850 1 1 46 571510152_02 \n", "4 i9 1704406850 2 2 114 NaN \n", ".. ... ... ... ... ... ... \n", "477 i6 1704410200 4 4 23 571500585_02 \n", "478 i2 1704410220 1 1 40 -571542809_01 \n", "479 i2 1704410220 2 2 25 571542811_02 \n", "480 i2 1704410220 3 3 71 NaN \n", "481 i2 1704410220 4 4 34 -571542809_01 \n", "\n", " inc_edge_B out_edge_A out_edge_B move_A move_B \n", "0 571542797_02.99 -571542797_02.99 571542810_01 8 4 \n", "1 -571542810_01 -571542797_02.99 571543469_01 8 3 \n", "2 NaN -571542797_02.99 NaN 5 18 \n", "3 571510152_01 -571510152_01 571510152_01.65 6 2 \n", "4 NaN NaN NaN 17 18 \n", ".. ... ... ... ... ... \n", "477 571500585_02 571511538_01 571500535_01 8 3 \n", "478 571542811_02 571542811_01 571542809_01 8 4 \n", "479 -571542809_01 571542107_01 571542809_01 7 3 \n", "480 NaN NaN NaN 17 18 \n", "481 571542107_02 571542811_01 571542809_01 5 1 \n", "\n", "[482 rows x 11 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "midnight = int(datetime(2024, 1, 5, 0, 0, 0).timestamp())\n", "next_day = int(datetime(2024, 1, 6, 0, 0, 0).timestamp())\n", "fmins = range(midnight, next_day, 300)\n", "m = 100 # m ranges from 26 to 287\n", "print(fmins[m])\n", "net = sumolib.net.readNet('../../Data/networks/SN_sample.net.xml')\n", "inter_node = pd.read_csv('../../data/tables/inter_node.csv', index_col=0)\n", "inter_node = inter_node[inter_node.inter_type=='parent']\n", "histid = pd.read_csv(f'../../Data/tables/histids/histids_{fmins[m]}.csv', index_col=0)\n", "histid = histid[histid.inter_no.isin(inter_node.inter_no.unique())]\n", "inter2node = dict(zip(inter_node['inter_no'], inter_node['node_id']))\n", "histid['node_id'] = histid['inter_no'].map(inter2node)\n", "histid = histid[['node_id', 'start_unix', 'phas_A', 'phas_B', 'duration', 'inc_edge_A', 'inc_edge_B', 'out_edge_A', 'out_edge_B', 'move_A', 'move_B']]\n", "histid = histid.reset_index(drop=True)\n", "histid" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['i0', 'i1', 'i2', 'i3', 'i6', 'i7', 'i8', 'i9']\n", "[, , , , , , , ]\n" ] } ], "source": [ "sigtable = histid.copy()\n", "node_ids = sorted(sigtable.node_id.unique())\n", "nodes = [net.getNode(node_id) for node_id in node_ids]\n", "print(node_ids)\n", "print(nodes)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "i0 grrrgrrrgrrrrrgrr\n", "i1 grrrrrrgrr\n", "i2 rrggrrr\n", "i3 grrrrgrrrrgrrrrgrrrr\n", "i6 grrrgrrrrgrrgrrr\n", "i7 rrrggrr\n", "i8 grrrrrrrgrrrgrrr\n", "i9 rrrr\n" ] } ], "source": [ "node2init = {}\n", "for node in nodes:\n", " node_id = node.getID()\n", " conns = [(c.getJunctionIndex(), c) for c in node.getConnections()]\n", " conns = [c for c in conns if c[0] >= 0]\n", " conns = sorted(conns, key=lambda x: x[0])\n", " state = []\n", " for i, ci in conns:\n", " if ci.getTLLinkIndex() < 0:\n", " continue\n", " are_foes = False\n", " for j, cj in conns:\n", " if ci.getTo() == cj.getTo():\n", " continue\n", " if node.areFoes(i, j):\n", " are_foes = True\n", " break\n", " state.append('r' if are_foes else 'g')\n", " node2init[node_id] = state\n", "\n", "# 어떤 연결과도 상충이 일어나지는 않지만, 신호가 부여되어 있는 경우에는 r을 부여\n", "for _, row in sigtable.iterrows():\n", " node_id = row['node_id']\n", " inc_edge_A = row.inc_edge_A\n", " inc_edge_B = row.inc_edge_B\n", " out_edge_A = row.out_edge_A\n", " out_edge_B = row.out_edge_B\n", " move_A = row['move_A']\n", " move_B = row['move_B']\n", "\n", " if pd.isna(inc_edge_A) or pd.isna(out_edge_A):\n", " continue\n", " else:\n", " inc_edge_A = net.getEdge(inc_edge_A)\n", " out_edge_A = net.getEdge(out_edge_A)\n", " for conn in inc_edge_A.getConnections(out_edge_A):\n", " index = conn.getTLLinkIndex()\n", " if index >= 0:\n", " node2init[node_id][index] = 'r'\n", "\n", " if pd.isna(inc_edge_B) or pd.isna(out_edge_B):\n", " continue\n", " else:\n", " inc_edge_B = net.getEdge(inc_edge_B)\n", " out_edge_B = net.getEdge(out_edge_B)\n", " for conn in inc_edge_B.getConnections(out_edge_B):\n", " index = conn.getTLLinkIndex()\n", " if index >= 0:\n", " node2init[node_id][index] = 'r'\n", "for node_id in node_ids:\n", " print(node_id, \"\".join(node2init[node_id]))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['g', 'r', 'r', 'r', 'g', 'r', 'r', 'r', 'r', 'g', 'r', 'r', 'g', 'r', 'r', 'r']\n", "['G', 'r', 'r', 'r', 'g', 'r', 'r', 'r', 'r', 'g', 'r', 'r', 'g', 'r', 'r', 'r']\n", "['g', 'r', 'r', 'r', 'g', 'r', 'r', 'r', 'r', 'g', 'r', 'r', 'g', 'r', 'r', 'r']\n" ] } ], "source": [ "print(node2init['i6'])\n", "state = copy.deepcopy(node2init)['i6']\n", "state[0] = 'G'\n", "print(state)\n", "print(node2init['i6'])" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([ 1., 7., 11., 12., 6., 7., 3., 1., 2., 3.]),\n", " array([ 0. , 12.2, 24.4, 36.6, 48.8, 61. , 73.2, 85.4, 97.6,\n", " 109.8, 122. ]),\n", " )" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/OQEPoAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAbkklEQVR4nO3de5CVdf3A8c/CugdUdhGMhc1FNnMGFTITIcQpHXcyw1sXK4eKqOm6psRMAhUWo7R0GYcuDqYzXpq81YyQadkYosaEXMWyEnEkZbSFytjDJVfa/f7+cDzTCurS7+z37LKv18yZ8TzPw3k+fAf3vOc55+ypSimlAADIZFClBwAABhbxAQBkJT4AgKzEBwCQlfgAALISHwBAVuIDAMhKfAAAWVVXeoBX6+rqiueffz6GDRsWVVVVlR4HAOiBlFLs2rUrGhoaYtCg17+20efi4/nnn4/GxsZKjwEA/A+2bdsWxxxzzOse0+fiY9iwYRHx8vC1tbUVngYA6IlisRiNjY2l5/HX0+fi45WXWmpra8UHAPQzPXnLhDecAgBZiQ8AICvxAQBkJT4AgKzEBwCQlfgAALISHwBAVuIDAMhKfAAAWYkPACCrg46Phx9+OM4///xoaGiIqqqqWL58eWnfvn37Yu7cuTFx4sQ44ogjoqGhIT7xiU/E888/X86ZAYB+7KDjY8+ePXHyySfHtddeu9++vXv3xsaNG2PBggWxcePGuOuuu2Lz5s1xwQUXlGVYAKD/q0oppf/5D1dVxbJly+Kiiy56zWPWrVsXkydPjmeeeSbGjh37ho9ZLBajrq4u2tvbfbEcAPQTB/P83evfatve3h5VVVUxfPjwA+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556aqxYsaK0raurK1asWBFTp04t9+kAgH6mV152mTNnTsycOTMmTZoUkydPjiVLlsSePXti1qxZvXE6AKAf6ZX4+MhHPhJ///vf48orr4y2trZ4+9vfHvfdd99+b0LNrVAoxDe+8Y39XuahO+vUM9apZ6xTz1inN2aNeqY/rFNV6slnYgAAysR3uwAAWYkPACAr8QEAZCU+AICsBkx8XHvttTFu3LgYMmRITJkyJdauXVvpkSqqtbU1TjvttBg2bFiMGjUqLrrooti8eXO3Y1588cVoaWmJkSNHxpFHHhkf/OAH9/vlcQPN4sWLo6qqKmbPnl3aZp1e9txzz8XHPvaxGDlyZAwdOjQmTpwY69evL+1PKcWVV14ZY8aMiaFDh0Zzc3Ns2bKlghPn19nZGQsWLIimpqYYOnRoHHfccXHVVVd1+y6MgbhODz/8cJx//vnR0NAQVVVVsXz58m77e7ImL7zwQsyYMSNqa2tj+PDh8elPfzp2796d8W/R+15vnfbt2xdz586NiRMnxhFHHBENDQ3xiU98Ip5//vluj9Fn1ikNAHfccUeqqalJN954Y/rTn/6UPvOZz6Thw4en7du3V3q0ijnnnHPSTTfdlB5//PG0adOm9L73vS+NHTs27d69u3TM5z//+dTY2JhWrFiR1q9fn975znem008/vYJTV9batWvTuHHj0tve9rZ0+eWXl7Zbp5ReeOGFdOyxx6ZPfvKTac2aNenpp59Ov/nNb9JTTz1VOmbx4sWprq4uLV++PD322GPpggsuSE1NTenf//53BSfPa9GiRWnkyJHpnnvuSVu3bk0///nP05FHHpm+//3vl44ZiOv0q1/9Kn3ta19Ld911V4qItGzZsm77e7Im733ve9PJJ5+cHnnkkfS73/0uvfWtb02XXHJJ5r9J73q9ddq5c2dqbm5Od955Z3riiSfS6tWr0+TJk9Opp57a7TH6yjoNiPiYPHlyamlpKd3v7OxMDQ0NqbW1tYJT9S07duxIEZEeeuihlNLL/5APO+yw9POf/7x0zF/+8pcUEWn16tWVGrNidu3alY4//vh0//33p3e/+92l+LBOL5s7d24644wzXnN/V1dXGj16dPrud79b2rZz585UK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y+NZcuWxQMPPBBNTU3d9p966qlx2GGHdVu3zZs3x7PPPjug1u3ss8+OP/7xj7Fp06bSbdKkSTFjxozSf1uniGnTpu33Ue0nn3wyjj322IiIaGpqitGjR3dbp2KxGGvWrBlQ67R3794YNKj7j93BgwdHV1dXRFinA+nJmkydOjV27twZGzZsKB3zwAMPRFdXV0yZMiX7zJXySnhs2bIlfvvb38bIkSO77e9T65T17a0Vcscdd6RCoZBuvvnm9Oc//zl99rOfTcOHD09tbW2VHq1ivvCFL6S6urr04IMPpr/97W+l2969e0vHfP7zn09jx45NDzzwQFq/fn2aOnVqmjp1agWn7hv++9MuKVmnlF5+V311dXVatGhR2rJlS7r11lvT4Ycfnn7605+Wjlm8eHEaPnx4+sUvfpH+8Ic/pAsvvPCQ/wjpq82cOTO9+c1vLn3U9q677kpHH310uuKKK0rHDMR12rVrV3r00UfTo48+miIiXXPNNenRRx8tfUqjJ2vy3ve+N51yyilpzZo1adWqVen4448/5D5q+3rr9NJLL6ULLrggHXPMMWnTpk3dfq53dHSUHqOvrNOAiI+UUvrhD3+Yxo4dm2pqatLkyZPTI488UumRKioiDni76aabSsf8+9//Tl/84hfTUUcdlQ4//PD0/ve/P/3tb3+r3NB9xKvjwzq97Je//GWaMGFCKhQKafz48en666/vtr+rqystWLAg1dfXp0KhkM4+++y0efPmCk1bGcViMV1++eVp7NixaciQIektb3lL+trXvtbtyWEgrtPKlSsP+PNo5syZKaWerck///nPdMkll6Qjjzwy1dbWplmzZqVdu3ZV4G/Te15vnbZu3fqaP9dXrlxZeoy+sk5VKf3Xr9YDAOhlh/x7PgCAvkV8AABZiQ8AICvxAQBkJT4AgKzEBwCQlfgAALISHwBAVuIDAMhKfAAAWYkPACAr8QEAZPV/qgnE9bhoJQwAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plan = pd.read_csv('../../Data/tables/plan.csv', index_col=0)\n", "durs = plan[[f'dura_{alph}{j}' for alph in ['A', 'B'] for j in range(1,9)]].values.flatten()\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "plt.hist(np.unique(durs))" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
node_idstart_unixphase_sumodurationstatestart_dt
399i71704410130044GGrggGG2024-01-05 08:15:30
400i71704410130126GGrggGG2024-01-05 08:15:30
401i01704410170040gGGrgrrrgGGGGrgrr2024-01-05 08:16:10
402i01704410170142grrGgrrrgrrrrGgrr2024-01-05 08:16:10
403i01704410170229grrrgGGGgrrrrrgrr2024-01-05 08:16:10
404i01704410170326grrrgGGrgrrrrrgGr2024-01-05 08:16:10
405i01704410170433grrrgrrrgrrrrrgGG2024-01-05 08:16:10
406i61704410200024grrrgGGGrgrrgrrr2024-01-05 08:16:40
407i61704410200119grrrgGGGrgrrgGGr2024-01-05 08:16:40
408i61704410200239grrrgrrrrgrrgGGG2024-01-05 08:16:40
409i61704410200365gGGGgrrrrgrrgrrr2024-01-05 08:16:40
410i61704410200423grrrgrrrrgGGgrrr2024-01-05 08:16:40
\n", "
" ], "text/plain": [ " node_id start_unix phase_sumo duration state \\\n", "399 i7 1704410130 0 44 GGrggGG \n", "400 i7 1704410130 1 26 GGrggGG \n", "401 i0 1704410170 0 40 gGGrgrrrgGGGGrgrr \n", "402 i0 1704410170 1 42 grrGgrrrgrrrrGgrr \n", "403 i0 1704410170 2 29 grrrgGGGgrrrrrgrr \n", "404 i0 1704410170 3 26 grrrgGGrgrrrrrgGr \n", "405 i0 1704410170 4 33 grrrgrrrgrrrrrgGG \n", "406 i6 1704410200 0 24 grrrgGGGrgrrgrrr \n", "407 i6 1704410200 1 19 grrrgGGGrgrrgGGr \n", "408 i6 1704410200 2 39 grrrgrrrrgrrgGGG \n", "409 i6 1704410200 3 65 gGGGgrrrrgrrgrrr \n", "410 i6 1704410200 4 23 grrrgrrrrgGGgrrr \n", "\n", " start_dt \n", "399 2024-01-05 08:15:30 \n", "400 2024-01-05 08:15:30 \n", "401 2024-01-05 08:16:10 \n", "402 2024-01-05 08:16:10 \n", "403 2024-01-05 08:16:10 \n", "404 2024-01-05 08:16:10 \n", "405 2024-01-05 08:16:10 \n", "406 2024-01-05 08:16:40 \n", "407 2024-01-05 08:16:40 \n", "408 2024-01-05 08:16:40 \n", "409 2024-01-05 08:16:40 \n", "410 2024-01-05 08:16:40 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sigtable = histid.copy()\n", "sigtable['init_state'] = sigtable['node_id'].map(node2init)\n", "for i, row in sigtable.iterrows():\n", " node_id = row.node_id\n", " inc_edge_A = row.inc_edge_A\n", " inc_edge_B = row.inc_edge_B\n", " out_edge_A = row.out_edge_A\n", " out_edge_B = row.out_edge_B\n", " state = copy.deepcopy(node2init)[node_id]\n", "\n", " if pd.isna(inc_edge_A) or pd.isna(out_edge_A):\n", " continue\n", " else:\n", " inc_edge_A = net.getEdge(inc_edge_A)\n", " out_edge_A = net.getEdge(out_edge_A)\n", " for conn in inc_edge_A.getConnections(out_edge_A):\n", " index = conn.getTLLinkIndex()\n", " if index >= 0:\n", " state[index] = 'G'\n", " sigtable.at[i, 'state'] = ''.join(state)\n", "\n", " if pd.isna(inc_edge_B) or pd.isna(out_edge_B):\n", " continue\n", " else:\n", " inc_edge_B = net.getEdge(inc_edge_B)\n", " out_edge_B = net.getEdge(out_edge_B)\n", " for conn in inc_edge_B.getConnections(out_edge_B):\n", " index = conn.getTLLinkIndex()\n", " if index >= 0:\n", " state[index] = 'G'\n", " sigtable.at[i, 'state'] = ''.join(state)\n", "sigtable = sigtable.dropna(subset='state')\n", "sigtable = sigtable.reset_index(drop=True)\n", "sigtable['phase_sumo'] = sigtable.groupby(['node_id', 'start_unix']).cumcount()\n", "sigtable = sigtable[['node_id', 'start_unix', 'phase_sumo', 'duration', 'state']]\n", "sigtable = sigtable.sort_values(by=['start_unix', 'node_id'])\n", "sigtable_dt = sigtable.copy()[sigtable.start_unix >= fmins[m]-360]\n", "sigtable_dt['start_dt'] = sigtable_dt['start_unix'].apply(lambda x:datetime.fromtimestamp(x))\n", "sigtable_dt = sigtable_dt[sigtable_dt.node_id!='i9']\n", "sigtable_dt = sigtable_dt[sigtable_dt.node_id!='i2']\n", "display(sigtable_dt)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3380\n", "2024-01-05 08:15:00\n", "2024-01-05 08:20:00\n", "2024-01-05 08:17:00\n", "2024-01-05 07:20:40\n" ] } ], "source": [ "print(sigtable.start_unix.max() - sigtable.start_unix.min())\n", "print(datetime.fromtimestamp(fmins[m - 1]))\n", "print(datetime.fromtimestamp(fmins[m]))\n", "print(datetime.fromtimestamp(sigtable.start_unix.max()))\n", "print(datetime.fromtimestamp(sigtable.start_unix.min()))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "sigtable1 = sigtable.copy()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['i0', 'i1', 'i2', 'i3', 'i6', 'i7', 'i8', 'i9']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sorted(sigtable.node_id.unique())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "strings = ['\\n']\n", "for key, group in sigtable.groupby(['start_unix', 'node_id']):\n", " start_unix = key[0]\n", " node_id = key[1]\n", " strings.append(f' \\n')\n", " for i, row in group.iterrows():\n", " duration = row.duration\n", " state = row.state\n", " strings.append(f' \\n')\n", " strings.append(' \\n')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ] } ], "source": [ "strings = ['\\n']\n", "for key, group in sigtable.groupby(['start_unix', 'node_id']):\n", " start_unix = key[0]\n", " node_id = key[1]\n", " strings.append(f' \\n')\n", " for i, row in group.iterrows():\n", " duration = row.duration\n", " state = row.state\n", " strings.append(f' \\n')\n", " strings.append(' \\n')\n", "strings.append('')\n", "strings = ''.join(strings)\n", "# 저장\n", "path_output = '../../Data/networks/SN_sample.tll.xml'\n", "with open(path_output, 'w') as f:\n", " f.write(strings)\n", "print(strings)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ] } ], "source": [ "strings = ['\\n']\n", "for key, group in sigtable.groupby(['start_unix', 'node_id']):\n", " start_unix = key[0]\n", " node_id = key[1]\n", " strings.append(f' \\n')\n", " for i, row in group.iterrows():\n", " duration = row.duration\n", " state = row.state\n", " strings.append(f' \\n')\n", " strings.append(' \\n')\n", "strings.append('')\n", "strings = ''.join(strings)\n", "# 저장\n", "path_output = '../../Data/networks/SN_sample.tll.xml'\n", "with open(path_output, 'w') as f:\n", " f.write(strings)\n", "print(strings)" ] } ], "metadata": { "kernelspec": { "display_name": "rts", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 2 }