- All the examples below assume the user's timezone is US/Central.
Activity.objects(device="sausages")
Activity.objects(device="sausages", data__type="running")
Note:
- end time strictly greater than start of today (in user's timezone)
today = arrow.now("US/Central").datetime.replace(hour=0, minute=0, second=0, microsecond=0)
Activity.objects(device="sausages", data__end_time__gt=today)
today = arrow.now("US/Central").datetime.replace(hour=0, minute=0, second=0, microsecond=0)
Activity.objects(device="sausages", data__end_time__gt=today, data__type="running")
Notes:
- start time strictly less than start of today (in user's timezone)
- end time strictly greater than start of yesterday (in user's timezone)
today = arrow.now("US/Central").datetime.replace(hour=0, minute=0, second=0, microsecond=0)
yesterday = today - datetime.timedelta(days=1)
Activity.objects(device="sausages", data__start_time__lt=today, data__end_time__gt=yesterday, data__type="running")
Notes:
- need to drop down to
pymongo
to make use of the aggregation framework
today = arrow.now("US/Central").datetime.replace(hour=0, minute=0, second=0, microsecond=0)
Activity._get_collection().aggregate(
[
{ "$match": { "device": "sausages", "data.end_time": { "$gt": today } } },
{ "$group": { "_id": "$data.type", "total": { "$sum": "$data.duration" } } }
]
)