From ec16712498999ddc963e897b71401cda4b8a0e67 Mon Sep 17 00:00:00 2001 From: sanginnwoo Date: Mon, 5 Dec 2022 16:41:58 +0900 Subject: [PATCH] From SW's laptop --- controller.py | 46 +++++++++++++++++++++---- settle_prediction_steps_main.py | 61 +++++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 25 deletions(-) diff --git a/controller.py b/controller.py index 1113ba2..79636ee 100644 --- a/controller.py +++ b/controller.py @@ -5,19 +5,53 @@ Sang Inn Woo, Ph.D. @ Incheon National University Starting Date: 2022-11-10 """ import psycopg2 as pg2 +import numpy as np import settle_prediction_steps_main + +''' +apptb_surset01 +cons_code: names of monitoring points + +apptb_surset02 +cons_code: names of monitoring points +amount_cum_sub: accumulated settlement +fill_height: height of surcharge fill +nod: number of date +''' + + # connect the database -conn = 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") # set cursor -cur = conn.cursor() +cursor = connection.cursor() -# read data +# select all monitoring points +postgres_select_query = """SELECT * FROM apptb_surset01""" +cursor.execute(postgres_select_query) +point_record = cursor.fetchall() +# for a monitoring point, set name +point_name = point_record[0][3] -# extract settlement prediction data using the prime key +# select monitoring data for the monitoring point +postgres_select_query = """SELECT * FROM apptb_surset02 WHERE cons_code='""" \ + + point_name + """' ORDER BY nod ASC""" +cursor.execute(postgres_select_query) +monitoring_record = cursor.fetchall() -# run settlement analysis +# initialize time, surcharge, and settlement lists +time = [] +surcharge = [] +settlement = [] -# save results in the database \ No newline at end of file +# fill list +for row in monitoring_record: + settlement.append(float(row[6])) + surcharge.append(float(row[8])) + time.append(float(row[12])) + +print(settlement) +print(surcharge) +print(time) diff --git a/settle_prediction_steps_main.py b/settle_prediction_steps_main.py index facd19b..7924ec3 100644 --- a/settle_prediction_steps_main.py +++ b/settle_prediction_steps_main.py @@ -57,21 +57,16 @@ def fun_rmse(py1, py2): return np.sqrt(mse) -def run_settle_prediction(input_file, output_dir, - final_step_predict_percent, additional_predict_percent, - plot_show, - print_values, - run_original_hyperbolic='True', - run_nonlinear_hyperbolic='True', - run_weighted_nonlinear_hyperbolic='False', - run_asaoka = 'True', - run_step_prediction='True', - asaoka_interval = 3, - settle_unit='cm'): - - # ==================== - # 파일 읽기, 데이터 설정 - # ==================== +def run_settle_prediction_from_file(input_file, output_dir, + final_step_predict_percent, additional_predict_percent, + plot_show, + print_values, + run_original_hyperbolic='True', + run_nonlinear_hyperbolic='True', + run_weighted_nonlinear_hyperbolic='False', + run_asaoka='True', + run_step_prediction='True', + asaoka_interval=3): # 현재 파일 이름 출력 print("Working on " + input_file) @@ -84,11 +79,39 @@ def run_settle_prediction(input_file, output_dir, settle = data['Settlement'].to_numpy() surcharge = data['Surcharge'].to_numpy() - # 만일 침하량의 단위가 m일 경우, 조정 - if settle_unit == 'm': - settle = settle * 100 + run_settle_prediction(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, + asaoka_interval=asaoka_interval) - # 데이터 닫기 +def run_settle_prediction(np_time, np_surcharge, np_settlement, + final_step_predict_percent, additional_predict_percent, + plot_show, + print_values, + run_original_hyperbolic='True', + run_nonlinear_hyperbolic='True', + run_weighted_nonlinear_hyperbolic='False', + run_asaoka = 'True', + run_step_prediction='True', + asaoka_interval = 3): + + # ==================== + # 파일 읽기, 데이터 설정 + # ==================== + + # 시간, 침하량, 성토고 배열 생성 + time = np_time + settle = np_settlement + surcharge = np_surcharge # 마지막 계측 데이터 index + 1 파악 final_index = time.size