27 lines
1020 B
Python
27 lines
1020 B
Python
|
import numpy as np
|
||
|
import time
|
||
|
from django.utils import timezone
|
||
|
|
||
|
def queuing_time(start_time, ai_profile_individual):
|
||
|
return ai_profile_individual["inference"][0] - start_time
|
||
|
|
||
|
def inference_cost(ai_profile_individual):
|
||
|
return ai_profile_individual["inference"][1][0] - ai_profile_individual["inference"][0]
|
||
|
|
||
|
def postprocessing_cost(ai_profile_individual):
|
||
|
return ai_profile_individual["postprocess"][1] - ai_profile_individual["postprocess"][0]
|
||
|
|
||
|
def cost_profile(start_time, ai_profile_individual):
|
||
|
result = {"queue": queuing_time(start_time, ai_profile_individual),
|
||
|
"inference": inference_cost(ai_profile_individual),
|
||
|
"postprocessing":postprocessing_cost(ai_profile_individual)}
|
||
|
return result
|
||
|
|
||
|
def backend_cost(created_at, ai_start_time):
|
||
|
"""
|
||
|
Args:
|
||
|
created_at: str : django timezone format: example: 2024-04-01 16:16:18.344 +0700
|
||
|
ai_start_time: float : timestamp
|
||
|
"""
|
||
|
received = created_at.timestamp()
|
||
|
return ai_start_time - received
|