diff --git a/app/repositories/monitor_physical_progress.py b/app/repositories/monitor_physical_progress.py index 097d5b6..3de3c5f 100644 --- a/app/repositories/monitor_physical_progress.py +++ b/app/repositories/monitor_physical_progress.py @@ -139,6 +139,34 @@ class PhysicalProgressRepository(BaseRepository): else: await use_collection(COLLECTION).update_one({"_id": _i_model.id},{"$set": _update}) return True +# for recalc medium progress in database +# async def recalc_medium_progress(self): +# print('111111111111111111111') +# coll = use_collection(TaskEnv.CLN_MONITOR_PYSICAL) +# project_ids = await coll.distinct( +# "project_id", +# {"deleted_at": {"$exists": False}}, +# ) +# print('222222222222222222222') +# +# updated = 0 +# for pid in project_ids: +# print('piiiiiidf',pid) +# records = await coll.find({ +# "project_id": pid, +# "deleted_at": {"$exists": False}, +# }).sort([("date_at", 1), ("_id", 1)]).to_list(None) +# +# total = 0 +# for i, rec in enumerate(records, start=1): +# total += rec.get("real") or 0 +# await coll.update_one( +# {"_id": rec["_id"]}, +# {"$set": {"medium_progress": round(total / i, 1)}}, +# ) +# updated += 1 +# +# return {"projects": len(project_ids), "updated": updated} diff --git a/app/repositories/report.py b/app/repositories/report.py index 0a3b486..f9841e1 100644 --- a/app/repositories/report.py +++ b/app/repositories/report.py @@ -10,9 +10,9 @@ from core.service.mongo_db import use_collection class ReportRepository(): async def project_status(self, _inp: StatusReport, type): if _inp.state: - match = {f'{type}.sts': {'$exists': 1}, 'design.state': _inp.state} + match = {f'{type}.sts': {'$exists': 1}, 'design.state': _inp.state,'sts':1} else: - match = {f'{type}.sts': {'$exists': 1}} + match = {f'{type}.sts': {'$exists': 1},'sts':1} if _inp.type_id: match.update({'design.type_id': _inp.type_id}) if _inp.nature_id: diff --git a/app/urls/monitor_physical.py b/app/urls/monitor_physical.py index 49d7c94..95ad959 100644 --- a/app/urls/monitor_physical.py +++ b/app/urls/monitor_physical.py @@ -25,6 +25,11 @@ def create(coding: ThisModel = Body(...)): def last_record(last:LastRecord): pass +# @router.get('/progress/rediv', response_model=list[dict], tags=_tag_base, description='پیشرفت فیزیکی') +# @shrink(repo.recalc_medium_progress) +# def recalc_medium_progress(): +# pass + @router.get('/list/{_id}', response_model=List[ThisModel], tags=_tag_base, description='پیشرفت فیزیکی') @shrink(repo.list_by_project) def list_by_project(_id: UUID):