From 0bb500fe4af299d36e767503c4bf12c41e09dbc7 Mon Sep 17 00:00:00 2001 From: govin08 Date: Thu, 11 Apr 2024 13:35:42 +0900 Subject: [PATCH] made 'fetchall' option for make_match1 --- .../0411_unp-left.ipynb | 347 +++++++++ Results/sn_1704418200.add.xml | 684 +++++++++--------- Scripts/preprocess_daily.py | 35 +- 3 files changed, 708 insertions(+), 358 deletions(-) create mode 100644 Analysis/0411_unp-left_p-right-uturn/0411_unp-left.ipynb diff --git a/Analysis/0411_unp-left_p-right-uturn/0411_unp-left.ipynb b/Analysis/0411_unp-left_p-right-uturn/0411_unp-left.ipynb new file mode 100644 index 000000000..f1d14e145 --- /dev/null +++ b/Analysis/0411_unp-left_p-right-uturn/0411_unp-left.ipynb @@ -0,0 +1,347 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import pandas as pd\n", + "import numpy as np\n", + "import sys\n", + "sys.path.append('../../Scripts')\n", + "from preprocess_daily import DailyPreprocessor\n", + "from generate_signals import SignalGenerator" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "줄임말 목록\n", + "- `i` : 교차로번호, `inter_no`\n", + "- `f` : 진입, from, `inc_edge_id`\n", + "- `t` : 진출, to, `out_edge_id`\n", + "- `vec` : 방향벡터, unit vector (`np.array([0.6, 0.8])`)\n", + "- `dire` : 방위, direction (동, 서, 남, 북, 북동, 북서, 남동, 남서)\n", + "- `rvec` : 정방향 방향벡터, unit vector to the right direction (`np.array([0,1])`)\n", + "\n", + "필요한 객체들 목록\n", + "\n", + "- `i2dire2rvec` : `inter_no` $\\mapsto$ `dire2rvec`\n", + " - `dire2rvec` : `dire` $\\mapsto$ `rvec`\n", + "- `i2f` : `inter_no` $\\mapsto$ `f_edges`\n", + "- `i2t` : `inter_no` $\\mapsto$ `t_edges`\n", + "- `i2f2dire` : `inter_no` $\\mapsto$ `f21dire`\n", + " - `f2dire` : `from_edge` $\\mapsto$ `dire`\n", + "- `i2t2dire` : `inter_no` $\\mapsto$ `t21dire`\n", + " - `t2dire` : `to_edge` $\\mapsto$ `dire`" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1. 데이터를 로드합니다.\n", + "1-1. 네트워크가 로드되었습니다.\n", + "1-2. 테이블들이 로드되었습니다.\n", + "1-3. 네트워크의 모든 clean state requirement들을 체크했습니다.\n", + "1-4. 테이블들의 무결성 검사를 완료했습니다.\n", + "2. 중간산출물을 생성합니다.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "이동류정보 불러오는 중: 100%|██████████| 17280/17280 [00:14<00:00, 1185.13it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2-1. 매칭 테이블들을 생성했습니다.\n", + "2-2. 비보호우회전(g)을 배정했습니다.\n", + "2-3. 직진 및 좌회전(G)을 배정했습니다.\n", + "2-2. node2num_cycles.json를 저장했습니다.\n", + "3. 이슈사항을 저장합니다.\n" + ] + } + ], + "source": [ + "self = DailyPreprocessor()\n", + "self.main()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "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", + "
inter_nophase_noring_typemove_noinc_dirout_dirinc_angleout_angle
01751A8179179
11751B4001001
21752A7001001
31752B3179179
41753A6090090
\n", + "
" + ], + "text/plain": [ + " inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle\n", + "0 175 1 A 8 남 북 179 179\n", + "1 175 1 B 4 북 남 001 001\n", + "2 175 2 A 7 북 동 001 001\n", + "3 175 2 B 3 남 서 179 179\n", + "4 175 3 A 6 동 서 090 090" + ] + }, + "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", + "
inter_nophase_noring_typemove_noinc_dirout_dirinc_angleout_angleinc_edgeout_edgenode_id
01751A8179179-571542797_02571542797_02i0
11751B4001001-571500487_01571500487_01i0
21752A7001001-571500487_01571500487_01i0
31752B3179179-571542797_02571542797_02i0
41753A6090090571545870_02571545870_01i0
\n", + "
" + ], + "text/plain": [ + " inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n", + "0 175 1 A 8 남 북 179 179 \n", + "1 175 1 B 4 북 남 001 001 \n", + "2 175 2 A 7 북 동 001 001 \n", + "3 175 2 B 3 남 서 179 179 \n", + "4 175 3 A 6 동 서 090 090 \n", + "\n", + " inc_edge out_edge node_id \n", + "0 -571542797_02 571542797_02 i0 \n", + "1 -571500487_01 571500487_01 i0 \n", + "2 -571500487_01 571500487_01 i0 \n", + "3 -571542797_02 571542797_02 i0 \n", + "4 571545870_02 571545870_01 i0 " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "display(self.match4.head())\n", + "display(self.match5.head())" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "sts", + "language": "python", + "name": "sts" + }, + "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 +} diff --git a/Results/sn_1704418200.add.xml b/Results/sn_1704418200.add.xml index 6a4fce0a7..350cbbb64 100644 --- a/Results/sn_1704418200.add.xml +++ b/Results/sn_1704418200.add.xml @@ -1,90 +1,90 @@ - + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + - - - - - - - - - - - + + - - - - - + + + + + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + @@ -94,13 +94,13 @@ - + - + - + @@ -117,7 +117,7 @@ - + @@ -162,110 +162,110 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + @@ -310,125 +310,125 @@ - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - - + + + - - + + - - + + - - + + - - + + - - + + - + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + @@ -473,197 +473,197 @@ - + - - + + - - + + - - + + - - - - + - - + + - - - - - + + - + + + + - - + + - - - - - + + - + + + + - - + + + + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + \ No newline at end of file diff --git a/Scripts/preprocess_daily.py b/Scripts/preprocess_daily.py index 835509686..d9aceb58a 100644 --- a/Scripts/preprocess_daily.py +++ b/Scripts/preprocess_daily.py @@ -203,7 +203,7 @@ class DailyPreprocessor(): print('2-1. 매칭 테이블들을 생성했습니다.') # 2-1-1 - def make_match1(self): + def make_match1(self,fetch_all:bool=False): ''' 신호 DB에는 매 초마다 이동류정보가 업데이트 된다. 그리고 이 이동류정보를 매 5초마다 불러와서 사용하게 된다. '../Data/tables/move/'에는 5초마다의 이동류정보가 저장되어 있다. @@ -213,21 +213,24 @@ class DailyPreprocessor(): match1을 만드는 데 시간이 소요되므로 한 번 만들어서 저장해두고 저장해둔 것을 쓴다. ''' - # [이동류번호] 불러오기 (약 1분의 소요시간) - path_move = os.path.join(self.path_tables, 'move') - csv_moves = os.listdir(path_move) - moves = [pd.read_csv(os.path.join(path_move, csv_move), index_col=0) for csv_move in tqdm(csv_moves, desc='이동류정보 불러오는 중')] - df = pd.concat(moves).reset_index(drop=True) - self.match1 = [] - for i, group in df.groupby(['inter_no', 'phas_A', 'phas_B']): - inter_no, phas_A, phas_B = i - pairs_array = np.array(group[['move_A', 'move_B']]) - unique_pairs, counts = np.unique(pairs_array, axis=0, return_counts=True) - frequent_pair = unique_pairs[np.argmax(counts)] - self.match1.append(pd.DataFrame({'inter_no':[inter_no], 'phas_A':[phas_A], 'phas_B':[phas_B], - 'move_A':[frequent_pair[0]], 'move_B':[frequent_pair[1]]})) - self.match1 = pd.concat(self.match1).reset_index(drop=True) - self.match1.to_csv(os.path.join(self.path_intermediates, 'match1.csv')) + if fetch_all: + # [이동류번호] 불러오기 (약 1분의 소요시간) + path_move = os.path.join(self.path_tables, 'move') + csv_moves = os.listdir(path_move) + moves = [pd.read_csv(os.path.join(path_move, csv_move), index_col=0) for csv_move in tqdm(csv_moves, desc='이동류정보 불러오는 중')] + df = pd.concat(moves).reset_index(drop=True) + self.match1 = [] + for i, group in df.groupby(['inter_no', 'phas_A', 'phas_B']): + inter_no, phas_A, phas_B = i + pairs_array = np.array(group[['move_A', 'move_B']]) + unique_pairs, counts = np.unique(pairs_array, axis=0, return_counts=True) + frequent_pair = unique_pairs[np.argmax(counts)] + self.match1.append(pd.DataFrame({'inter_no':[inter_no], 'phas_A':[phas_A], 'phas_B':[phas_B], + 'move_A':[frequent_pair[0]], 'move_B':[frequent_pair[1]]})) + self.match1 = pd.concat(self.match1).reset_index(drop=True) + self.match1.to_csv(os.path.join(self.path_intermediates, 'match1.csv')) + else: + self.match1 = pd.read_csv(os.path.join(self.path_intermediates, 'match1.csv')) # 2-1-2 def make_match2(self):