{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 42,
|
|
"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": 43,
|
|
"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": 44,
|
|
"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": 80,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[Timestamp('2024-01-05 08:06:30'),\n",
|
|
" Timestamp('2024-01-05 08:09:20'),\n",
|
|
" Timestamp('2024-01-05 08:12:10')]"
|
|
]
|
|
},
|
|
"execution_count": 80,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"histid_dt = histid.copy()\n",
|
|
"histid_dt['start_dt'] = histid_dt['start_unix'].map(lambda x:datetime.fromtimestamp(x))\n",
|
|
"sdti3 = sorted(histid_dt[histid_dt.node_id=='i0'].start_dt.unique())\n",
|
|
"sdti3"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 45,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1704410400 2024-01-05 08:20:00\n"
|
|
]
|
|
},
|
|
{
|
|
"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>node_id</th>\n",
|
|
" <th>start_unix</th>\n",
|
|
" <th>phas_A</th>\n",
|
|
" <th>phas_B</th>\n",
|
|
" <th>duration</th>\n",
|
|
" <th>inc_edge_A</th>\n",
|
|
" <th>out_edge_A</th>\n",
|
|
" <th>inc_edge_B</th>\n",
|
|
" <th>out_edge_B</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>i3</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>38</td>\n",
|
|
" <td>571540304_02</td>\n",
|
|
" <td>571556450_01</td>\n",
|
|
" <td>571556450_02</td>\n",
|
|
" <td>571540304_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>i3</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>39</td>\n",
|
|
" <td>571556450_02</td>\n",
|
|
" <td>571500475_01</td>\n",
|
|
" <td>571540304_02</td>\n",
|
|
" <td>571540303_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>i3</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>42</td>\n",
|
|
" <td>571540303_02.21</td>\n",
|
|
" <td>571556450_01</td>\n",
|
|
" <td>571540303_02.21</td>\n",
|
|
" <td>571500475_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>i3</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>21</td>\n",
|
|
" <td>-571500475_01</td>\n",
|
|
" <td>571540303_01</td>\n",
|
|
" <td>-571500475_01</td>\n",
|
|
" <td>571540304_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>i9</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>46</td>\n",
|
|
" <td>571510152_02</td>\n",
|
|
" <td>-571510152_01</td>\n",
|
|
" <td>571510152_01</td>\n",
|
|
" <td>571510152_01.65</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>...</th>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>88</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>30</td>\n",
|
|
" <td>-571500569_01</td>\n",
|
|
" <td>571500583_02</td>\n",
|
|
" <td>-571500569_01</td>\n",
|
|
" <td>571500618_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>89</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>36</td>\n",
|
|
" <td>571500618_02</td>\n",
|
|
" <td>571500583_02</td>\n",
|
|
" <td>571500618_02</td>\n",
|
|
" <td>571500617_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>90</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>18</td>\n",
|
|
" <td>571500617_02</td>\n",
|
|
" <td>571500618_01</td>\n",
|
|
" <td>571500618_02</td>\n",
|
|
" <td>571500617_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>91</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>58</td>\n",
|
|
" <td>571500617_02</td>\n",
|
|
" <td>571500618_01</td>\n",
|
|
" <td>571500617_02</td>\n",
|
|
" <td>571500569_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>92</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>18</td>\n",
|
|
" <td>571500583_01</td>\n",
|
|
" <td>571500617_01</td>\n",
|
|
" <td>571500583_01</td>\n",
|
|
" <td>571500569_01</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"<p>93 rows × 9 columns</p>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" node_id start_unix phas_A phas_B duration inc_edge_A \\\n",
|
|
"0 i3 1704409510 1 1 38 571540304_02 \n",
|
|
"1 i3 1704409510 2 2 39 571556450_02 \n",
|
|
"2 i3 1704409510 3 3 42 571540303_02.21 \n",
|
|
"3 i3 1704409510 4 4 21 -571500475_01 \n",
|
|
"4 i9 1704409510 1 1 46 571510152_02 \n",
|
|
".. ... ... ... ... ... ... \n",
|
|
"88 i8 1704410180 1 1 30 -571500569_01 \n",
|
|
"89 i8 1704410180 2 2 36 571500618_02 \n",
|
|
"90 i8 1704410180 3 3 18 571500617_02 \n",
|
|
"91 i8 1704410180 4 4 58 571500617_02 \n",
|
|
"92 i8 1704410180 5 5 18 571500583_01 \n",
|
|
"\n",
|
|
" out_edge_A inc_edge_B out_edge_B \n",
|
|
"0 571556450_01 571556450_02 571540304_01 \n",
|
|
"1 571500475_01 571540304_02 571540303_01 \n",
|
|
"2 571556450_01 571540303_02.21 571500475_01 \n",
|
|
"3 571540303_01 -571500475_01 571540304_01 \n",
|
|
"4 -571510152_01 571510152_01 571510152_01.65 \n",
|
|
".. ... ... ... \n",
|
|
"88 571500583_02 -571500569_01 571500618_01 \n",
|
|
"89 571500583_02 571500618_02 571500617_01 \n",
|
|
"90 571500618_01 571500618_02 571500617_01 \n",
|
|
"91 571500618_01 571500617_02 571500569_01 \n",
|
|
"92 571500617_01 571500583_01 571500569_01 \n",
|
|
"\n",
|
|
"[93 rows x 9 columns]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"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>node_id</th>\n",
|
|
" <th>phase_no</th>\n",
|
|
" <th>ring_type</th>\n",
|
|
" <th>inc_edge</th>\n",
|
|
" <th>out_edge</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>-571542797_02</td>\n",
|
|
" <td>571500487_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>-571500487_01</td>\n",
|
|
" <td>571542797_02</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>-571500487_01</td>\n",
|
|
" <td>571545870_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>-571542797_02</td>\n",
|
|
" <td>571510153_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>i0</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>571545870_02</td>\n",
|
|
" <td>571510153_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>...</th>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>111</th>\n",
|
|
" <td>u60</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>571500535_02</td>\n",
|
|
" <td>-571500535_02</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>112</th>\n",
|
|
" <td>u60</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>113</th>\n",
|
|
" <td>u60</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>114</th>\n",
|
|
" <td>u60</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>A</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>115</th>\n",
|
|
" <td>u60</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>B</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"<p>116 rows × 5 columns</p>\n",
|
|
"</div>"
|
|
],
|
|
"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": [
|
|
"print(fmins[m], datetime.fromtimestamp(fmins[m]))\n",
|
|
"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": 46,
|
|
"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>node_id</th>\n",
|
|
" <th>start_unix</th>\n",
|
|
" <th>phas_A</th>\n",
|
|
" <th>phas_B</th>\n",
|
|
" <th>duration</th>\n",
|
|
" <th>inc_edge_A</th>\n",
|
|
" <th>out_edge_A</th>\n",
|
|
" <th>inc_edge_B</th>\n",
|
|
" <th>out_edge_B</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>c30</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>38</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>c30</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>39</td>\n",
|
|
" <td>571542116_01</td>\n",
|
|
" <td>-571542116_02.96</td>\n",
|
|
" <td>571542116_02.96</td>\n",
|
|
" <td>571542116_02.164</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>c30</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>42</td>\n",
|
|
" <td>571542116_01</td>\n",
|
|
" <td>-571542116_02.96</td>\n",
|
|
" <td>571542116_02.96</td>\n",
|
|
" <td>571542116_02.164</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>c30</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>21</td>\n",
|
|
" <td>571542116_01</td>\n",
|
|
" <td>-571542116_02.96</td>\n",
|
|
" <td>571542116_02.96</td>\n",
|
|
" <td>571542116_02.164</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>i3</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>38</td>\n",
|
|
" <td>571540304_02</td>\n",
|
|
" <td>571556450_01</td>\n",
|
|
" <td>571556450_02</td>\n",
|
|
" <td>571540304_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>...</th>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>195</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>30</td>\n",
|
|
" <td>-571500569_01</td>\n",
|
|
" <td>571500583_02</td>\n",
|
|
" <td>-571500569_01</td>\n",
|
|
" <td>571500618_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>196</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>36</td>\n",
|
|
" <td>571500618_02</td>\n",
|
|
" <td>571500583_02</td>\n",
|
|
" <td>571500618_02</td>\n",
|
|
" <td>571500617_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>197</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>18</td>\n",
|
|
" <td>571500617_02</td>\n",
|
|
" <td>571500618_01</td>\n",
|
|
" <td>571500618_02</td>\n",
|
|
" <td>571500617_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>198</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>58</td>\n",
|
|
" <td>571500617_02</td>\n",
|
|
" <td>571500618_01</td>\n",
|
|
" <td>571500617_02</td>\n",
|
|
" <td>571500569_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>199</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>18</td>\n",
|
|
" <td>571500583_01</td>\n",
|
|
" <td>571500617_01</td>\n",
|
|
" <td>571500583_01</td>\n",
|
|
" <td>571500569_01</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"<p>200 rows × 9 columns</p>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" node_id start_unix phas_A phas_B duration inc_edge_A \\\n",
|
|
"0 c30 1704409510 1 1 38 NaN \n",
|
|
"1 c30 1704409510 2 2 39 571542116_01 \n",
|
|
"2 c30 1704409510 3 3 42 571542116_01 \n",
|
|
"3 c30 1704409510 4 4 21 571542116_01 \n",
|
|
"4 i3 1704409510 1 1 38 571540304_02 \n",
|
|
".. ... ... ... ... ... ... \n",
|
|
"195 i8 1704410180 1 1 30 -571500569_01 \n",
|
|
"196 i8 1704410180 2 2 36 571500618_02 \n",
|
|
"197 i8 1704410180 3 3 18 571500617_02 \n",
|
|
"198 i8 1704410180 4 4 58 571500617_02 \n",
|
|
"199 i8 1704410180 5 5 18 571500583_01 \n",
|
|
"\n",
|
|
" out_edge_A inc_edge_B out_edge_B \n",
|
|
"0 NaN NaN NaN \n",
|
|
"1 -571542116_02.96 571542116_02.96 571542116_02.164 \n",
|
|
"2 -571542116_02.96 571542116_02.96 571542116_02.164 \n",
|
|
"3 -571542116_02.96 571542116_02.96 571542116_02.164 \n",
|
|
"4 571556450_01 571556450_02 571540304_01 \n",
|
|
".. ... ... ... \n",
|
|
"195 571500583_02 -571500569_01 571500618_01 \n",
|
|
"196 571500583_02 571500618_02 571500617_01 \n",
|
|
"197 571500618_01 571500618_02 571500617_01 \n",
|
|
"198 571500618_01 571500617_02 571500569_01 \n",
|
|
"199 571500617_01 571500583_01 571500569_01 \n",
|
|
"\n",
|
|
"[200 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": 47,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"['c30', 'i0', 'i1', 'i2', 'i3', 'i6', 'i8', 'i9', 'u00', 'u20', 'u30', 'u31', 'u32']\n",
|
|
"[<junction id=\"c30\"/>, <junction id=\"i0\"/>, <junction id=\"i1\"/>, <junction id=\"i2\"/>, <junction id=\"i3\"/>, <junction id=\"i6\"/>, <junction id=\"i8\"/>, <junction id=\"i9\"/>, <junction id=\"u00\"/>, <junction id=\"u20\"/>, <junction id=\"u30\"/>, <junction id=\"u31\"/>, <junction id=\"u32\"/>]\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": 48,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"c30 rrrrrr\n",
|
|
"i0 grrrgrrrgrrrrrgrr\n",
|
|
"i1 grrrrrrgrr\n",
|
|
"i2 rrggrrr\n",
|
|
"i3 grrrrgrrrrgrrrrgrrrr\n",
|
|
"i6 grrrgrrrrgrrgrrr\n",
|
|
"i8 grrrrrrrgrrrgrrr\n",
|
|
"i9 rrrr\n",
|
|
"u00 ggggrgggg\n",
|
|
"u20 ggrggg\n",
|
|
"u30 ggggrggg\n",
|
|
"u31 ggggrggg\n",
|
|
"u32 gggggggr\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",
|
|
"\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": 49,
|
|
"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>node_id</th>\n",
|
|
" <th>start_unix</th>\n",
|
|
" <th>phase_sumo</th>\n",
|
|
" <th>duration</th>\n",
|
|
" <th>state</th>\n",
|
|
" <th>start_dt</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>c30</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>39</td>\n",
|
|
" <td>GGGGGG</td>\n",
|
|
" <td>2024-01-05 08:05:10</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>c30</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>42</td>\n",
|
|
" <td>GGGGGG</td>\n",
|
|
" <td>2024-01-05 08:05:10</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>c30</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>21</td>\n",
|
|
" <td>GGGGGG</td>\n",
|
|
" <td>2024-01-05 08:05:10</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>i3</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>38</td>\n",
|
|
" <td>gGGGrgrrrrgGGGrgrrrr</td>\n",
|
|
" <td>2024-01-05 08:05:10</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>i3</td>\n",
|
|
" <td>1704409510</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>39</td>\n",
|
|
" <td>grrrGgrrrrgrrrGgrrrr</td>\n",
|
|
" <td>2024-01-05 08:05:10</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>...</th>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" <td>...</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>112</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>30</td>\n",
|
|
" <td>grrrrrrrgGGGgrrr</td>\n",
|
|
" <td>2024-01-05 08:16:20</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>113</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>36</td>\n",
|
|
" <td>grrrrrrrgrrrgGGG</td>\n",
|
|
" <td>2024-01-05 08:16:20</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>114</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>18</td>\n",
|
|
" <td>grrrGGGrgrrrgGGr</td>\n",
|
|
" <td>2024-01-05 08:16:20</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>115</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>58</td>\n",
|
|
" <td>grrrGGGGgrrrgrrr</td>\n",
|
|
" <td>2024-01-05 08:16:20</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>116</th>\n",
|
|
" <td>i8</td>\n",
|
|
" <td>1704410180</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>18</td>\n",
|
|
" <td>gGGGrrrrgrrrgrrr</td>\n",
|
|
" <td>2024-01-05 08:16:20</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"<p>117 rows × 6 columns</p>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" node_id start_unix phase_sumo duration state \\\n",
|
|
"0 c30 1704409510 0 39 GGGGGG \n",
|
|
"1 c30 1704409510 1 42 GGGGGG \n",
|
|
"2 c30 1704409510 2 21 GGGGGG \n",
|
|
"3 i3 1704409510 0 38 gGGGrgrrrrgGGGrgrrrr \n",
|
|
"4 i3 1704409510 1 39 grrrGgrrrrgrrrGgrrrr \n",
|
|
".. ... ... ... ... ... \n",
|
|
"112 i8 1704410180 0 30 grrrrrrrgGGGgrrr \n",
|
|
"113 i8 1704410180 1 36 grrrrrrrgrrrgGGG \n",
|
|
"114 i8 1704410180 2 18 grrrGGGrgrrrgGGr \n",
|
|
"115 i8 1704410180 3 58 grrrGGGGgrrrgrrr \n",
|
|
"116 i8 1704410180 4 18 gGGGrrrrgrrrgrrr \n",
|
|
"\n",
|
|
" start_dt \n",
|
|
"0 2024-01-05 08:05:10 \n",
|
|
"1 2024-01-05 08:05:10 \n",
|
|
"2 2024-01-05 08:05:10 \n",
|
|
"3 2024-01-05 08:05:10 \n",
|
|
"4 2024-01-05 08:05:10 \n",
|
|
".. ... \n",
|
|
"112 2024-01-05 08:16:20 \n",
|
|
"113 2024-01-05 08:16:20 \n",
|
|
"114 2024-01-05 08:16:20 \n",
|
|
"115 2024-01-05 08:16:20 \n",
|
|
"116 2024-01-05 08:16:20 \n",
|
|
"\n",
|
|
"[117 rows x 6 columns]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"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:10\n",
|
|
"# 시뮬레이션 종료시각 : 현재시각 - 300 = 08:15\n",
|
|
"# 현재시각 : present_time, PT = 08:20\n",
|
|
"# PT-900 ... PT-600 ... PT-300 ... PT"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1704409800 2024-01-05 08:10:00\n",
|
|
"1704410100 2024-01-05 08:15:00\n",
|
|
"1704410400 2024-01-05 08:20:00\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(sim_start, datetime.fromtimestamp(sim_start))\n",
|
|
"print(sim_end, datetime.fromtimestamp(sim_end))\n",
|
|
"print(present_time,datetime.fromtimestamp(present_time))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 56,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"c30 2024-01-05 08:05:10 2024-01-05 08:15:50\n",
|
|
"i0 2024-01-05 08:06:30 2024-01-05 08:12:10\n",
|
|
"i1 2024-01-05 08:07:10 2024-01-05 08:15:40\n",
|
|
"i2 2024-01-05 08:08:40 2024-01-05 08:14:20\n",
|
|
"i3 2024-01-05 08:05:10 2024-01-05 08:15:50\n",
|
|
"i6 2024-01-05 08:11:50 2024-01-05 08:14:40\n",
|
|
"i8 2024-01-05 08:11:00 2024-01-05 08:16:20\n",
|
|
"i9 2024-01-05 08:05:10 2024-01-05 08:16:00\n",
|
|
"u00 2024-01-05 08:06:30 2024-01-05 08:12:10\n",
|
|
"u20 2024-01-05 08:08:40 2024-01-05 08:14:20\n",
|
|
"u30 2024-01-05 08:05:10 2024-01-05 08:15:50\n",
|
|
"u31 2024-01-05 08:05:10 2024-01-05 08:15:50\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"for node_id in sorted(sigtable_dt.node_id.unique()):\n",
|
|
" sig1 = sigtable_dt[sigtable_dt.node_id==node_id]\n",
|
|
" dt_min = sig1.start_dt.min()\n",
|
|
" dt_max = sig1.start_dt.max()\n",
|
|
" print(node_id, dt_min, dt_max)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"sig1 = sigtable_dt[sigtable_dt.node_id=='i2']\n",
|
|
"dts = sorted(sig1.start_dt.unique())\n",
|
|
"print(dt_min)\n",
|
|
"print(dt_min.strftime('%H:%M:%S'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 22,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2024-01-05 08:08:40\n",
|
|
"08:08:40\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"sig1 = sigtable_dt[sigtable_dt.node_id=='i2']\n",
|
|
"dt_min = sig1.start_dt.min()\n",
|
|
"print(dt_min)\n",
|
|
"print(dt_min.strftime('%H:%M:%S'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 34,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"i0 2024-01-05 08:06:30 2024-01-05 08:12:10\n",
|
|
"i1 2024-01-05 08:07:10 2024-01-05 08:15:40\n",
|
|
"i2 2024-01-05 08:08:40 2024-01-05 08:14:20\n",
|
|
"i3 2024-01-05 08:05:10 2024-01-05 08:15:50\n",
|
|
"i6 2024-01-05 08:11:50 2024-01-05 08:14:40\n",
|
|
"i7 NaT NaT\n",
|
|
"i8 2024-01-05 08:11:00 2024-01-05 08:16:20\n",
|
|
"i9 2024-01-05 08:05:10 2024-01-05 08:16:00\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"for node_id in parent_ids:\n",
|
|
" sig1 = sigtable_dt[sigtable_dt.node_id==node_id]\n",
|
|
" dt_min = sig1.start_dt.min()\n",
|
|
" dt_max = sig1.start_dt.max()\n",
|
|
" print(node_id, dt_min, dt_max)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 35,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"670\n",
|
|
"2024-01-05 08:15:00\n",
|
|
"2024-01-05 08:20:00\n",
|
|
"2024-01-05 08:16:20\n",
|
|
"2024-01-05 08:05:10\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": 36,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"sigtable1 = sigtable.copy()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 37,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"['c30', 'i0', 'i1', 'i2', 'i3', 'i6', 'i8', 'i9', 'u00', 'u20', 'u30', 'u31']"
|
|
]
|
|
},
|
|
"execution_count": 37,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"sorted(sigtable.node_id.unique())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 38,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"strings = ['<tlLogics>\\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' <tlLogic id=\"{node_id}\" type=\"traffic_light\" programID=\"{key}\" offset=\"{start_unix}\">\\n')\n",
|
|
" for i, row in group.iterrows():\n",
|
|
" duration = row.duration\n",
|
|
" state = row.state\n",
|
|
" strings.append(f' <phase duration=\"{duration}\" state=\"{state}\"/>\\n')\n",
|
|
" strings.append(' </tlLogic>\\n')\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 39,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<tlLogics>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704409510, 'c30')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704409510, 'i3')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704409510, 'i9')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"46\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704409510, 'u30')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704409510, 'u31')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i0\" type=\"traffic_light\" programID=\"(1704409590, 'i0')\" offset=\"1704409590\">\n",
|
|
" <phase duration=\"40\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
|
|
" <phase duration=\"29\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
|
|
" <phase duration=\"26\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
|
|
" <phase duration=\"33\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u00\" type=\"traffic_light\" programID=\"(1704409590, 'u00')\" offset=\"1704409590\">\n",
|
|
" <phase duration=\"42\" state=\"ggggGgggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i1\" type=\"traffic_light\" programID=\"(1704409630, 'i1')\" offset=\"1704409630\">\n",
|
|
" <phase duration=\"37\" state=\"gGGGGGrgrr\"/>\n",
|
|
" <phase duration=\"93\" state=\"grrGGGGgrr\"/>\n",
|
|
" <phase duration=\"40\" state=\"grrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704409670, 'c30')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704409670, 'i3')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704409670, 'i9')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"49\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704409670, 'u30')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704409670, 'u31')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i2\" type=\"traffic_light\" programID=\"(1704409720, 'i2')\" offset=\"1704409720\">\n",
|
|
" <phase duration=\"40\" state=\"GGggGGG\"/>\n",
|
|
" <phase duration=\"25\" state=\"rrggrrr\"/>\n",
|
|
" <phase duration=\"34\" state=\"rrggGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u20\" type=\"traffic_light\" programID=\"(1704409720, 'u20')\" offset=\"1704409720\">\n",
|
|
" <phase duration=\"71\" state=\"ggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i0\" type=\"traffic_light\" programID=\"(1704409760, 'i0')\" offset=\"1704409760\">\n",
|
|
" <phase duration=\"40\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
|
|
" <phase duration=\"29\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
|
|
" <phase duration=\"26\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
|
|
" <phase duration=\"33\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u00\" type=\"traffic_light\" programID=\"(1704409760, 'u00')\" offset=\"1704409760\">\n",
|
|
" <phase duration=\"42\" state=\"ggggGgggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i1\" type=\"traffic_light\" programID=\"(1704409800, 'i1')\" offset=\"1704409800\">\n",
|
|
" <phase duration=\"37\" state=\"gGGGGGrgrr\"/>\n",
|
|
" <phase duration=\"93\" state=\"grrGGGGgrr\"/>\n",
|
|
" <phase duration=\"40\" state=\"grrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704409830, 'c30')\" offset=\"1704409830\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704409830, 'i3')\" offset=\"1704409830\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704409830, 'u30')\" offset=\"1704409830\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704409830, 'u31')\" offset=\"1704409830\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704409840, 'i9')\" offset=\"1704409840\">\n",
|
|
" <phase duration=\"46\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i8\" type=\"traffic_light\" programID=\"(1704409860, 'i8')\" offset=\"1704409860\">\n",
|
|
" <phase duration=\"30\" state=\"grrrrrrrgGGGgrrr\"/>\n",
|
|
" <phase duration=\"36\" state=\"grrrrrrrgrrrgGGG\"/>\n",
|
|
" <phase duration=\"18\" state=\"grrrGGGrgrrrgGGr\"/>\n",
|
|
" <phase duration=\"58\" state=\"grrrGGGGgrrrgrrr\"/>\n",
|
|
" <phase duration=\"18\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i2\" type=\"traffic_light\" programID=\"(1704409890, 'i2')\" offset=\"1704409890\">\n",
|
|
" <phase duration=\"40\" state=\"GGggGGG\"/>\n",
|
|
" <phase duration=\"25\" state=\"rrggrrr\"/>\n",
|
|
" <phase duration=\"34\" state=\"rrggGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u20\" type=\"traffic_light\" programID=\"(1704409890, 'u20')\" offset=\"1704409890\">\n",
|
|
" <phase duration=\"71\" state=\"ggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i6\" type=\"traffic_light\" programID=\"(1704409910, 'i6')\" offset=\"1704409910\">\n",
|
|
" <phase duration=\"24\" state=\"grrrgGGGrgrrgrrr\"/>\n",
|
|
" <phase duration=\"19\" state=\"grrrgGGGrgrrgGGr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrgrrrrgrrgGGG\"/>\n",
|
|
" <phase duration=\"65\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"23\" state=\"grrrgrrrrgGGgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i0\" type=\"traffic_light\" programID=\"(1704409930, 'i0')\" offset=\"1704409930\">\n",
|
|
" <phase duration=\"40\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
|
|
" <phase duration=\"29\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
|
|
" <phase duration=\"26\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
|
|
" <phase duration=\"33\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u00\" type=\"traffic_light\" programID=\"(1704409930, 'u00')\" offset=\"1704409930\">\n",
|
|
" <phase duration=\"42\" state=\"ggggGgggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i1\" type=\"traffic_light\" programID=\"(1704409970, 'i1')\" offset=\"1704409970\">\n",
|
|
" <phase duration=\"37\" state=\"gGGGGGrgrr\"/>\n",
|
|
" <phase duration=\"93\" state=\"grrGGGGgrr\"/>\n",
|
|
" <phase duration=\"40\" state=\"grrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704409990, 'c30')\" offset=\"1704409990\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704409990, 'i3')\" offset=\"1704409990\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704409990, 'u30')\" offset=\"1704409990\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704409990, 'u31')\" offset=\"1704409990\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704410000, 'i9')\" offset=\"1704410000\">\n",
|
|
" <phase duration=\"46\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i8\" type=\"traffic_light\" programID=\"(1704410020, 'i8')\" offset=\"1704410020\">\n",
|
|
" <phase duration=\"30\" state=\"grrrrrrrgGGGgrrr\"/>\n",
|
|
" <phase duration=\"36\" state=\"grrrrrrrgrrrgGGG\"/>\n",
|
|
" <phase duration=\"18\" state=\"grrrGGGrgrrrgGGr\"/>\n",
|
|
" <phase duration=\"58\" state=\"grrrGGGGgrrrgrrr\"/>\n",
|
|
" <phase duration=\"18\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i2\" type=\"traffic_light\" programID=\"(1704410060, 'i2')\" offset=\"1704410060\">\n",
|
|
" <phase duration=\"40\" state=\"GGggGGG\"/>\n",
|
|
" <phase duration=\"25\" state=\"rrggrrr\"/>\n",
|
|
" <phase duration=\"34\" state=\"rrggGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u20\" type=\"traffic_light\" programID=\"(1704410060, 'u20')\" offset=\"1704410060\">\n",
|
|
" <phase duration=\"71\" state=\"ggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i6\" type=\"traffic_light\" programID=\"(1704410080, 'i6')\" offset=\"1704410080\">\n",
|
|
" <phase duration=\"24\" state=\"grrrgGGGrgrrgrrr\"/>\n",
|
|
" <phase duration=\"19\" state=\"grrrgGGGrgrrgGGr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrgrrrrgrrgGGG\"/>\n",
|
|
" <phase duration=\"65\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"23\" state=\"grrrgrrrrgGGgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i1\" type=\"traffic_light\" programID=\"(1704410140, 'i1')\" offset=\"1704410140\">\n",
|
|
" <phase duration=\"37\" state=\"gGGGGGrgrr\"/>\n",
|
|
" <phase duration=\"93\" state=\"grrGGGGgrr\"/>\n",
|
|
" <phase duration=\"40\" state=\"grrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704410150, 'c30')\" offset=\"1704410150\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704410150, 'i3')\" offset=\"1704410150\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704410150, 'u30')\" offset=\"1704410150\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704410150, 'u31')\" offset=\"1704410150\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704410160, 'i9')\" offset=\"1704410160\">\n",
|
|
" <phase duration=\"46\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i8\" type=\"traffic_light\" programID=\"(1704410180, 'i8')\" offset=\"1704410180\">\n",
|
|
" <phase duration=\"30\" state=\"grrrrrrrgGGGgrrr\"/>\n",
|
|
" <phase duration=\"36\" state=\"grrrrrrrgrrrgGGG\"/>\n",
|
|
" <phase duration=\"18\" state=\"grrrGGGrgrrrgGGr\"/>\n",
|
|
" <phase duration=\"58\" state=\"grrrGGGGgrrrgrrr\"/>\n",
|
|
" <phase duration=\"18\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
"</tlLogics>\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"strings = ['<tlLogics>\\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' <tlLogic id=\"{node_id}\" type=\"traffic_light\" programID=\"{key}\" offset=\"{start_unix}\">\\n')\n",
|
|
" for i, row in group.iterrows():\n",
|
|
" duration = row.duration\n",
|
|
" state = row.state\n",
|
|
" strings.append(f' <phase duration=\"{duration}\" state=\"{state}\"/>\\n')\n",
|
|
" strings.append(' </tlLogic>\\n')\n",
|
|
"strings.append('</tlLogics>')\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": 40,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<tlLogics>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704409510, 'c30')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704409510, 'i3')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704409510, 'i9')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"46\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704409510, 'u30')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704409510, 'u31')\" offset=\"1704409510\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i0\" type=\"traffic_light\" programID=\"(1704409590, 'i0')\" offset=\"1704409590\">\n",
|
|
" <phase duration=\"40\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
|
|
" <phase duration=\"29\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
|
|
" <phase duration=\"26\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
|
|
" <phase duration=\"33\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u00\" type=\"traffic_light\" programID=\"(1704409590, 'u00')\" offset=\"1704409590\">\n",
|
|
" <phase duration=\"42\" state=\"ggggGgggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i1\" type=\"traffic_light\" programID=\"(1704409630, 'i1')\" offset=\"1704409630\">\n",
|
|
" <phase duration=\"37\" state=\"gGGGGGrgrr\"/>\n",
|
|
" <phase duration=\"93\" state=\"grrGGGGgrr\"/>\n",
|
|
" <phase duration=\"40\" state=\"grrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704409670, 'c30')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704409670, 'i3')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704409670, 'i9')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"49\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704409670, 'u30')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704409670, 'u31')\" offset=\"1704409670\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i2\" type=\"traffic_light\" programID=\"(1704409720, 'i2')\" offset=\"1704409720\">\n",
|
|
" <phase duration=\"40\" state=\"GGggGGG\"/>\n",
|
|
" <phase duration=\"25\" state=\"rrggrrr\"/>\n",
|
|
" <phase duration=\"34\" state=\"rrggGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u20\" type=\"traffic_light\" programID=\"(1704409720, 'u20')\" offset=\"1704409720\">\n",
|
|
" <phase duration=\"71\" state=\"ggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i0\" type=\"traffic_light\" programID=\"(1704409760, 'i0')\" offset=\"1704409760\">\n",
|
|
" <phase duration=\"40\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
|
|
" <phase duration=\"29\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
|
|
" <phase duration=\"26\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
|
|
" <phase duration=\"33\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u00\" type=\"traffic_light\" programID=\"(1704409760, 'u00')\" offset=\"1704409760\">\n",
|
|
" <phase duration=\"42\" state=\"ggggGgggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i1\" type=\"traffic_light\" programID=\"(1704409800, 'i1')\" offset=\"1704409800\">\n",
|
|
" <phase duration=\"37\" state=\"gGGGGGrgrr\"/>\n",
|
|
" <phase duration=\"93\" state=\"grrGGGGgrr\"/>\n",
|
|
" <phase duration=\"40\" state=\"grrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704409830, 'c30')\" offset=\"1704409830\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704409830, 'i3')\" offset=\"1704409830\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704409830, 'u30')\" offset=\"1704409830\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704409830, 'u31')\" offset=\"1704409830\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704409840, 'i9')\" offset=\"1704409840\">\n",
|
|
" <phase duration=\"46\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i8\" type=\"traffic_light\" programID=\"(1704409860, 'i8')\" offset=\"1704409860\">\n",
|
|
" <phase duration=\"30\" state=\"grrrrrrrgGGGgrrr\"/>\n",
|
|
" <phase duration=\"36\" state=\"grrrrrrrgrrrgGGG\"/>\n",
|
|
" <phase duration=\"18\" state=\"grrrGGGrgrrrgGGr\"/>\n",
|
|
" <phase duration=\"58\" state=\"grrrGGGGgrrrgrrr\"/>\n",
|
|
" <phase duration=\"18\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i2\" type=\"traffic_light\" programID=\"(1704409890, 'i2')\" offset=\"1704409890\">\n",
|
|
" <phase duration=\"40\" state=\"GGggGGG\"/>\n",
|
|
" <phase duration=\"25\" state=\"rrggrrr\"/>\n",
|
|
" <phase duration=\"34\" state=\"rrggGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u20\" type=\"traffic_light\" programID=\"(1704409890, 'u20')\" offset=\"1704409890\">\n",
|
|
" <phase duration=\"71\" state=\"ggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i6\" type=\"traffic_light\" programID=\"(1704409910, 'i6')\" offset=\"1704409910\">\n",
|
|
" <phase duration=\"24\" state=\"grrrgGGGrgrrgrrr\"/>\n",
|
|
" <phase duration=\"19\" state=\"grrrgGGGrgrrgGGr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrgrrrrgrrgGGG\"/>\n",
|
|
" <phase duration=\"65\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"23\" state=\"grrrgrrrrgGGgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i0\" type=\"traffic_light\" programID=\"(1704409930, 'i0')\" offset=\"1704409930\">\n",
|
|
" <phase duration=\"40\" state=\"gGGrgrrrgGGGGrgrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrGgrrrgrrrrGgrr\"/>\n",
|
|
" <phase duration=\"29\" state=\"grrrgGGGgrrrrrgrr\"/>\n",
|
|
" <phase duration=\"26\" state=\"grrrgGGrgrrrrrgGr\"/>\n",
|
|
" <phase duration=\"33\" state=\"grrrgrrrgrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u00\" type=\"traffic_light\" programID=\"(1704409930, 'u00')\" offset=\"1704409930\">\n",
|
|
" <phase duration=\"42\" state=\"ggggGgggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i1\" type=\"traffic_light\" programID=\"(1704409970, 'i1')\" offset=\"1704409970\">\n",
|
|
" <phase duration=\"37\" state=\"gGGGGGrgrr\"/>\n",
|
|
" <phase duration=\"93\" state=\"grrGGGGgrr\"/>\n",
|
|
" <phase duration=\"40\" state=\"grrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704409990, 'c30')\" offset=\"1704409990\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704409990, 'i3')\" offset=\"1704409990\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704409990, 'u30')\" offset=\"1704409990\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704409990, 'u31')\" offset=\"1704409990\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704410000, 'i9')\" offset=\"1704410000\">\n",
|
|
" <phase duration=\"46\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i8\" type=\"traffic_light\" programID=\"(1704410020, 'i8')\" offset=\"1704410020\">\n",
|
|
" <phase duration=\"30\" state=\"grrrrrrrgGGGgrrr\"/>\n",
|
|
" <phase duration=\"36\" state=\"grrrrrrrgrrrgGGG\"/>\n",
|
|
" <phase duration=\"18\" state=\"grrrGGGrgrrrgGGr\"/>\n",
|
|
" <phase duration=\"58\" state=\"grrrGGGGgrrrgrrr\"/>\n",
|
|
" <phase duration=\"18\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i2\" type=\"traffic_light\" programID=\"(1704410060, 'i2')\" offset=\"1704410060\">\n",
|
|
" <phase duration=\"40\" state=\"GGggGGG\"/>\n",
|
|
" <phase duration=\"25\" state=\"rrggrrr\"/>\n",
|
|
" <phase duration=\"34\" state=\"rrggGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u20\" type=\"traffic_light\" programID=\"(1704410060, 'u20')\" offset=\"1704410060\">\n",
|
|
" <phase duration=\"71\" state=\"ggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i6\" type=\"traffic_light\" programID=\"(1704410080, 'i6')\" offset=\"1704410080\">\n",
|
|
" <phase duration=\"24\" state=\"grrrgGGGrgrrgrrr\"/>\n",
|
|
" <phase duration=\"19\" state=\"grrrgGGGrgrrgGGr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrgrrrrgrrgGGG\"/>\n",
|
|
" <phase duration=\"65\" state=\"gGGGgrrrrgrrgrrr\"/>\n",
|
|
" <phase duration=\"23\" state=\"grrrgrrrrgGGgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i1\" type=\"traffic_light\" programID=\"(1704410140, 'i1')\" offset=\"1704410140\">\n",
|
|
" <phase duration=\"37\" state=\"gGGGGGrgrr\"/>\n",
|
|
" <phase duration=\"93\" state=\"grrGGGGgrr\"/>\n",
|
|
" <phase duration=\"40\" state=\"grrrrrrgGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"c30\" type=\"traffic_light\" programID=\"(1704410150, 'c30')\" offset=\"1704410150\">\n",
|
|
" <phase duration=\"39\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"42\" state=\"GGGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"GGGGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i3\" type=\"traffic_light\" programID=\"(1704410150, 'i3')\" offset=\"1704410150\">\n",
|
|
" <phase duration=\"38\" state=\"gGGGrgrrrrgGGGrgrrrr\"/>\n",
|
|
" <phase duration=\"39\" state=\"grrrGgrrrrgrrrGgrrrr\"/>\n",
|
|
" <phase duration=\"42\" state=\"grrrrgrrrrgrrrrgGGGG\"/>\n",
|
|
" <phase duration=\"21\" state=\"grrrrgGGGGgrrrrgrrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u30\" type=\"traffic_light\" programID=\"(1704410150, 'u30')\" offset=\"1704410150\">\n",
|
|
" <phase duration=\"21\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"u31\" type=\"traffic_light\" programID=\"(1704410150, 'u31')\" offset=\"1704410150\">\n",
|
|
" <phase duration=\"38\" state=\"ggggGggg\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i9\" type=\"traffic_light\" programID=\"(1704410160, 'i9')\" offset=\"1704410160\">\n",
|
|
" <phase duration=\"46\" state=\"GGGG\"/>\n",
|
|
" </tlLogic>\n",
|
|
" <tlLogic id=\"i8\" type=\"traffic_light\" programID=\"(1704410180, 'i8')\" offset=\"1704410180\">\n",
|
|
" <phase duration=\"30\" state=\"grrrrrrrgGGGgrrr\"/>\n",
|
|
" <phase duration=\"36\" state=\"grrrrrrrgrrrgGGG\"/>\n",
|
|
" <phase duration=\"18\" state=\"grrrGGGrgrrrgGGr\"/>\n",
|
|
" <phase duration=\"58\" state=\"grrrGGGGgrrrgrrr\"/>\n",
|
|
" <phase duration=\"18\" state=\"gGGGrrrrgrrrgrrr\"/>\n",
|
|
" </tlLogic>\n",
|
|
"</tlLogics>\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"strings = ['<tlLogics>\\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' <tlLogic id=\"{node_id}\" type=\"traffic_light\" programID=\"{key}\" offset=\"{start_unix}\">\\n')\n",
|
|
" for i, row in group.iterrows():\n",
|
|
" duration = row.duration\n",
|
|
" state = row.state\n",
|
|
" strings.append(f' <phase duration=\"{duration}\" state=\"{state}\"/>\\n')\n",
|
|
" strings.append(' </tlLogic>\\n')\n",
|
|
"strings.append('</tlLogics>')\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
|
|
}
|