in flask/utils.py [0:0]
def history(dynamodb_client, table_name, metric, i, interval=50):
"""
Returns an event's history (items in a DynamoDB table) as a DataFrame
:param dynamodb_client: Connection to DynamoDB service
:param table_name: Name of DynamoDB table (string)
:param metric: Name of metric subtopic (string)
:param i: ID of message payload (integer)
:param interval: Interval of history (integer)
:return: A DataFrame
"""
records = []
if i > interval:
floor = i - interval
else:
floor = 0
response = dynamodb_client.query(TableName=table_name, KeyConditionExpression="Metric = :metric AND ID > :floor",
ExpressionAttributeValues={":metric": {"S": metric}, ":floor": {"N": str(floor)}})
for n in range(0, interval - 1):
record = response['Items'][n]['payload']['M']
new_record = {}
for key in record.keys():
for dt in record[key]:
new_record[key] = record[key][dt]
records.append(new_record)
metric_df = pd.DataFrame(records, dtype=float)
return metric_df