Created
March 2, 2021 11:10
-
-
Save bahrmichael/d6b3de70583cedf0dc3448bced882b25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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