feat:add donut delay
This commit is contained in:
+47
-28
@@ -6,9 +6,9 @@ from core.service.mongo_db import use_collection
|
|||||||
|
|
||||||
|
|
||||||
class ReportRepository():
|
class ReportRepository():
|
||||||
async def project_status(self, _inp: StatusReport,type):
|
async def project_status(self, _inp: StatusReport, type):
|
||||||
if _inp.state:
|
if _inp.state:
|
||||||
match = {f'{type}.sts': {'$exists': 1}, 'design.state':_inp.state}
|
match = {f'{type}.sts': {'$exists': 1}, 'design.state': _inp.state}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
match = {f'{type}.sts': {'$exists': 1}}
|
match = {f'{type}.sts': {'$exists': 1}}
|
||||||
@@ -20,7 +20,7 @@ class ReportRepository():
|
|||||||
'$group': {
|
'$group': {
|
||||||
'_id': f"${type}.sts",
|
'_id': f"${type}.sts",
|
||||||
'count': {'$sum': 1}
|
'count': {'$sum': 1}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]).to_list(None)
|
]).to_list(None)
|
||||||
return report
|
return report
|
||||||
@@ -31,15 +31,14 @@ class ReportRepository():
|
|||||||
async def project_status_monitor(self, _inp: StatusReport):
|
async def project_status_monitor(self, _inp: StatusReport):
|
||||||
return await self.project_status(_inp, 'monitor')
|
return await self.project_status(_inp, 'monitor')
|
||||||
|
|
||||||
|
async def report_country(self, _inp: ReportCountry):
|
||||||
async def report_country(self ,_inp: ReportCountry):
|
|
||||||
match = {}
|
match = {}
|
||||||
if _inp.state:
|
if _inp.state:
|
||||||
match = {'design.state':_inp.state}
|
match = {'design.state': _inp.state}
|
||||||
if _inp.type_id:
|
if _inp.type_id:
|
||||||
match.update({'design.type_id': _inp.type_id})
|
match.update({'design.type_id': _inp.type_id})
|
||||||
if _inp.nature_id:
|
if _inp.nature_id:
|
||||||
match.update({'design.nature_id':_inp.nature_id})
|
match.update({'design.nature_id': _inp.nature_id})
|
||||||
if _inp.monitor_type:
|
if _inp.monitor_type:
|
||||||
match.update({'monitor.base_information.type': _inp.monitor_type})
|
match.update({'monitor.base_information.type': _inp.monitor_type})
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ class ReportRepository():
|
|||||||
# count_monitor_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'monitor.base_information.type': _inp.monitor_type,'design.state':_inp.state})
|
# count_monitor_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'monitor.base_information.type': _inp.monitor_type,'design.state':_inp.state})
|
||||||
|
|
||||||
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
||||||
{"$match":match},
|
{"$match": match},
|
||||||
{'$group': {
|
{'$group': {
|
||||||
'_id': "$design.state",
|
'_id': "$design.state",
|
||||||
'nature_id': {'$addToSet': '$design.nature_id'},
|
'nature_id': {'$addToSet': '$design.nature_id'},
|
||||||
@@ -63,10 +62,10 @@ class ReportRepository():
|
|||||||
"_id": 1
|
"_id": 1
|
||||||
}}
|
}}
|
||||||
]).to_list(None)
|
]).to_list(None)
|
||||||
# count_nature = await use_collection(TaskEnv.CLN_PROJECT).count_documents(
|
# count_nature = await use_collection(TaskEnv.CLN_PROJECT).count_documents(
|
||||||
# {'design.nature_id': _inp.nature_id})
|
# {'design.nature_id': _inp.nature_id})
|
||||||
# count_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'design.type_id':_inp.type_id})
|
# count_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'design.type_id':_inp.type_id})
|
||||||
# count_monitor_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'monitor.base_information.type': _inp.monitor_type})
|
# count_monitor_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'monitor.base_information.type': _inp.monitor_type})
|
||||||
# return {'count_nature':count_nature,'count_type':count_type,'count_monitor_type':count_monitor_type}
|
# return {'count_nature':count_nature,'count_type':count_type,'count_monitor_type':count_monitor_type}
|
||||||
return report
|
return report
|
||||||
|
|
||||||
@@ -82,11 +81,11 @@ class ReportRepository():
|
|||||||
|
|
||||||
return report
|
return report
|
||||||
|
|
||||||
async def donut(self,_select:int):
|
async def donut(self, _select: int):
|
||||||
report = None
|
report = None
|
||||||
if _select == 1:
|
if _select == 1:
|
||||||
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
||||||
{"$group":{"_id":"$design.nature_id",'count':{'$sum':1}}}
|
{"$group": {"_id": "$design.nature_id", 'count': {'$sum': 1}}}
|
||||||
]).to_list(None)
|
]).to_list(None)
|
||||||
elif _select == 2:
|
elif _select == 2:
|
||||||
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
||||||
@@ -98,15 +97,19 @@ class ReportRepository():
|
|||||||
"less_than_1000",
|
"less_than_1000",
|
||||||
{
|
{
|
||||||
"$cond": [
|
"$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",
|
"between_1000_and_5000",
|
||||||
{
|
{
|
||||||
"$cond": [
|
"$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",
|
"between_5000_and_15000",
|
||||||
{
|
{
|
||||||
"$cond": [
|
"$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",
|
"between_15000_and_30000",
|
||||||
"greater_than_or_equal_30000" # Otherwise, a >= 30
|
"greater_than_or_equal_30000" # Otherwise, a >= 30
|
||||||
]
|
]
|
||||||
@@ -128,30 +131,46 @@ class ReportRepository():
|
|||||||
]).to_list(None)
|
]).to_list(None)
|
||||||
return report
|
return report
|
||||||
|
|
||||||
async def list_donut(self,_inp:DonutList):
|
async def list_donut(self, _inp: DonutList):
|
||||||
if _inp.type == 1:
|
if _inp.type == 1:
|
||||||
_filter = {'design.nature_id':int(_inp.donut_select)}
|
_filter = {'design.nature_id': int(_inp.donut_select)}
|
||||||
if _inp.type == 2:
|
if _inp.type == 2:
|
||||||
if _inp.donut_select == "less_than_1000":
|
if _inp.donut_select == "less_than_1000":
|
||||||
_filter = {'design.building_infrastructure': {'$lt': 1000}}
|
_filter = {'design.building_infrastructure': {'$lt': 1000}}
|
||||||
elif _inp.donut_select == "between_1000_and_5000":
|
elif _inp.donut_select == "between_1000_and_5000":
|
||||||
_filter = {'design.building_infrastructure': {'$lt': 5000, "$gte": 1000 }}
|
_filter = {'design.building_infrastructure': {'$lt': 5000, "$gte": 1000}}
|
||||||
elif _inp.donut_select == "between_5000_and_15000":
|
elif _inp.donut_select == "between_5000_and_15000":
|
||||||
_filter = {'design.building_infrastructure': {'$lt': 15000, "$gte": 5000 }}
|
_filter = {'design.building_infrastructure': {'$lt': 15000, "$gte": 5000}}
|
||||||
elif _inp.donut_select == "between_15000_and_30000":
|
elif _inp.donut_select == "between_15000_and_30000":
|
||||||
_filter = {'design.building_infrastructure': {'$lt': 30000, "$gte": 15000 }}
|
_filter = {'design.building_infrastructure': {'$lt': 30000, "$gte": 15000}}
|
||||||
else:
|
else:
|
||||||
_filter = {'design.building_infrastructure': {'$gte': 30000}}
|
_filter = {'design.building_infrastructure': {'$gte': 30000}}
|
||||||
elif _inp.type == 3 :
|
elif _inp.type == 3:
|
||||||
_filter = {'design.type_id': int(_inp.donut_select)}
|
_filter = {'design.type_id': int(_inp.donut_select)}
|
||||||
report = await use_collection(TaskEnv.CLN_PROJECT).find(_filter).to_list(None)
|
report = await use_collection(TaskEnv.CLN_PROJECT).find(_filter).to_list(None)
|
||||||
|
|
||||||
return report
|
return report
|
||||||
|
|
||||||
async def delay_donut(self):
|
async def delay_donut(self):
|
||||||
...
|
report = await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([
|
||||||
# await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([
|
{'$group': {"_id": None, "total_financial": {"$sum": "$financial.total"},
|
||||||
# {'$group':}
|
"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
|
||||||
|
|||||||
@@ -28,6 +28,15 @@ def report_country(_inp: ReportCountry):
|
|||||||
def exist_project_state():
|
def exist_project_state():
|
||||||
pass
|
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)
|
@router.get('/donut/{_select}', tags=_tag_base)
|
||||||
@shrink(repo.donut)
|
@shrink(repo.donut)
|
||||||
def donut(_select:int):
|
def donut(_select:int):
|
||||||
@@ -38,4 +47,6 @@ def donut(_select:int):
|
|||||||
def list_donut(_inp: DonutList):
|
def list_donut(_inp: DonutList):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
Reference in New Issue
Block a user