Skip to content

Instantly share code, notes, and snippets.

@bahrmichael
Created March 2, 2021 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahrmichael/d6b3de70583cedf0dc3448bced882b25 to your computer and use it in GitHub Desktop.
Save bahrmichael/d6b3de70583cedf0dc3448bced882b25 to your computer and use it in GitHub Desktop.
def lambda_handler(event, context):
data = event['data']
print(data)
prices = []
types = []
volumes = []
for page_data in data:
prices.extend(page_data['P'])
types.extend(page_data['T'])
volumes.extend(page_data['V'])
structured = {}
for i in range(0, len(types) - 1):
id = f"{types[i]}"
volume = int(volumes[i])
price = int(prices[i])
if id not in structured:
structured[id] = {
'p': price,
'v': volume
}
else:
if price < structured[id]['p']:
structured[id]['p'] = price
structured[id]['v'] += volume
aggregated = []
for key, value in structured.items():
aggregated.append({
'k': key,
'p': value['p'],
'v': value['v']
})
return aggregated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment