feat: implementation of new report collumns
parent
69a93b1041
commit
64b990d248
|
@ -1,6 +1,6 @@
|
||||||
from flask_restx import fields, Namespace
|
from flask_restx import fields, Namespace
|
||||||
|
|
||||||
billing_ns = Namespace('billing', description='Authentication')
|
billing_ns = Namespace('billing', description='Product price')
|
||||||
|
|
||||||
product_model = billing_ns.model('Product', {
|
product_model = billing_ns.model('Product', {
|
||||||
'name': fields.String(required=True, description='Name of the product'),
|
'name': fields.String(required=True, description='Name of the product'),
|
||||||
|
|
|
@ -48,7 +48,7 @@ class TranscriptionExport(Resource):
|
||||||
|
|
||||||
ignore_cache = is_current_date(validated.start_date, validated.end_date)
|
ignore_cache = is_current_date(validated.start_date, validated.end_date)
|
||||||
|
|
||||||
# Verifica se o arquivo já existe
|
# Verifica se o arquivo já existe e se a consulta é referente a data atual
|
||||||
if not os.path.exists(filepath) or ignore_cache:
|
if not os.path.exists(filepath) or ignore_cache:
|
||||||
# Gera o relatório e salva no caminho desejado
|
# Gera o relatório e salva no caminho desejado
|
||||||
service = TranscriptionReportService(
|
service = TranscriptionReportService(
|
||||||
|
|
|
@ -64,7 +64,8 @@ class TranscriptionReportService:
|
||||||
"_id": {
|
"_id": {
|
||||||
"sessionId": "$sessionId",
|
"sessionId": "$sessionId",
|
||||||
"type": "$pricing.type",
|
"type": "$pricing.type",
|
||||||
"product": "$product"
|
"product": "$product",
|
||||||
|
"provider": "$pricing.provider"
|
||||||
},
|
},
|
||||||
"usage": {"$sum": {"$toDouble": "$usage"}},
|
"usage": {"$sum": {"$toDouble": "$usage"}},
|
||||||
"totalCost": {"$sum": {"$toDouble": "$total_cost"}},
|
"totalCost": {"$sum": {"$toDouble": "$total_cost"}},
|
||||||
|
@ -84,21 +85,15 @@ class TranscriptionReportService:
|
||||||
"usageByType": {
|
"usageByType": {
|
||||||
"$push": {
|
"$push": {
|
||||||
"k": "$_id.type",
|
"k": "$_id.type",
|
||||||
"v": "$usage"
|
"v": {
|
||||||
|
"product": "$_id.product",
|
||||||
|
"type": "$_id.type",
|
||||||
|
"provider": "$_id.provider",
|
||||||
|
"usage": "$usage",
|
||||||
|
"usageCost": "$totalCost"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"costByType": {
|
|
||||||
"$push": {
|
|
||||||
"k": "$_id.type",
|
|
||||||
"v": "$totalCost"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"usageByProduct": {
|
|
||||||
"$push": {
|
|
||||||
"k": "$_id.product",
|
|
||||||
"v": "$usage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +103,7 @@ class TranscriptionReportService:
|
||||||
"firstCreatedAt": 1,
|
"firstCreatedAt": 1,
|
||||||
"callerIds": 1,
|
"callerIds": 1,
|
||||||
"totalCost": 1,
|
"totalCost": 1,
|
||||||
"usageByType": {"$arrayToObject": "$usageByType"},
|
"usageByType": {"$arrayToObject": "$usageByType"}
|
||||||
"costByType": {"$arrayToObject": "$costByType"},
|
|
||||||
"usageByProduct": {"$arrayToObject": "$usageByProduct"}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +131,7 @@ class TranscriptionReportService:
|
||||||
self.unique_ids = [doc["_id"] for doc in self.mongo_results]
|
self.unique_ids = [doc["_id"] for doc in self.mongo_results]
|
||||||
|
|
||||||
# print("=====> self.mongo_results: ", self.mongo_results)
|
# print("=====> self.mongo_results: ", self.mongo_results)
|
||||||
|
# exit(1)
|
||||||
|
|
||||||
# Pipeline para contagem total
|
# Pipeline para contagem total
|
||||||
count_pipeline = [
|
count_pipeline = [
|
||||||
|
@ -190,8 +184,21 @@ class TranscriptionReportService:
|
||||||
|
|
||||||
if rowMongo := next((m for m in self.mongo_results if m["_id"] == row["uniqueid"] ), None):
|
if rowMongo := next((m for m in self.mongo_results if m["_id"] == row["uniqueid"] ), None):
|
||||||
row["custo_hit"] = f"{float(rowMongo["totalCost"])}"
|
row["custo_hit"] = f"{float(rowMongo["totalCost"])}"
|
||||||
row["qtd_token_input"] = rowMongo.get('usageByType', {}).get('input', 0)
|
|
||||||
row["qtd_token_output"] = rowMongo.get('usageByType', {}).get('output', 0)
|
token_output = rowMongo.get('usageByType', {}).get('output', {})
|
||||||
|
token_input = rowMongo.get('usageByType', {}).get('input',{})
|
||||||
|
|
||||||
|
row["qtd_token_input"] = token_input.get('usage', 0)
|
||||||
|
row["qtd_token_output"] = token_output.get('usage', 0)
|
||||||
|
row["total_cost_token"] = float(token_input.get('usageCost',0) + token_output.get('usageCost', 0))
|
||||||
|
row["llm_provider"] = token_output.get('provider','unknown')
|
||||||
|
|
||||||
|
tts = rowMongo.get('usageByType', {}).get('stt',{})
|
||||||
|
row["tts_model"] = tts.get('product', 'unknown')
|
||||||
|
row["tts_provider"] = tts.get('provider', 'unknown')
|
||||||
|
row["tts_cost"] = tts.get('usageCost', 0)
|
||||||
|
row["tts_usage"] = tts.get('usage', 0)
|
||||||
|
|
||||||
row["total_min"] = f"{(int(row['total_billsec']) / 60):.2f}"
|
row["total_min"] = f"{(int(row['total_billsec']) / 60):.2f}"
|
||||||
|
|
||||||
self.client_price_row(products, row)
|
self.client_price_row(products, row)
|
||||||
|
@ -259,6 +266,14 @@ class TranscriptionReportService:
|
||||||
"custo_hit": "Custo HIT",
|
"custo_hit": "Custo HIT",
|
||||||
"qtd_token_input": "Quantidade de tokens(input)",
|
"qtd_token_input": "Quantidade de tokens(input)",
|
||||||
"qtd_token_output": "Quantidade de tokens(output)",
|
"qtd_token_output": "Quantidade de tokens(output)",
|
||||||
|
"total_cost_token": "Preço Final LLM",
|
||||||
|
"llm_provider": "Provider LLM",
|
||||||
|
|
||||||
|
"tts_model": "TTS",
|
||||||
|
"tts_provider": "Provider TTS",
|
||||||
|
"tts_cost": "Preço Final TTS",
|
||||||
|
"tts_usage": "Segundos Transcritos",
|
||||||
|
|
||||||
"client_total_cost": "Custo Cliente",
|
"client_total_cost": "Custo Cliente",
|
||||||
"client_price": "Preço Cliente por Minuto",
|
"client_price": "Preço Cliente por Minuto",
|
||||||
"start_call": "Inicio",
|
"start_call": "Inicio",
|
||||||
|
|
|
@ -56,7 +56,15 @@ interface HitTranscriptionData {
|
||||||
total_billsec: number // Quantidade de segundos
|
total_billsec: number // Quantidade de segundos
|
||||||
qtd_token_input: number // Quantidade de tokens(input)
|
qtd_token_input: number // Quantidade de tokens(input)
|
||||||
qtd_token_output: number // Quantidade de tokens(output)
|
qtd_token_output: number // Quantidade de tokens(output)
|
||||||
total_min: number,
|
total_cost_token: number // Total token(input + output)
|
||||||
|
llm_provider: string // Provider llm
|
||||||
|
|
||||||
|
// tts_model: string // Modelo de trascrição de audio para texto
|
||||||
|
tts_provider: string // Provedor do tts
|
||||||
|
tts_cost: number // Custo total dos minutos do audio em texto
|
||||||
|
tts_usage: number // Tempo total de trascrição do audio em segundos
|
||||||
|
|
||||||
|
total_min: number, // Minutos de ligação
|
||||||
custo_hit: string // Custo HIT
|
custo_hit: string // Custo HIT
|
||||||
client_total_cost: string // Custo Cliente
|
client_total_cost: string // Custo Cliente
|
||||||
client_price: string // Preço Cliente por Minuto
|
client_price: string // Preço Cliente por Minuto
|
||||||
|
@ -471,6 +479,12 @@ export default function TranscriptionTable() {
|
||||||
<TableHead>Fim</TableHead>
|
<TableHead>Fim</TableHead>
|
||||||
<TableHead>Tokens (Input)</TableHead>
|
<TableHead>Tokens (Input)</TableHead>
|
||||||
<TableHead>Tokens (Output)</TableHead>
|
<TableHead>Tokens (Output)</TableHead>
|
||||||
|
<TableHead>Preço Final LLM ($)</TableHead>
|
||||||
|
<TableHead>Provider LLM</TableHead>
|
||||||
|
{/* <TableHead>Model TTS</TableHead> */}
|
||||||
|
<TableHead>Provider TTS</TableHead>
|
||||||
|
<TableHead>Preço Final TTS ($)</TableHead>
|
||||||
|
<TableHead>Segundos Transcritos</TableHead>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
@ -517,6 +531,24 @@ export default function TranscriptionTable() {
|
||||||
<TableCell>{formatDateTime((item as HitTranscriptionData).end_call || "-")}</TableCell>
|
<TableCell>{formatDateTime((item as HitTranscriptionData).end_call || "-")}</TableCell>
|
||||||
<TableCell>{(item as HitTranscriptionData).qtd_token_input || "-"}</TableCell>
|
<TableCell>{(item as HitTranscriptionData).qtd_token_input || "-"}</TableCell>
|
||||||
<TableCell>{(item as HitTranscriptionData).qtd_token_output || "-"}</TableCell>
|
<TableCell>{(item as HitTranscriptionData).qtd_token_output || "-"}</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
{(item as HitTranscriptionData)?.total_cost_token
|
||||||
|
? `$ ${Number((item as HitTranscriptionData).total_cost_token).toFixed(7)}`
|
||||||
|
: "-"}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{(item as HitTranscriptionData).llm_provider || "-"}</TableCell>
|
||||||
|
{/* <TableCell>{(item as HitTranscriptionData).tts_model || "-"}</TableCell> */}
|
||||||
|
<TableCell>{(item as HitTranscriptionData).tts_provider || "-"}</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
{(item as HitTranscriptionData)?.tts_cost
|
||||||
|
? `$ ${Number((item as HitTranscriptionData).tts_cost).toFixed(2)}`
|
||||||
|
: "-"}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{(item as HitTranscriptionData).tts_usage || "-"}</TableCell>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
|
Loading…
Reference in New Issue