|
2 | 2 | from flask_json import FlaskJSON, JsonError, json_response
|
3 | 3 | from flask_uploads import UploadSet, configure_uploads
|
4 | 4 | from os import path
|
5 |
| -from config import UPLOADS_DEFAULT_DEST, HECHMS_LIBS_DIR, DISTRIBUTED_MODEL_TEMPLATE_DIR, INIT_DATE_TIME_FORMAT, RAIN_FALL_FILE_NAME |
6 |
| -from input.shape_util.polygon_util import get_sub_ratios, get_timeseris, get_sub_catchment_rain_files, get_rain_files |
| 5 | +from datetime import datetime,timedelta |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +from config import UPLOADS_DEFAULT_DEST, INIT_DATE_TIME_FORMAT, RAIN_FALL_FILE_NAME, HEC_HMS_MODEL_DIR |
| 9 | +from input.shape_util.polygon_util import get_rain_files |
7 | 10 | from input.gage.model_gage import create_gage_file, create_gage_file_by_rain_file
|
8 | 11 | from input.control.model_control import create_control_file, create_control_file_by_rain_file
|
9 | 12 | from input.run.model_run import create_run_file
|
10 |
| -from datetime import datetime,timedelta |
11 |
| -from pathlib import Path |
| 13 | +from model.model_execute import execute_pre_dssvue, execute_post_dssvue, execute_hechms |
12 | 14 |
|
13 | 15 |
|
14 | 16 | app = Flask(__name__)
|
@@ -74,6 +76,70 @@ def init_run():
|
74 | 76 | return json_response(status_=200, run_id=run_id, description='Successfully saved files.')
|
75 | 77 |
|
76 | 78 |
|
| 79 | +@app.route('/HECHMS/distributed/init', methods=['GET', 'POST']) |
| 80 | +@app.route('/HECHMS/distributed/init/<string:run_datetime>', methods=['GET', 'POST']) |
| 81 | +@app.route('/HECHMS/distributed/init/<string:run_datetime>/<int:back_days>/<int:forward_days>', methods=['GET', 'POST']) |
| 82 | +def prepare_input_files(run_datetime=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), back_days=2, forward_days=3): |
| 83 | + print('prepare_input_files.') |
| 84 | + print('run_datetime : ', run_datetime) |
| 85 | + print('back_days : ', back_days) |
| 86 | + print('forward_days : ', forward_days) |
| 87 | + run_datetime = datetime.strptime(run_datetime, '%Y-%m-%d %H:%M:%S') |
| 88 | + to_date = run_datetime + timedelta(days=forward_days) |
| 89 | + from_date = run_datetime - timedelta(days=back_days) |
| 90 | + file_date = run_datetime.strftime('%Y-%m-%d') |
| 91 | + from_date = from_date.strftime('%Y-%m-%d %H:%M:%S') |
| 92 | + to_date = to_date.strftime('%Y-%m-%d %H:%M:%S') |
| 93 | + file_name = RAIN_FALL_FILE_NAME.format(file_date) |
| 94 | + print('file_name : ', file_name) |
| 95 | + print('{from_date, to_date} : ', {from_date, to_date}) |
| 96 | + get_rain_files(file_name, run_datetime.strftime('%Y-%m-%d %H:%M:%S'), forward_days, back_days) |
| 97 | + rain_fall_file = Path(file_name) |
| 98 | + if rain_fall_file.is_file(): |
| 99 | + create_gage_file_by_rain_file('distributed_model', file_name) |
| 100 | + create_control_file_by_rain_file('distributed_model', file_name) |
| 101 | + else: |
| 102 | + create_gage_file('distributed_model', from_date, to_date) |
| 103 | + create_control_file('distributed_model', from_date, to_date) |
| 104 | + create_run_file('distributed_model', run_datetime.strftime('%Y-%m-%d %H:%M:%S')) |
| 105 | + |
| 106 | + |
| 107 | +@app.route('/HECHMS/distributed/pre-process', methods=['GET', 'POST']) |
| 108 | +@app.route('/HECHMS/distributed/pre-process/<string:run_datetime>', methods=['GET', 'POST']) |
| 109 | +def pre_processing(run_datetime=datetime.now().strftime('%Y-%m-%d %H:%M:%S')): |
| 110 | + print('pre_processing.') |
| 111 | + print('run_datetime : ', run_datetime) |
| 112 | + run_datetime = datetime.strptime(run_datetime, '%Y-%m-%d %H:%M:%S') |
| 113 | + ret_code = execute_pre_dssvue('distributed_model', run_datetime.strftime('%Y-%m-%d %H:%M:%S')) |
| 114 | + if ret_code == 0: |
| 115 | + return jsonify({'Result': 'Success'}) |
| 116 | + else: |
| 117 | + return jsonify({'Result': 'Fail'}) |
| 118 | + |
| 119 | + |
| 120 | +@app.route('/HECHMS/distributed/run', methods=['GET', 'POST']) |
| 121 | +def run_hec_hms_model(): |
| 122 | + print('run_hec_hms_model.') |
| 123 | + ret_code = execute_hechms('distributed_model', HEC_HMS_MODEL_DIR) |
| 124 | + if ret_code == 0: |
| 125 | + return jsonify({'Result': 'Success'}) |
| 126 | + else: |
| 127 | + return jsonify({'Result': 'Fail'}) |
| 128 | + |
| 129 | + |
| 130 | +@app.route('/HECHMS/distributed/post-process', methods=['GET', 'POST']) |
| 131 | +@app.route('/HECHMS/distributed/post-process/<string:run_datetime>', methods=['GET', 'POST']) |
| 132 | +def post_processing(run_datetime=datetime.now().strftime('%Y-%m-%d %H:%M:%S')): |
| 133 | + print('post_processing.') |
| 134 | + print('run_datetime : ', run_datetime) |
| 135 | + run_datetime = datetime.strptime(run_datetime, '%Y-%m-%d %H:%M:%S') |
| 136 | + ret_code = execute_post_dssvue('distributed_model', run_datetime.strftime('%Y-%m-%d %H:%M:%S')) |
| 137 | + if ret_code == 0: |
| 138 | + return jsonify({'Result': 'Success'}) |
| 139 | + else: |
| 140 | + return jsonify({'Result': 'Fail'}) |
| 141 | + |
| 142 | + |
77 | 143 | @app.route('/HECHMS/distributed/rain-fall', methods=['GET', 'POST'])
|
78 | 144 | @app.route('/HECHMS/distributed/rain-fall/<string:run_datetime>', methods=['GET', 'POST'])
|
79 | 145 | @app.route('/HECHMS/distributed/rain-fall/<string:run_datetime>/<int:back_days>/<int:forward_days>', methods=['GET', 'POST'])
|
@@ -111,7 +177,7 @@ def get_gage_file(run_datetime=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), bac
|
111 | 177 | file_date = run_datetime.strftime('%Y-%m-%d')
|
112 | 178 | from_date = from_date.strftime('%Y-%m-%d %H:%M:%S')
|
113 | 179 | to_date = to_date.strftime('%Y-%m-%d %H:%M:%S')
|
114 |
| - file_name = 'output/DailyRain-{}.csv'.format(file_date) |
| 180 | + file_name = RAIN_FALL_FILE_NAME.format(file_date) |
115 | 181 | rain_fall_file = Path(file_name)
|
116 | 182 | if rain_fall_file.is_file():
|
117 | 183 | create_gage_file_by_rain_file('distributed_model', file_name)
|
|
0 commit comments