Files
sakhteman/app/repositories/monitor_physical_progress.py
T

47 lines
1.7 KiB
Python
Raw Normal View History

2024-06-04 17:29:56 +03:30
import uuid
2024-06-13 20:13:47 +03:30
import datetime
2024-06-04 17:29:56 +03:30
from app.config import TaskEnv
2024-06-13 20:13:47 +03:30
from app.models.monito_physical_progress import PhysicalProgressModel, LastRecord
2024-06-04 17:29:56 +03:30
from core.repositories.base import BaseRepository
from core.service.mongo_db import use_collection
2024-06-08 00:01:04 +03:30
from core.utils.crudify import mongo_inserter
from app.repositories.project import ProjectRepository
2024-06-04 17:29:56 +03:30
COLLECTION = TaskEnv.CLN_MONITOR_PYSICAL
MODEL = PhysicalProgressModel
2024-06-13 20:13:47 +03:30
2024-06-04 17:29:56 +03:30
class PhysicalProgressRepository(BaseRepository):
def __init__(self):
super().__init__(collection=TaskEnv.CLN_MONITOR_PYSICAL, model=PhysicalProgressModel)
2024-06-13 20:13:47 +03:30
async def search_last(self, connection: str, _inp: LastRecord, first: int, last: int):
m_first = _inp.date_at - datetime.timedelta(days=first)
print(m_first)
m_end = _inp.date_at - datetime.timedelta(days=last)
print(m_end)
last = await use_collection(connection).find({
'project_id': _inp.project_id,
'date_at': {'$gte': m_first, '$lte': m_end}
}).sort("$natural", -1).to_list(None)
2024-06-04 17:29:56 +03:30
if last:
return last[0]
else:
2024-06-08 00:01:04 +03:30
return {}
2024-06-13 20:13:47 +03:30
async def last_record(self, _inp: LastRecord):
send = {'month': {}, 'three_month': {}}
last = await self.search_last(TaskEnv.CLN_MONITOR_PYSICAL, _inp, 35, 25)
if last:
send['month'] = last
three_month = await self.search_last(TaskEnv.CLN_MONITOR_PYSICAL, _inp, 95, 85)
if three_month:
send['three_month'] = three_month
return send
async def create(self, _inp: MODEL):
create = await mongo_inserter(_inp, COLLECTION, getter=self.get)
2024-06-08 00:01:04 +03:30
await ProjectRepository().set_sts_two_for_monitor(_inp.project_id)
return create