fix:last record
This commit is contained in:
@@ -2,6 +2,7 @@ import datetime
|
|||||||
import uuid
|
import uuid
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
import pydantic
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
from core.models.base import BaseModel
|
from core.models.base import BaseModel
|
||||||
@@ -18,3 +19,8 @@ class PhysicalProgressModel(BaseModel):
|
|||||||
last_month:Optional[int] = Field(description='واقعی ماه اخیر')
|
last_month:Optional[int] = Field(description='واقعی ماه اخیر')
|
||||||
last_three_month:Optional[int] = Field(description='واقعی ماه اخیر')
|
last_three_month:Optional[int] = Field(description='واقعی ماه اخیر')
|
||||||
|
|
||||||
|
class LastRecord(pydantic.BaseModel):
|
||||||
|
project_id:Optional[uuid.UUID] = Field(description="کد شناسایی پروژه در این فیلد قرار می گیرد")
|
||||||
|
date_at:Optional[datetime.datetime] = Field(description='تاریخ وارد شده')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
import datetime
|
||||||
|
|
||||||
from app.config import TaskEnv
|
from app.config import TaskEnv
|
||||||
from app.models.monito_physical_progress import PhysicalProgressModel
|
from app.models.monito_physical_progress import PhysicalProgressModel, LastRecord
|
||||||
from core.repositories.base import BaseRepository
|
from core.repositories.base import BaseRepository
|
||||||
from core.service.mongo_db import use_collection
|
from core.service.mongo_db import use_collection
|
||||||
from core.utils.crudify import mongo_inserter
|
from core.utils.crudify import mongo_inserter
|
||||||
@@ -9,18 +10,37 @@ from app.repositories.project import ProjectRepository
|
|||||||
|
|
||||||
COLLECTION = TaskEnv.CLN_MONITOR_PYSICAL
|
COLLECTION = TaskEnv.CLN_MONITOR_PYSICAL
|
||||||
MODEL = PhysicalProgressModel
|
MODEL = PhysicalProgressModel
|
||||||
|
|
||||||
|
|
||||||
class PhysicalProgressRepository(BaseRepository):
|
class PhysicalProgressRepository(BaseRepository):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(collection=TaskEnv.CLN_MONITOR_PYSICAL, model=PhysicalProgressModel)
|
super().__init__(collection=TaskEnv.CLN_MONITOR_PYSICAL, model=PhysicalProgressModel)
|
||||||
|
|
||||||
async def last_record(self,project_id:uuid.UUID):
|
async def search_last(self, connection: str, _inp: LastRecord, first: int, last: int):
|
||||||
last = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find({'project_id':project_id}).sort("$natural", -1).to_list(None)
|
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)
|
||||||
if last:
|
if last:
|
||||||
return last[0]
|
return last[0]
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
async def create(self,_inp:MODEL):
|
async def last_record(self, _inp: LastRecord):
|
||||||
create = await mongo_inserter(_inp,COLLECTION,getter=self.get)
|
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)
|
||||||
await ProjectRepository().set_sts_two_for_monitor(_inp.project_id)
|
await ProjectRepository().set_sts_two_for_monitor(_inp.project_id)
|
||||||
return create
|
return create
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from app.config import TaskEnv
|
from app.config import TaskEnv
|
||||||
|
from app.models.monito_physical_progress import LastRecord
|
||||||
from app.models.monitor_rial_progress import RialProgressModel
|
from app.models.monitor_rial_progress import RialProgressModel
|
||||||
|
from app.repositories.monitor_physical_progress import PhysicalProgressRepository
|
||||||
from app.repositories.project import ProjectRepository
|
from app.repositories.project import ProjectRepository
|
||||||
from core.repositories.base import BaseRepository
|
from core.repositories.base import BaseRepository
|
||||||
from core.service.mongo_db import use_collection
|
from core.service.mongo_db import use_collection
|
||||||
@@ -12,12 +14,9 @@ class RialProgressRepository(BaseRepository):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(collection=TaskEnv.CLN_MONITOR_RIAL, model=RialProgressModel)
|
super().__init__(collection=TaskEnv.CLN_MONITOR_RIAL, model=RialProgressModel)
|
||||||
|
|
||||||
async def last_record(self, project_id:uuid.UUID):
|
async def last_record(self, _inp: LastRecord):
|
||||||
last = await use_collection(TaskEnv.CLN_MONITOR_RIAL).find({'project_id':project_id}).sort("$natural", -1).to_list(None)
|
last = await PhysicalProgressRepository().search_last(TaskEnv.CLN_MONITOR_RIAL, _inp, 35, 25)
|
||||||
if last:
|
return last
|
||||||
return last[0]
|
|
||||||
else:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
async def create(self,_inp:RialProgressModel):
|
async def create(self,_inp:RialProgressModel):
|
||||||
create = await mongo_inserter(_inp,TaskEnv.CLN_MONITOR_RIAL,getter=self.get)
|
create = await mongo_inserter(_inp,TaskEnv.CLN_MONITOR_RIAL,getter=self.get)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from uuid import UUID
|
|||||||
|
|
||||||
from fastapi import Body
|
from fastapi import Body
|
||||||
|
|
||||||
from app.models.monito_physical_progress import PhysicalProgressModel
|
from app.models.monito_physical_progress import PhysicalProgressModel, LastRecord
|
||||||
from app.repositories.monitor_physical_progress import PhysicalProgressRepository
|
from app.repositories.monitor_physical_progress import PhysicalProgressRepository
|
||||||
from core.app import app
|
from core.app import app
|
||||||
from core.utils.router import generate_router, shrink
|
from core.utils.router import generate_router, shrink
|
||||||
@@ -19,9 +19,9 @@ repo = PhysicalProgressRepository()
|
|||||||
def create(coding: ThisModel = Body(...)):
|
def create(coding: ThisModel = Body(...)):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@router.post('/last/{project_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت فیزیکی')
|
@router.post('/last', response_model=list[dict], tags=_tag_base, description='پیشرفت فیزیکی')
|
||||||
@shrink(repo.last_record)
|
@shrink(repo.last_record)
|
||||||
def last_record(project_id:UUID):
|
def last_record(last:LastRecord):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت فیزیکی')
|
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت فیزیکی')
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from uuid import UUID
|
|||||||
|
|
||||||
from fastapi import Body
|
from fastapi import Body
|
||||||
|
|
||||||
|
from app.models.monito_physical_progress import LastRecord
|
||||||
from app.models.monitor_rial_progress import RialProgressModel
|
from app.models.monitor_rial_progress import RialProgressModel
|
||||||
from app.repositories.monitor_rial_progress import RialProgressRepository
|
from app.repositories.monitor_rial_progress import RialProgressRepository
|
||||||
from core.app import app
|
from core.app import app
|
||||||
@@ -19,9 +20,9 @@ repo = RialProgressRepository()
|
|||||||
def create(coding: ThisModel = Body(...)):
|
def create(coding: ThisModel = Body(...)):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@router.post('/last/{project_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت ریالی')
|
@router.post('/last', response_model=ThisModel, tags=_tag_base, description='پیشرفت ریالی')
|
||||||
@shrink(repo.last_record)
|
@shrink(repo.last_record)
|
||||||
def last_record(project_id:UUID):
|
def last_record(last:LastRecord):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت ریالی')
|
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت ریالی')
|
||||||
|
|||||||
Reference in New Issue
Block a user