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