{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import os, sys, json, argparse, pickle\n", "import sumolib, traci\n", "from tqdm import tqdm\n", "from datetime import datetime, timedelta\n", "path_root = os.path.dirname(os.path.dirname(os.path.abspath('.')))\n", "path_scr = os.path.join(path_root, 'scripts')\n", "sys.path.append(path_scr)\n", "# from preprocess_daily import DailyPreprocessor\n", "from generate_signals import SignalGenerator" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "self = SignalGenerator()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1. 데이터를 준비합니다.\n", "1-1. 네트워크가 로드되었습니다.\n", "1-2. 테이블들이 로드되었습니다.\n", "1-5. 필요한 보조 객체들이 모두 준비되었습니다.\n", "2. 신호이력 테이블을 변환합니다.\n", "3. 이동류정보 테이블을 변환합니다.\n", "4. 통합 테이블을 생성합니다.\n" ] } ], "source": [ "self.prepare_data()\n", "self.process_history()\n", "self.process_movement()\n", "self.make_histids()\n", "self.set_timepoints()\n", "self.assign_red_yellow()" ] }, { "cell_type": "code", "execution_count": 8, "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", "
node_idstart_unixphasedurationstate
010623117223839681g_1g11grgrrGGG
110623117223839681y_1y4grgrrGGy
210623117223839682g_2g24grgGGGGr
310623117223839682y_2y4grgyyyyr
410623117223839683g_3g8gGgrrrrr
..................
25010998617223847001g_1g67gGGGGrgrrgGGGGrgrr
25110998617223847001y_1y4gyyyyrgrrgyyyyrgrr
25210998617223847002g_2g24grrrrGgrrgrrrrGgrr
25310998617223847002y_2y4grrrrygrrgrrrrygrr
25410998617223847003g_3g54grrrrrgGGgrrrrrgrr
\n", "

255 rows × 5 columns

\n", "
" ], "text/plain": [ " node_id start_unix phase duration state\n", "0 106231 1722383968 1g_1g 11 grgrrGGG\n", "1 106231 1722383968 1y_1y 4 grgrrGGy\n", "2 106231 1722383968 2g_2g 24 grgGGGGr\n", "3 106231 1722383968 2y_2y 4 grgyyyyr\n", "4 106231 1722383968 3g_3g 8 gGgrrrrr\n", ".. ... ... ... ... ...\n", "250 109986 1722384700 1g_1g 67 gGGGGrgrrgGGGGrgrr\n", "251 109986 1722384700 1y_1y 4 gyyyyrgrrgyyyyrgrr\n", "252 109986 1722384700 2g_2g 24 grrrrGgrrgrrrrGgrr\n", "253 109986 1722384700 2y_2y 4 grrrrygrrgrrrrygrr\n", "254 109986 1722384700 3g_3g 54 grrrrrgGGgrrrrrgrr\n", "\n", "[255 rows x 5 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "self.SIGTABLE = self.SIGTABLE.reset_index(drop=True)\n", "self.SIGTABLE" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{(0, 1): 1,\n", " (1, 2): 3,\n", " (2, 3): 5,\n", " (3, 4): 7,\n", " (4, 5): 9,\n", " (5, 6): 11,\n", " (6, 7): 13,\n", " (7, 8): 15,\n", " (8, 9): 17}" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = range(10)\n", "B = dict()\n", "for a, b in zip(A[:-1], A[1:]):\n", " B[a, b] = a + b\n", "B" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "improper_pairs = dict()\n", "improper_pairs['ry'] = []\n", "improper_pairs['Gr'] = []\n", "improper_pairs['yG'] = []\n", "for node_id, group in self.SIGTABLE.groupby('node_id'):\n", " state_length = len(group.iloc[0].state)\n", " # 상태를 리스트로 변환\n", " state_lists = group['state'].apply(list)\n", " # 새로운 열들을 한 번에 추가\n", " cnxnwises = {str(j): [state[j] for state in state_lists] for j in range(state_length)}\n", " for state_order in cnxnwises:\n", " cnxnwise = cnxnwises[state_order]\n", " for phase_order, (p, q) in enumerate(zip(cnxnwise[:-1], cnxnwise[1:])):\n", " if (p, q) == ('r', 'y'):\n", " improper_pairs['ry'].append({'node_id':node_id, 'state_order':state_order, 'phase_order':phase_order})\n", " if (p, q) == ('G', 'r'):\n", " improper_pairs['Gr'].append({'node_id':node_id, 'state_order':state_order, 'phase_order':phase_order})\n", " if (p, q) == ('y', 'G'):\n", " improper_pairs['ry'].append({'node_id':node_id, 'state_order':state_order, 'phase_order':phase_order})\n", "if any(value for value in improper_pairs.values()):\n", " print('부적절하게 연속된 신호조합(r->y, G->r, y->G)이 존재합니다 :')\n", " print(improper_pairs)" ] } ], "metadata": { "kernelspec": { "display_name": "siggen_env", "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.12.4" } }, "nbformat": 4, "nbformat_minor": 2 }