{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\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": [ "2024-01-05 08:20:00\n" ] } ], "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", "present_time = fmins[m]\n", "sim_start = fmins[m] - 600\n", "sim_end = fmins[m] - 300\n", "print(datetime.fromtimestamp(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)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{175: 'u00', 176: 'i1', 177: 'u20', 178: 'c30', 201: 'i8', 202: 'i9', 206: 'i7', 210: 'i6'}\n", "{'i0': 175, 'u00': 175, 'i1': 176, 'i2': 177, 'u20': 177, 'i3': 178, 'u30': 178, 'u31': 178, 'u32': 178, 'i8': 201, 'i9': 202, 'i7': 206, 'i6': 210, 'c30': 178}\n", "{'u00': 'i0', 'u20': 'i2', 'u30': 'i3', 'u31': 'i3', 'u32': 'i3', 'c30': 'i3'}\n", "{'i0': ['u00'], 'i1': [], 'i2': ['u20'], 'i3': ['c30', 'u30', 'u31', 'u32'], 'i6': [], 'i7': [], 'i8': [], 'i9': []}\n", "['c30', 'i0', 'i1', 'i2', 'i3', 'i6', 'i7', 'i8', 'i9', 'u00', 'u20', 'u30', 'u31', 'u32']\n", "['i0', 'i1', 'i2', 'i3', 'i6', 'i7', 'i8', 'i9']\n", "['c30', 'u00', 'u20', 'u30', 'u31', 'u32']\n" ] } ], "source": [ "inter2node = dict(zip(inter_node['inter_no'], inter_node['node_id']))\n", "node2inter = dict(zip(inter_node['node_id'], inter_node['inter_no']))\n", "ch2pa = {'u00': 'i0', 'u20': 'i2', 'u30': 'i3', 'u31': 'i3', 'u32': 'i3', 'c30': 'i3'}\n", "pa2ch = {'i0':['u00'], 'i1':[], 'i2':['u20'], 'i3':['c30', 'u30', 'u31', 'u32'], 'i6':[], 'i7':[], 'i8':[], 'i9':[]}\n", "node_ids = sorted(inter_node.node_id.unique())\n", "parent_ids = sorted(inter_node[inter_node.inter_type=='parent'].node_id.unique())\n", "child_ids = sorted(inter_node[inter_node.inter_type=='child'].node_id.unique())\n", "\n", "print(inter2node)\n", "print(node2inter)\n", "print(ch2pa)\n", "print(pa2ch)\n", "print(node_ids)\n", "print(parent_ids)\n", "print(child_ids)" ] }, { "cell_type": "code", "execution_count": 4, "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", " \n", " \n", " \n", " \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_Aout_edge_Ainc_edge_Bout_edge_B
0u0017044089101140-571542797_02571500487_01-571500487_01571542797_02
1u0017044089102242-571500487_01571545870_01-571542797_02571510153_01
2u0017044089103329571545870_02571510153_01571545870_02571542797_02
3u0017044089103426571545870_02571510153_01571510153_02571545870_01
4u0017044089104433571510153_02571500487_01571510153_02571545870_01
..............................
210i817044101801130-571500569_01571500583_02-571500569_01571500618_01
211i817044101802236571500618_02571500583_02571500618_02571500617_01
212i817044101803318571500617_02571500618_01571500618_02571500617_01
213i817044101804458571500617_02571500618_01571500617_02571500569_01
214i817044101805518571500583_01571500617_01571500583_01571500569_01
\n", "

215 rows × 9 columns

\n", "
" ], "text/plain": [ " node_id start_unix phas_A phas_B duration inc_edge_A \\\n", "0 u00 1704408910 1 1 40 -571542797_02 \n", "1 u00 1704408910 2 2 42 -571500487_01 \n", "2 u00 1704408910 3 3 29 571545870_02 \n", "3 u00 1704408910 3 4 26 571545870_02 \n", "4 u00 1704408910 4 4 33 571510153_02 \n", ".. ... ... ... ... ... ... \n", "210 i8 1704410180 1 1 30 -571500569_01 \n", "211 i8 1704410180 2 2 36 571500618_02 \n", "212 i8 1704410180 3 3 18 571500617_02 \n", "213 i8 1704410180 4 4 58 571500617_02 \n", "214 i8 1704410180 5 5 18 571500583_01 \n", "\n", " out_edge_A inc_edge_B out_edge_B \n", "0 571500487_01 -571500487_01 571542797_02 \n", "1 571545870_01 -571542797_02 571510153_01 \n", "2 571510153_01 571545870_02 571542797_02 \n", "3 571510153_01 571510153_02 571545870_01 \n", "4 571500487_01 571510153_02 571545870_01 \n", ".. ... ... ... \n", "210 571500583_02 -571500569_01 571500618_01 \n", "211 571500583_02 571500618_02 571500617_01 \n", "212 571500618_01 571500618_02 571500617_01 \n", "213 571500618_01 571500617_02 571500569_01 \n", "214 571500617_01 571500583_01 571500569_01 \n", "\n", "[215 rows x 9 columns]" ] }, "metadata": {}, "output_type": "display_data" }, { "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", "
node_idphase_noring_typeinc_edgeout_edge
0i01A-571542797_02571500487_01
1i01B-571500487_01571542797_02
2i02A-571500487_01571545870_01
3i02B-571542797_02571510153_01
4i03A571545870_02571510153_01
..................
111u602B571500535_02-571500535_02
112u603ANaNNaN
113u603BNaNNaN
114u604ANaNNaN
115u604BNaNNaN
\n", "

116 rows × 5 columns

\n", "
" ], "text/plain": [ " node_id phase_no ring_type inc_edge out_edge\n", "0 i0 1 A -571542797_02 571500487_01\n", "1 i0 1 B -571500487_01 571542797_02\n", "2 i0 2 A -571500487_01 571545870_01\n", "3 i0 2 B -571542797_02 571510153_01\n", "4 i0 3 A 571545870_02 571510153_01\n", ".. ... ... ... ... ...\n", "111 u60 2 B 571500535_02 -571500535_02\n", "112 u60 3 A NaN NaN\n", "113 u60 3 B NaN NaN\n", "114 u60 4 A NaN NaN\n", "115 u60 4 B NaN NaN\n", "\n", "[116 rows x 5 columns]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "histid = pd.read_csv(f'../../Data/tables/histids/histids_{fmins[m]}.csv', index_col=0)\n", "match6 = pd.read_csv('../../Data/tables/matching/match6.csv', index_col=0)\n", "histid = histid.reset_index(drop=True)\n", "histid = histid.drop(columns=['inter_no'])\n", "match6 = match6[['node_id', 'phase_no', 'ring_type', 'inc_edge', 'out_edge']].reset_index(drop=True)\n", "display(histid)\n", "display(match6)" ] }, { "cell_type": "code", "execution_count": 5, "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", " \n", " \n", " \n", " \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_Aout_edge_Ainc_edge_Bout_edge_B
0u0017044089101140-571542797_02571500487_01-571500487_01571542797_02
1u0017044089102242-571500487_01571545870_01-571542797_02571510153_01
2u0017044089103329571545870_02571510153_01571545870_02571542797_02
3u0017044089103426571545870_02571510153_01571510153_02571545870_01
4u0017044089104433571510153_02571500487_01571510153_02571545870_01
..............................
210i817044101801130-571500569_01571500583_02-571500569_01571500618_01
211i817044101802236571500618_02571500583_02571500618_02571500617_01
212i817044101803318571500617_02571500618_01571500618_02571500617_01
213i817044101804458571500617_02571500618_01571500617_02571500569_01
214i817044101805518571500583_01571500617_01571500583_01571500569_01
\n", "

215 rows × 9 columns

\n", "
" ], "text/plain": [ " node_id start_unix phas_A phas_B duration inc_edge_A \\\n", "0 u00 1704408910 1 1 40 -571542797_02 \n", "1 u00 1704408910 2 2 42 -571500487_01 \n", "2 u00 1704408910 3 3 29 571545870_02 \n", "3 u00 1704408910 3 4 26 571545870_02 \n", "4 u00 1704408910 4 4 33 571510153_02 \n", ".. ... ... ... ... ... ... \n", "210 i8 1704410180 1 1 30 -571500569_01 \n", "211 i8 1704410180 2 2 36 571500618_02 \n", "212 i8 1704410180 3 3 18 571500617_02 \n", "213 i8 1704410180 4 4 58 571500617_02 \n", "214 i8 1704410180 5 5 18 571500583_01 \n", "\n", " out_edge_A inc_edge_B out_edge_B \n", "0 571500487_01 -571500487_01 571542797_02 \n", "1 571545870_01 -571542797_02 571510153_01 \n", "2 571510153_01 571545870_02 571542797_02 \n", "3 571510153_01 571510153_02 571545870_01 \n", "4 571500487_01 571510153_02 571545870_01 \n", ".. ... ... ... \n", "210 571500583_02 -571500569_01 571500618_01 \n", "211 571500583_02 571500618_02 571500617_01 \n", "212 571500618_01 571500618_02 571500617_01 \n", "213 571500618_01 571500617_02 571500569_01 \n", "214 571500617_01 571500583_01 571500569_01 \n", "\n", "[215 rows x 9 columns]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "new_histids = []\n", "for parent_id in parent_ids:\n", " for child_id in pa2ch[parent_id]:\n", " new_histid = histid.copy()[histid.node_id==parent_id]\n", " new_histid[['inc_edge_A', 'out_edge_A', 'inc_edge_B', 'out_edge_B']] = np.nan\n", " for i, row in new_histid.iterrows():\n", " phas_A = row.phas_A\n", " phas_B = row.phas_B\n", " new_match = match6[match6.node_id==child_id]\n", " Arow = new_match[(new_match.phase_no==phas_A) & (new_match.ring_type=='A')]\n", " if ~Arow[['inc_edge', 'out_edge']].isna().all().all():\n", " inc_edge = Arow.iloc[0].inc_edge\n", " out_edge = Arow.iloc[0].out_edge\n", " new_histid.loc[i, ['inc_edge_A', 'out_edge_A']] = [inc_edge, out_edge]\n", " Brow = new_match[(new_match.phase_no==phas_B) & (new_match.ring_type=='B')]\n", " if ~Brow[['inc_edge', 'out_edge']].isna().all().all():\n", " inc_edge = Brow.iloc[0].inc_edge\n", " out_edge = Brow.iloc[0].out_edge\n", " new_histid.loc[i, ['inc_edge_B', 'out_edge_B']] = [inc_edge, out_edge]\n", " new_histid.loc[i, 'node_id'] = child_id\n", " new_histids.append(new_histid)\n", "\n", "new_histids = pd.concat(new_histids)\n", "sigtable = pd.concat([histid.copy(), new_histids])\n", "sigtable = sigtable.sort_values(by=['start_unix', 'node_id', 'phas_A', 'phas_B']).reset_index(drop=True)\n", "display(sigtable)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['c30', 'i1', 'i6', 'i8', 'i9', 'u00', 'u20']\n", "[, , , , , , ]\n" ] } ], "source": [ "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": 7, "metadata": {}, "outputs": [ { "ename": "IndexError", "evalue": "list assignment index out of range", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[7], line 37\u001b[0m\n\u001b[0;32m 35\u001b[0m index \u001b[38;5;241m=\u001b[39m conn\u001b[38;5;241m.\u001b[39mgetTLLinkIndex()\n\u001b[0;32m 36\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m index \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m---> 37\u001b[0m \u001b[43mnode2init\u001b[49m\u001b[43m[\u001b[49m\u001b[43mnode_id\u001b[49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[43mindex\u001b[49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 39\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m pd\u001b[38;5;241m.\u001b[39misna(inc_edge_B) \u001b[38;5;129;01mor\u001b[39;00m pd\u001b[38;5;241m.\u001b[39misna(out_edge_B):\n\u001b[0;32m 40\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m\n", "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" ] } ], "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", "\n", " if pd.isna(inc_edge_A) or pd.isna(out_edge_A):\n", " pass\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", " pass\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": null, "metadata": {}, "outputs": [], "source": [ "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]-420]\n", "sigtable_dt['start_dt'] = sigtable_dt['start_unix'].apply(lambda x:datetime.fromtimestamp(x))\n", "display(sigtable_dt)\n", "# 시뮬레이션 시작시각 : 현재시각 - 600 = 08:20\n", "# 시뮬레이션 종료시각 : 현재시각 - 300 = 08:15\n", "# 현재시각 : present_time, PT = 08:10\n", "# PT-900 ... PT-600 ... PT-300 ... PT" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(sim_start)\n", "print(sim_end)\n", "print(present_time)\n", "sigtable[:60]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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": null, "metadata": {}, "outputs": [], "source": [ "sigtable1 = sigtable.copy()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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": [], "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": [], "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 }