Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
dynamodb has data - testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vggonzal authored and vggonzal committed Aug 16, 2023
1 parent 9849ba3 commit cf11047
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 44 deletions.
40 changes: 27 additions & 13 deletions hydrocronapi/controllers/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion hydrocronapi/controllers/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
62 changes: 32 additions & 30 deletions hydrocronapi/controllers/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -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

Expand Down

0 comments on commit cf11047

Please sign in to comment.