perf: added property to return totatCost

master
adriano 2025-09-04 16:15:15 -03:00
parent 3f36f908fa
commit 1061aa9981
3 changed files with 27 additions and 19 deletions

View File

@ -93,11 +93,15 @@ class TranscriptionUsageData(Resource):
"""
Get transcription report data.
"""
print('request.args.get("totalCost"): ', request.args.get("totalCost"))
data = {
"company_id": request.args.get("companyId", type=str),
"start_date": request.args.get("startDate"),
"end_date": request.args.get("endDate"),
"who": request.args.get("who", type=str)
"who": request.args.get("who", type=str),
"totalCost": request.args.get("totalCost", type=str, default="true")
}
validated = TranscriptionRequest(**data)
@ -111,11 +115,12 @@ class TranscriptionUsageData(Resource):
validated.end_date
)
totalCost = True if validated.totalCost == "true" else False
if validated.who == "hit":
result = service.reportData(page=page, page_size=page_size,hit_report=True)
result = service.reportData(page=page, page_size=page_size,hit_report=True,totalCost=totalCost)
else:
result = service.reportData(page=page, page_size=page_size)
result = service.reportData(page=page, page_size=page_size,hit_report=False,totalCost=totalCost)
return {"success": True, "data": {"data": result["data"], "pagination": result["pagination"], "cost":result["cost"]}}, 200

View File

@ -6,3 +6,4 @@ class TranscriptionRequest(BaseModel):
start_date: str
end_date: str
who: Literal['hit', 'client']
totalCost: Optional[Literal['true', 'false']]

View File

@ -365,20 +365,22 @@ class TranscriptionReportService:
return self._create_excel(mysql_data)
def reportData(self, page: int = 1, page_size: int = 20, hit_report: Optional[bool] = False) -> Dict[str, Any]:
def reportData(self, page: int = 1, page_size: int = 20, hit_report: Optional[bool] = False, totalCost: Optional[bool] = True) -> Dict[str, Any]:
mongo_data = self._fetch_mongo_data(page=page, page_size=page_size)
if mongo_data["total"] == 0:
return {
"pagination": mongo_data,
"data": [],
"cost": {
cost_data = {
'company_id': self.company_id,
'start_date': self.start_date,
'end_date': self.end_date,
'total_cost_hit': 0,
'total_client_cost': 0
}
if mongo_data["total"] == 0:
return {
"pagination": mongo_data,
"data": [],
"cost": cost_data
}
if hit_report:
@ -389,7 +391,7 @@ class TranscriptionReportService:
return {
"pagination": mongo_data,
"data": mysql_data,
"cost": self._reportDataTotalCost()
"cost": self._reportDataTotalCost() if totalCost else cost_data
}