perf: added property to return totatCost
parent
3f36f908fa
commit
1061aa9981
|
@ -93,11 +93,15 @@ class TranscriptionUsageData(Resource):
|
||||||
"""
|
"""
|
||||||
Get transcription report data.
|
Get transcription report data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
print('request.args.get("totalCost"): ', request.args.get("totalCost"))
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"company_id": request.args.get("companyId", type=str),
|
"company_id": request.args.get("companyId", type=str),
|
||||||
"start_date": request.args.get("startDate"),
|
"start_date": request.args.get("startDate"),
|
||||||
"end_date": request.args.get("endDate"),
|
"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)
|
validated = TranscriptionRequest(**data)
|
||||||
|
@ -111,11 +115,12 @@ class TranscriptionUsageData(Resource):
|
||||||
validated.end_date
|
validated.end_date
|
||||||
)
|
)
|
||||||
|
|
||||||
|
totalCost = True if validated.totalCost == "true" else False
|
||||||
|
|
||||||
if validated.who == "hit":
|
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:
|
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
|
return {"success": True, "data": {"data": result["data"], "pagination": result["pagination"], "cost":result["cost"]}}, 200
|
||||||
|
|
||||||
|
|
|
@ -6,3 +6,4 @@ class TranscriptionRequest(BaseModel):
|
||||||
start_date: str
|
start_date: str
|
||||||
end_date: str
|
end_date: str
|
||||||
who: Literal['hit', 'client']
|
who: Literal['hit', 'client']
|
||||||
|
totalCost: Optional[Literal['true', 'false']]
|
||||||
|
|
|
@ -365,20 +365,22 @@ class TranscriptionReportService:
|
||||||
return self._create_excel(mysql_data)
|
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)
|
mongo_data = self._fetch_mongo_data(page=page, page_size=page_size)
|
||||||
|
|
||||||
if mongo_data["total"] == 0:
|
cost_data = {
|
||||||
return {
|
|
||||||
"pagination": mongo_data,
|
|
||||||
"data": [],
|
|
||||||
"cost": {
|
|
||||||
'company_id': self.company_id,
|
'company_id': self.company_id,
|
||||||
'start_date': self.start_date,
|
'start_date': self.start_date,
|
||||||
'end_date': self.end_date,
|
'end_date': self.end_date,
|
||||||
'total_cost_hit': 0,
|
'total_cost_hit': 0,
|
||||||
'total_client_cost': 0
|
'total_client_cost': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if mongo_data["total"] == 0:
|
||||||
|
return {
|
||||||
|
"pagination": mongo_data,
|
||||||
|
"data": [],
|
||||||
|
"cost": cost_data
|
||||||
}
|
}
|
||||||
|
|
||||||
if hit_report:
|
if hit_report:
|
||||||
|
@ -389,7 +391,7 @@ class TranscriptionReportService:
|
||||||
return {
|
return {
|
||||||
"pagination": mongo_data,
|
"pagination": mongo_data,
|
||||||
"data": mysql_data,
|
"data": mysql_data,
|
||||||
"cost": self._reportDataTotalCost()
|
"cost": self._reportDataTotalCost() if totalCost else cost_data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue