From a2b59b5bf48c38910a4f1daae7eb049f637cbfc5 Mon Sep 17 00:00:00 2001 From: itqop Date: Tue, 27 Feb 2024 22:42:40 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Fix=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/database/methods.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/database/methods.py b/app/database/methods.py index 974f009..dcf734c 100644 --- a/app/database/methods.py +++ b/app/database/methods.py @@ -3,6 +3,7 @@ from motor.motor_asyncio import AsyncIOMotorCollection 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 + 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 = [ { "$match": { @@ -17,7 +18,7 @@ async def aggregate_salaries(collection: AsyncIOMotorCollection, dt_from: str, d "_id": { "$dateToString": { - "format": "%Y-%m-%dT00:00:00", + "format": group_type_format, "date": "$dt" } }, @@ -25,6 +26,11 @@ async def aggregate_salaries(collection: AsyncIOMotorCollection, dt_from: str, d "$sum": "$value" }, } + }, + { + "$sort": { + "_id": 1 + } } ]