In [2]:
import sumolib, math
import pandas as pd
import numpy as np
import os, glob
from datetime import datetime
### intersections
intersections_path = os.path.join('daily/S_INT_CONFIG.csv')
intersections = pd.read_csv(intersections_path)
intersections_original = intersections.copy()
# demo names
demo_names = \
["한솔삼거리(한솔마을3거리)",
"느티마을4단지",
"한솔6단지(정자동사무소)",
"신기4거리",
"느티마을4거리",
"느티마을 안촌유치원",
"상록마을 321동",
"상록4거리(상록마을입구4거리)",
"상록마을단일로",
"상록마을302동 단일로"]
intersections = intersections[intersections['INT_NAME'].isin(demo_names)]
demo_node_ids = ["n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"]
demo_int_nos = list(intersections['INT_NO'])
# SUMO node_id 정보 추가
name2node_id = dict(zip(demo_names, demo_node_ids))
intersections['node_ids'] = intersections['INT_NAME'].map(name2node_id)
# SUMO X, Y 좌표 정보 추가
origin_name = '상록4거리(상록마을입구4거리)'
ref_lng = intersections[intersections['INT_NAME'] == origin_name]['INT_LNG'].values[0]
ref_lat = intersections[intersections['INT_NAME'] == origin_name]['INT_LAT'].values[0]
intersections['X'] = (intersections['INT_LNG'] - ref_lng) * 111000 * math.cos(math.radians(ref_lat))
intersections['Y'] = (intersections['INT_LAT'] - ref_lat) * 111000
intersections.reset_index(drop=True, inplace=True)
# n=ways 정보 추가 where "n지교차로"
name2way = \
{"한솔삼거리(한솔마을3거리)":3,
"느티마을4단지":3,
"한솔6단지(정자동사무소)":4,
"신기4거리":4,
"느티마을4거리":4,
"느티마을 안촌유치원":2,
"상록마을 321동":2,
"상록4거리(상록마을입구4거리)":4,
"상록마을단일로":2,
"상록마을302동 단일로":2}
intersections['ways'] = intersections['INT_NAME'].map(name2way)
### phase_config
phase_config_path = os.path.join('daily/S_INT_PHASE_CONFIG.csv')
phase_config = pd.read_csv(phase_config_path)
phase_config_original = phase_config.copy()
phase_config = phase_config[phase_config['INT_NO'].isin(demo_int_nos)]
# INT_NO, ways 가져옴
phase_config = pd.merge(phase_config, intersections[['INT_NO', 'ways']], on='INT_NO', how='left')
cols = phase_config.columns.tolist()
cols.remove('ways')
cols.insert(1, 'ways')
phase_config = phase_config[cols]
# 링번호 변경, 주현시여부, 황색시간, 최소녹색시간, 최대녹색시간 임의 지정
phase_config['INT_RING'] = phase_config['INT_RING'].replace({0: 'A', 1: 'B'})
phase_config['INT_MAIN_PHASE'] = np.where(phase_config['INT_PHASE_NO'] == 1, 20, 10)
null_condition = phase_config['INT_FLOW_NO'] == 17
phase_config['INT_YELLOW'] = np.where(null_condition, 0, 4)
np.random.seed(0)
phase_config['INT_MIN_SPLIT'] = np.where(~null_condition, np.random.randint(12, 41, size=len(phase_config)), phase_config['INT_MIN_SPLIT'])
phase_config['INT_MAX_SPLIT'] = np.where(~null_condition, phase_config['INT_MIN_SPLIT'] + np.random.randint(5, 20, size=len(phase_config)) ,phase_config['INT_MAX_SPLIT'])
phase_config.sort_values(by=['INT_NO', 'INT_PHASE_NO','INT_RING'], inplace=True)
In [ ]:
# 1. 교차로정보 (intersections, 테이블명 : S_INT_CONFIG)
intersections_original[:10]
Out[ ]:
In [ ]:
# 1*. 교차로정보 수정 (데모버전)
intersections[:10]
Out[ ]:
In [ ]:
# 2. 현시정보 (phase_config, 테이블명 : S_INT_PHASE_CONFIG)
phase_config_original[:10]
Out[ ]:
In [ ]:
# 2*. 현시정보 수정 (데모버전)
phase_config[:10]
Out[ ]:
In [ ]:
### tplan
tplan_path = os.path.join('daily/S_INT_TPLAN.csv')
tplan = pd.read_csv(tplan_path)
# cycleplan
cycleplan_path = os.path.join(recent_folder, 'daily/S_SA_CYCLE_PLAN.csv')
cycleplan = pd.read_csv(cycleplan_path)
# wplan
wplan_path = os.path.join(recent_folder, 'daily/S_SA_WPLAN.csv')
wplan = pd.read_csv(wplan_path)
# dplan
dplan_path = os.path.join(recent_folder, 'daily/S_SA_DPLAN.csv')
dplan = pd.read_csv(dplan_path)
# history
history_path = os.path.join(recent_folder, 'realtime/S_TOD_HIS.csv')
history= pd.read_csv(history_path)
In [ ]:
# 3. 신호계획정보 (tplan, wplan, dplan, 테이블명 : S_INT_TPLAN, S_INT_WPLAN, S_INT_DPLAN)
display(tplan[:10])
display(wplan[:10])
display(dplan[:10])
In [ ]:
# 4. 신호이력정보 (history, 테이블명 : S_TOD_HIS)
history
Out[ ]: