feat:add donut delay

This commit is contained in:
shahzeydyfah
2024-10-11 15:54:06 +03:30
parent 6028dced52
commit d31eca8316
2 changed files with 58 additions and 28 deletions
+28 -9
View File
@@ -31,7 +31,6 @@ class ReportRepository():
async def project_status_monitor(self, _inp: StatusReport):
return await self.project_status(_inp, 'monitor')
async def report_country(self, _inp: ReportCountry):
match = {}
if _inp.state:
@@ -98,15 +97,19 @@ class ReportRepository():
"less_than_1000",
{
"$cond": [
{"$and": [{"$gte": ["$design.building_infrastructure", 1000]}, {"$lt": ["$design.building_infrastructure", 5000]}]}, # Check if 10 <= a < 20
{"$and": [{"$gte": ["$design.building_infrastructure", 1000]},
{"$lt": ["$design.building_infrastructure", 5000]}]},
# Check if 10 <= a < 20
"between_1000_and_5000",
{
"$cond": [
{"$and": [{"$gte": ["$design.building_infrastructure", 5000]}, {"$lt": ["$design.building_infrastructure", 15000]}]},
{"$and": [{"$gte": ["$design.building_infrastructure", 5000]},
{"$lt": ["$design.building_infrastructure", 15000]}]},
"between_5000_and_15000",
{
"$cond": [
{"$and": [{"$gte": ["$design.building_infrastructure", 15000]}, {"$lt": ["$design.building_infrastructure", 30000]}]},
{"$and": [{"$gte": ["$design.building_infrastructure", 15000]},
{"$lt": ["$design.building_infrastructure", 30000]}]},
"between_15000_and_30000",
"greater_than_or_equal_30000" # Otherwise, a >= 30
]
@@ -149,9 +152,25 @@ class ReportRepository():
return report
async def delay_donut(self):
...
# await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([
# {'$group':}
# ])
report = await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([
{'$group': {"_id": None, "total_financial": {"$sum": "$financial.total"},
"total_force_major": {"$sum": "$force_major.total"},
"total_technical": {"$sum": "$technical.total"},
"total_extra_new_work": {"$sum": "$extra_new_work"},
"total_other": {"$sum": "$other"},
}}
]).to_list(None)
return report
async def list_delay_donut(self, _select: str):
_map = {'1': 'financial.total', '2': 'force_major.total', '3': 'technical.total', '4': 'extra_new_work',
'5': 'other'}
report = await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([
{'$match': {_map[_select]: {'$gt': 0}}},
{'$group': {"_id": '$project_id'}}
]).to_list(None)
if report:
get_list = []
for i in report:
get_list.append(i['_id'])
return get_list
+11
View File
@@ -28,6 +28,15 @@ def report_country(_inp: ReportCountry):
def exist_project_state():
pass
@router.get('/donut/delay', tags=_tag_base)
@shrink(repo.delay_donut)
def delay_donut():
pass
@router.get('/donut/delay/{_select}', tags=_tag_base)
@shrink(repo.list_delay_donut)
def list_delay_donut(_select):
pass
@router.get('/donut/{_select}', tags=_tag_base)
@shrink(repo.donut)
def donut(_select:int):
@@ -38,4 +47,6 @@ def donut(_select:int):
def list_donut(_inp: DonutList):
pass
app.include_router(router)