diff --git a/hydrocronapi/controllers/db/db.py b/hydrocronapi/controllers/db/db.py index d84a55f..9778923 100644 --- a/hydrocronapi/controllers/db/db.py +++ b/hydrocronapi/controllers/db/db.py @@ -12,18 +12,27 @@ def get_reach_series(start_time: datetime, end_time: datetime) -> Generator: table_name = 'hydrocron_swot_reaches' - hydrocron_reach_table = dynamo_instance.load_table(table_name) - items = hydrocron_reach_table.query(KeyConditionExpression=Key('reach_id').eq('71224100223')) - return items - + response = dynamodb.get_item( + TableName=table_name, + Key={ + 'feature_id': {'S': '71224100223'} + } + ) + print("get_item") + print(response) + return response def get_node_series(start_time: datetime, end_time: datetime) -> Generator: table_name = 'hydrocron_swot_reaches' - - hydrocron_reach_table = dynamo_instance.load_table(table_name) - items = hydrocron_reach_table.query(KeyConditionExpression=Key('node_id').eq('71224100223')) - return items - + response = dynamodb.get_item( + TableName=table_name, + Key={ + 'node_id': {'S': '71224100223'} + } + ) + print("get_item") + print(response) + return response def get_reach_series_by_feature_id(feature_id: str, start_time: datetime, end_time: datetime) -> Generator: @@ -46,7 +55,12 @@ def get_reach_series_by_feature_id(feature_id: str, start_time: datetime, end_ti def get_node_series_by_feature_id(feature_id, start_time, end_time): table_name = 'hydrocron_swot_reaches' - - hydrocron_reach_table = dynamo_instance.load_table(table_name) - items = hydrocron_reach_table.query(KeyConditionExpression=Key('node_id').eq(feature_id)) - return items + response = dynamodb.get_item( + TableName=table_name, + Key={ + 'node_id': {'S': feature_id} + } + ) + print("get_item") + print(response) + return response diff --git a/hydrocronapi/controllers/subset.py b/hydrocronapi/controllers/subset.py index da4d1d2..c8af9a1 100644 --- a/hydrocronapi/controllers/subset.py +++ b/hydrocronapi/controllers/subset.py @@ -74,7 +74,7 @@ def format_subset_json(results: Generator, polygon, elapsed_time): """ # Fetch all results from query - results = results['Items'] + results = results['Item'] data = {} diff --git a/hydrocronapi/controllers/timeseries.py b/hydrocronapi/controllers/timeseries.py index fed7213..a24d42a 100644 --- a/hydrocronapi/controllers/timeseries.py +++ b/hydrocronapi/controllers/timeseries.py @@ -72,7 +72,10 @@ def format_json(results: Generator, feature_id, elapsed_time): """ # Fetch all results - results = results['Item'] + print("RESULTS") + res = results['Item'] + print(results) + print(res) data = {} @@ -89,35 +92,34 @@ def format_json(results: Generator, feature_id, elapsed_time): data['features'] = [] i = 0 - for res in results: - if res['feature_id'] == feature_id and res['feature_time'] != '-999999999999': # and (res['width'] != '-999999999999')): - feature = {'properties': {}, 'geometry': {}, 'type': "Feature"} - feature['geometry']['coordinates'] = [] - feature_type = '' - if 'POINT' in res['geometry']: - geometry = res['geometry'].replace('POINT (', '').replace(')', '') - geometry = geometry.replace('"', '') - geometry = geometry.replace("'", "") - feature_type = 'Point' - if 'LINESTRING' in res['geometry']: - geometry = res['geometry'].replace('LINESTRING (', '').replace(')', '') - geometry = geometry.replace('"', '') - geometry = geometry.replace("'", "") - feature_type = 'LineString' - feature['geometry']['type'] = feature_type - for pol in geometry.split(", "): - (var_x, var_y) = pol.split(" ") - if feature_type == 'LineString': - feature['geometry']['coordinates'].append([float(var_x), float(var_y)]) - if feature_type == 'Point': - feature['geometry']['coordinates'] = [float(var_x), float(var_y)] - i += 1 - feature['properties']['feature_time'] = datetime.fromtimestamp(float(res['feature_time']) + 946710000).strftime( - "%Y-%m-%d %H:%M:%S") - feature['properties']['reach_id'] = float(res['reach_id']) - feature['properties']['wse'] = float(res['wse']) - feature['properties']['slope'] = float(res['slope']) - data['features'].append(feature) + if res['feature_id'] == feature_id and res['feature_time'] != '-999999999999': # and (res['width'] != '-999999999999')): + feature = {'properties': {}, 'geometry': {}, 'type': "Feature"} + feature['geometry']['coordinates'] = [] + feature_type = '' + if 'POINT' in res['geometry']: + geometry = res['geometry'].replace('POINT (', '').replace(')', '') + geometry = geometry.replace('"', '') + geometry = geometry.replace("'", "") + feature_type = 'Point' + if 'LINESTRING' in res['geometry']: + geometry = res['geometry'].replace('LINESTRING (', '').replace(')', '') + geometry = geometry.replace('"', '') + geometry = geometry.replace("'", "") + feature_type = 'LineString' + feature['geometry']['type'] = feature_type + for pol in geometry.split(", "): + (var_x, var_y) = pol.split(" ") + if feature_type == 'LineString': + feature['geometry']['coordinates'].append([float(var_x), float(var_y)]) + if feature_type == 'Point': + feature['geometry']['coordinates'] = [float(var_x), float(var_y)] + i += 1 + feature['properties']['feature_time'] = datetime.fromtimestamp(float(res['feature_time']) + 946710000).strftime( + "%Y-%m-%d %H:%M:%S") + feature['properties']['reach_id'] = float(res['reach_id']) + feature['properties']['wse'] = float(res['wse']) + feature['properties']['slope'] = float(res['slope']) + data['features'].append(feature) data['hits'] = i