def get(model_id: int, bbox: list, latest=False): """ Fetch latest predictions from a model for the given bbox :params model_id, bbox :raises PredictionsNotFound :returns predictions """ if (latest): # get the latest version latest_version = MLModelVersion.get_latest_version(model_id) if (latest_version is None): raise PredictionsNotFound('Predictions not found') else: version_id = latest_version.id predictions = Prediction.get_latest_predictions_in_bbox( model_id, version_id, bbox) else: predictions = Prediction.get_all_predictions_in_bbox( model_id, bbox) if (len(predictions) == 0): raise PredictionsNotFound('Predictions not found') data = [] for prediction in predictions: prediction_dto = Prediction.as_dto(prediction) data.append(prediction_dto.to_primitive()) return data
def get_prediction_by_id(prediction_id: int): """ Get a prediction by ID :params prediction_id :returns prediction """ prediction = Prediction.get(prediction_id) if prediction: return Prediction.as_dto(prediction) else: raise PredictionsNotFound
def get_all_by_model(model_id: int): """ Fetch all predictions of the given model :params model_id :returns predictions :raises PredictionsNotFound """ predictions = Prediction.get_predictions_by_model(model_id) prediction_dtos = [] for prediction in predictions: prediction_dtos.append(Prediction.as_dto(prediction).to_primitive()) return prediction_dtos