def prepare_inflow_150(inflow_file_path, start, end, discharge_id, curw_sim_pool): try: # Extract discharge series TS = DisTS(pool=curw_sim_pool) discharge_ts = TS.get_timeseries(id_=discharge_id, start_date=start, end_date=end) inflow = [] inflow.append('0 41550') inflow.append('C 0 41550') inflow.append('H 0 0') timeseries = discharge_ts for i in range(1, len(timeseries)): time_col = (str('%.1f' % (((timeseries[i][0] - timeseries[0][0]).total_seconds())/3600))).rjust(16) value_col = (str('%.1f' % (timeseries[i][1]))).rjust(16) inflow.append('H' + time_col + value_col) write_to_file(inflow_file_path, data=inflow) except Exception as e: print(traceback.print_exc()) finally: destroy_Pool(curw_sim_pool) print("Inflow generated")
def prepare_inflow(inflow_file_path, start, end, discharge_id, wl_id, curw_sim_pool): obs_wl = None try: curw_obs_pool = get_Pool(host=con_params.CURW_OBS_HOST, user=con_params.CURW_OBS_USERNAME, password=con_params.CURW_OBS_PASSWORD, port=con_params.CURW_OBS_PORT, db=con_params.CURW_OBS_DATABASE) connection = curw_obs_pool.connection() # Extract waterlevel with connection.cursor() as cursor1: obs_end = datetime.strptime( start, COMMON_DATE_TIME_FORMAT) + timedelta(hours=10) cursor1.callproc('getWL', (wl_id, start, obs_end)) result = cursor1.fetchone() obs_wl = result.get('value') if obs_wl is None: obs_wl = 0.5 # Extract discharge series TS = DisTS(pool=curw_sim_pool) discharge_ts = TS.get_timeseries(id_=discharge_id, start_date=start, end_date=end) inflow = [] inflow.append('0 0') inflow.append('C 0 8655') inflow.append('H 0 0') timeseries = discharge_ts for i in range(1, len(timeseries)): time_col = (str( '%.1f' % (((timeseries[i][0] - timeseries[0][0]).total_seconds()) / 3600))).rjust(16) value_col = (str('%.1f' % (timeseries[i][1]))).rjust(16) inflow.append('H' + time_col + value_col) inflow.append('R 2265{}'.format((str(obs_wl)).rjust(16))) inflow.append('R 3559 6.6') write_to_file(inflow_file_path, data=inflow) except Exception as e: print(traceback.print_exc()) finally: connection.close() destroy_Pool(curw_obs_pool) destroy_Pool(curw_sim_pool) print("Inflow generated")