From 261f1d8e9515e26790bf5da59c622413bc03df70 Mon Sep 17 00:00:00 2001 From: sanginnwoo Date: Sat, 17 Dec 2022 20:20:18 +0900 Subject: [PATCH] From SW's laptop --- batch_process.py | 12 ++----- controller.py | 57 ++++++++++++++++++++------------- settle_prediction_steps_main.py | 26 +++++++-------- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/batch_process.py b/batch_process.py index 269e3cc..f336204 100644 --- a/batch_process.py +++ b/batch_process.py @@ -38,16 +38,8 @@ for input_file in input_files: for i in range(20, 100, 10): # 침하 예측을 수행하고 반환값 저장 - return_values = settle_prediction_steps_main.\ - run_settle_prediction(input_file=input_file, output_dir=output_dir, - final_step_predict_percent=i, - additional_predict_percent=100, - plot_show=False, - print_values=False, - run_original_hyperbolic=True, - run_nonlinear_hyperbolic=True, - run_step_prediction=True, - settle_unit=settle_unit) + return_values = settle_prediction_steps_main. \ + run_settle_prediction(, # 데이터프레임에 일단 및 다단 성토를 포함한 예측의 에러를 저장 df_overall.loc[len(df_overall.index)] = [input_file, i, return_values[0], return_values[1], diff --git a/controller.py b/controller.py index 6655b03..5bb0eb4 100644 --- a/controller.py +++ b/controller.py @@ -25,7 +25,8 @@ nod: number of date def settlement_prediction(point_name): # connect the database - connection = pg2.connect("host=localhost dbname=postgres user=postgres password=lab36981 port=5432") + #connection = pg2.connect("host=localhost dbname=postgres user=postgres password=lab36981 port=5432") # local + connection = pg2.connect("host=192.168.0.13 dbname=sgis user=sgis password=sgis port=5432") # ICTWay internal # set cursor cursor = connection.cursor() @@ -43,9 +44,9 @@ def settlement_prediction(point_name): # fill lists for row in monitoring_record: - settlement.append(float(row[6])) - surcharge.append(float(row[8])) - time.append(float(row[12])) + settlement.append(float(row[5])) + surcharge.append(float(row[7])) + time.append(float(row[1])) # convert lists to np arrays settlement = np.array(settlement) @@ -53,19 +54,14 @@ def settlement_prediction(point_name): time = np.array(time) # run the settlement prediction and get results - results = settle_prediction_steps_main.run_settle_prediction(point_name=point_name, - np_time=time, - np_surcharge=surcharge, - np_settlement=settlement, + results = settle_prediction_steps_main.run_settle_prediction(point_name=point_name, np_time=time, + np_surcharge=surcharge, np_settlement=settlement, final_step_predict_percent=90, - additional_predict_percent=300, - plot_show=False, - print_values=False, - run_original_hyperbolic=True, + additional_predict_percent=300, plot_show=False, + print_values=False, run_original_hyperbolic=True, run_nonlinear_hyperbolic=True, run_weighted_nonlinear_hyperbolic=True, - run_asaoka=True, - run_step_prediction=True, + run_asaoka=True, run_step_prediction=True, asaoka_interval=3) # if there are prediction data for the given data point, delete it first @@ -73,6 +69,14 @@ def settlement_prediction(point_name): cursor.execute(postgres_delete_query) connection.commit() + # prediction method code + # 0: original hyperbolic method + # 1: nonlinear hyperbolic method + # 2: weighted nonlinear hyperbolic method + # 3: Asaoka method + # 4: Step loading + # 5: temp + # insert predicted settlement into database for i in range(5): @@ -85,7 +89,8 @@ def settlement_prediction(point_name): # construct insert query postgres_insert_query \ - = """INSERT INTO apptb_pred02 (cons_code, prediction_progress_days, predicted_settlement, prediction_method) """\ + = """INSERT INTO apptb_pred02 """ \ + + """(cons_code, prediction_progress_days, predicted_settlement, prediction_method) """ \ + """VALUES (%s, %s, %s, %s)""" # set data to insert @@ -128,8 +133,18 @@ def read_database_and_plot(point_name): surcharge_monitored = np.array(surcharge_monitored) time_monitored = np.array(time_monitored) + # prediction method code + # 0: original hyperbolic method + # 1: nonlinear hyperbolic method + # 2: weighted nonlinear hyperbolic method + # 3: Asaoka method + # 4: Step loading + # 5: temp + + # temporarily set the prediction method as 0 prediction_method = 0 - # select monitoring data for the monitoring point + + # select predicted data for the monitoring point postgres_select_query = """SELECT prediction_progress_days, predicted_settlement """ \ + """FROM apptb_pred02 WHERE cons_code= '""" + point_name \ + """' and prediction_method = """ + str(prediction_method) \ @@ -169,12 +184,10 @@ def read_database_and_plot(point_name): linestyle='--', color='red', label='Original Hyperbolic') - -# python3 controller.py 1_SP-5 +# script to call: python3 controller.py [business_code] [cons_code] +# for example: if __name__ == '__main__': args = sys.argv[1:] point_name = args[0] - #settlement_prediction(point_name=point_name) - read_database_and_plot(point_name=point_name) - - + settlement_prediction(point_name=point_name) +# read_database_and_plot(point_name=point_name) #DB 입력 결과 확인 시에 활성화 / 평소에는 비활성화 \ No newline at end of file diff --git a/settle_prediction_steps_main.py b/settle_prediction_steps_main.py index b29c50a..88cea43 100644 --- a/settle_prediction_steps_main.py +++ b/settle_prediction_steps_main.py @@ -79,19 +79,12 @@ def run_settle_prediction_from_file(input_file, output_dir, settle = data['Settlement'].to_numpy() surcharge = data['Surcharge'].to_numpy() - run_settle_prediction(point_name=input_file, - np_time=time, - np_surcharge=surcharge, - np_settlement=settle, + run_settle_prediction(point_name=input_file, np_time=time, np_surcharge=surcharge, np_settlement=settle, final_step_predict_percent=final_step_predict_percent, - additional_predict_percent=additional_predict_percent, - plot_show=plot_show, - print_values=print_values, - run_original_hyperbolic=run_original_hyperbolic, - run_nonlinear_hyperbolic=run_nonlinear_hyperbolic, - run_weighted_nonlinear_hyperbolic='False', - run_asaoka=run_asaoka, - run_step_prediction=run_step_prediction, + additional_predict_percent=additional_predict_percent, plot_show=plot_show, + print_values=print_values, run_original_hyperbolic=run_original_hyperbolic, + run_nonlinear_hyperbolic=run_nonlinear_hyperbolic, run_weighted_nonlinear_hyperbolic='False', + run_asaoka=run_asaoka, run_step_prediction=run_step_prediction, asaoka_interval=asaoka_interval) def run_settle_prediction(point_name, @@ -101,10 +94,10 @@ def run_settle_prediction(point_name, print_values, run_original_hyperbolic='True', run_nonlinear_hyperbolic='True', - run_weighted_nonlinear_hyperbolic='False', + run_weighted_nonlinear_hyperbolic='True', run_asaoka = 'True', run_step_prediction='True', - asaoka_interval = 3): + asaoka_interval = 5): # ==================== # 파일 읽기, 데이터 설정 @@ -757,6 +750,11 @@ def run_settle_prediction(point_name, final_error_hyper_original, final_error_hyper_nonlinear, final_error_hyper_weight_nonlinear, final_error_asaoka, final_error_step] +#def run_postprocessing_error(point_name, np_time, np_surcharge, np_settlement): +# a = a + 1 + +#def run_postprocessing_graph(point_name, np_time, np_surcharge, np_) +# ''' run_settle_prediction(input_file='data/2-5_No.39.csv', output_dir='output',