Fix pipeline

This commit is contained in:
itqop 2024-02-27 22:42:40 +03:00
parent 1cb9117851
commit a2b59b5bf4
1 changed files with 7 additions and 1 deletions

View File

@ -3,6 +3,7 @@ from motor.motor_asyncio import AsyncIOMotorCollection
import datetime as dt import datetime as dt
async def aggregate_salaries(collection: AsyncIOMotorCollection, dt_from: str, dt_upto: str, group_type: str) -> Tuple[List[int], List[str]]: # type: ignore async def aggregate_salaries(collection: AsyncIOMotorCollection, dt_from: str, dt_upto: str, group_type: str) -> Tuple[List[int], List[str]]: # type: ignore
group_type_format = "%Y-%m-%dT00:00:00" if group_type == "day" else "%Y-%m-01T00:00:00" if group_type == "month" else "%Y-%m-%dT%H:00:00"
pipeline = [ pipeline = [
{ {
"$match": { "$match": {
@ -17,7 +18,7 @@ async def aggregate_salaries(collection: AsyncIOMotorCollection, dt_from: str, d
"_id": { "_id": {
"$dateToString": "$dateToString":
{ {
"format": "%Y-%m-%dT00:00:00", "format": group_type_format,
"date": "$dt" "date": "$dt"
} }
}, },
@ -25,6 +26,11 @@ async def aggregate_salaries(collection: AsyncIOMotorCollection, dt_from: str, d
"$sum": "$value" "$sum": "$value"
}, },
} }
},
{
"$sort": {
"_id": 1
}
} }
] ]