File size: 531 Bytes
360b354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from datetime import datetime


def count_orders_by_day(data):

    order_count_by_day = {}

    for order in data.get("data", []):
        timestamp = order.get("orderCreatedAt", None)
        if timestamp:
            date = datetime.fromtimestamp(timestamp / 1000).date()
            if date.strftime("%Y-%m-%d") not in order_count_by_day.keys():
                order_count_by_day[date.strftime("%Y-%m-%d")] = 1
            else:
                order_count_by_day[date.strftime("%Y-%m-%d")] += 1
    return order_count_by_day