Browse Source

generate_signals.py : introduce self.sim_timespan, add parser (not tested), preprocess_signal.py : fix a specific date.

master
김선중 1 year ago
parent
commit
333d61a5ac
4 changed files with 1795 additions and 105 deletions
  1. BIN
      Documents/신호생성 정리(240712).pptx
  2. +12
    -9
      Scripts/generate_signals.py
  3. +1
    -1
      Scripts/preprocess_daily.py
  4. +1782
    -95
      analysis/0712_revise_code/0717_revise_code.ipynb

BIN
Documents/신호생성 정리(240712).pptx View File


+ 12
- 9
Scripts/generate_signals.py View File

@ -1,13 +1,10 @@
# python .\Scripts\generate_signals.py
import pandas as pd
import numpy as np
import os, sys
import json
import copy
from tqdm import tqdm
import os, sys, json, argparse
import sumolib, traci
from tqdm import tqdm
from datetime import datetime
import time
class SignalGenerator():
def __init__(self, config_name='draft'):
@ -34,6 +31,7 @@ class SignalGenerator():
self.present_time = datetime.now().replace(month=1, day=5, hour=10).timestamp()
self.present_time = max([fmin for fmin in list(self.fmins) if fmin <= self.present_time])
self.sim_timespan = 300
self.adder = 600 # 10분 : '현재시점 + 10분'에 가상신호를 생성하기 위함.
self.subtractor = 1800 # 30분 : '현재시점 - 30분'의 신호이력을 가져온다.
@ -457,7 +455,7 @@ class SignalGenerator():
# 3-1. movement
def make_movement(self):
# - 아래 절차를 5초마다 반복
for fsec in range(self.present_time - 300, self.present_time + 1, 5): # fsec : unix time by Five SECond
for fsec in range(self.present_time - self.sim_timespan, self.present_time + 1, 5): # fsec : unix time by Five SECond
# 1. 상태 테이블 조회해서 전체 데이터중 필요데이터(교차로번호, A링 현시번호, A링 이동류번호, B링 현시번호, B링 이동류번호)만 수집 : A
move = pd.read_csv(os.path.join(self.path_tables, 'move', f'move_{fsec}.csv'), index_col=0)
# 2. 이력 테이블 조회해서 교차로별로 유닉스시간 최대인 데이터(교차로번호, 종료유닉스타임)만 수집 : B
@ -608,14 +606,14 @@ class SignalGenerator():
def set_timepoints(self):
self.offsets = {}
self.sigtable = []
sim_start = self.present_time - 300
sim_start = self.present_time - self.sim_timespan
for node_id, group in self.histids.groupby('node_id'):
lsbs = group[group['start_unix'] < sim_start]['start_unix'].max() # the last start_unix before sim_start
self.offsets[node_id] = lsbs - sim_start
group = group[group.start_unix >= lsbs]
start_unixes = np.array(group.start_unix)
start_unixes = np.sort(np.unique(start_unixes))[:self.node2num_cycles[node_id]]
group = group[group.start_unix.isin(start_unixes)]
self.sigtable.append(group)
self.sigtable = pd.concat(self.sigtable).reset_index(drop=True)
@ -855,7 +853,12 @@ class SignalGenerator():
print('total time :', self.time6 - self.time0)
if __name__ == '__main__':
self = SignalGenerator()
parser = argparse.ArgumentParser()
parser.add_argument('-c','--config_name', dest='config_name', type=str, default='draft')
args = parser.parse_args()
config_name = args.config_name
self = SignalGenerator(config_name=config_name)
self.main()
# self.path_unit = os.path.join(self.path_root, 'Analysis', '0207_unit_test')
# self.hrhists.to_csv(os.path.join(self.path_unit, 'hrhists.csv'))

+ 1
- 1
Scripts/preprocess_daily.py View File

@ -272,7 +272,7 @@ class DailyPreprocessor():
'PPC_TYPE', 'LOS_YN', 'USE_YN', 'FRST_REG_DT', 'LAST_MDFCN_DT'])
# 날짜정보 추출
now = datetime.now()
now = datetime.now().replace(month=1, day=5, hour=10)
MM, DD = now.month, now.day # 월, 일
hplan = self.holyplan[(self.holyplan.MM==MM) & (self.holyplan.DD==DD)]
dow_number = now.weekday() # 요일

+ 1782
- 95
analysis/0712_revise_code/0717_revise_code.ipynb
File diff suppressed because it is too large
View File


Loading…
Cancel
Save