pub async fn find_current_data(metric: AlertMetric, model_id: Id, context: &App) -> Result<f32> {
	// Grab the model from the DB
	let bytes = get_model_bytes(&context.storage, model_id).await?;
	let model = tangram_model::from_bytes(&bytes)?;
	// Determine model type
	let model_inner = model.inner();
	let model_type = AlertModelType::from(model_inner);
	if !metric.validate(model_type) {
		return Err(anyhow!(
			"Invalid metric {} for model type {:?}",
			metric,
			model_type
		));
	}

	// match on model_inner
	let result = match metric {
		AlertMetric::Accuracy => {
			// We know we have a classifier, need to get the accuracy from either type
			match model_inner {
				tangram_model::ModelInnerReader::BinaryClassifier(binary_classifier) => {
					binary_classifier
						.read()
						.test_metrics()
						.default_threshold() // TODO ask if this is correct?
						.accuracy()
				}
				tangram_model::ModelInnerReader::MulticlassClassifier(multiclass_classifier) => {
					multiclass_classifier.read().test_metrics().accuracy()
				}
				_ => unreachable!(),
			}
		}
		AlertMetric::MeanSquaredError => {
			// we know we have a regressor, just read it
			match model_inner {
				tangram_model::ModelInnerReader::Regressor(regressor) => {
					regressor.read().test_metrics().mse()
				}
				_ => unreachable!(),
			}
		}
		AlertMetric::RootMeanSquaredError => {
			// we know we have a regressor, just read it
			match model_inner {
				tangram_model::ModelInnerReader::Regressor(regressor) => {
					regressor.read().test_metrics().rmse()
				}
				_ => unreachable!(),
			}
		}
	};
	Ok(result)
}
/// Read the model, find the training metric value for the given AlertMetric
Read the model, find the training metric value for the given AlertMetric
Read the model find the training metric value for the given AlertMetric
pub async fn find_current_data(metric: AlertMetric, model_id: Id, context: &App) -> Result<f32> {
	// Grab the model from the DB
	let bytes = get_model_bytes(&context.storage, model_id).await?;
	let model = tangram_model::from_bytes(&bytes)?;
	// Determine model type
	let model_inner = model.inner();
	let model_type = AlertModelType::from(model_inner);
	if !metric.validate(model_type) {
		return Err(anyhow!(
			"Invalid metric {} for model type {:?}",
			metric,
			model_type
		));
	}
	// match on model_inner
	let result = match metric {
		AlertMetric::Accuracy => {
			// We know we have a classifier, need to get the accuracy from either type
			match model_inner {
				tangram_model::ModelInnerReader::BinaryClassifier(binary_classifier) => {
					binary_classifier
						.read()
						.test_metrics()
						.default_threshold() // TODO ask if this is correct?
						.accuracy()
				}
				tangram_model::ModelInnerReader::MulticlassClassifier(multiclass_classifier) => {
					multiclass_classifier.read().test_metrics().accuracy()
				}
				_ => unreachable!(),
			}
		}
		AlertMetric::MeanSquaredError => {
			// we know we have a regressor, just read it
			match model_inner {
				tangram_model::ModelInnerReader::Regressor(regressor) => {
					regressor.read().test_metrics().mse()
				}
				_ => unreachable!(),
			}
		}
		AlertMetric::RootMeanSquaredError => {
			// we know we have a regressor, just read it
			match model_inner {
				tangram_model::ModelInnerReader::Regressor(regressor) => {
					regressor.read().test_metrics().rmse()
				}
				_ => unreachable!(),
			}
		}
	};
	Ok(result)
}
pub async fn find_current_data ( metric : AlertMetric , model_id : Id , context : & App ) -> Result < f32 > { // Grab the model from the DB let bytes = get_model_bytes ( & context . storage , model_id ) . await ? ; let model = tangram_model :: from_bytes ( & bytes ) ? ; // Determine model type let model_inner = model . inner ( ) ; let model_type = AlertModelType :: from ( model_inner ) ; if ! metric . validate ( model_type ) { return Err ( anyhow ! ( " " metric model_type ) ) ; } // match on model_inner let result = match metric { AlertMetric :: Accuracy => { // We know we have a classifier, need to get the accuracy from either type match model_inner { tangram_model :: ModelInnerReader :: BinaryClassifier ( binary_classifier ) => { binary_classifier . read ( ) . test_metrics ( ) . default_threshold ( ) // TODO ask if this is correct? . accuracy ( ) } tangram_model :: ModelInnerReader :: MulticlassClassifier ( multiclass_classifier ) => { multiclass_classifier . read ( ) . test_metrics ( ) . accuracy ( ) } _ => unreachable ! ( ) , } } AlertMetric :: MeanSquaredError => { // we know we have a regressor, just read it match model_inner { tangram_model :: ModelInnerReader :: Regressor ( regressor ) => { regressor . read ( ) . test_metrics ( ) . mse ( ) } _ => unreachable ! ( ) , } } AlertMetric :: RootMeanSquaredError => { // we know we have a regressor, just read it match model_inner { tangram_model :: ModelInnerReader :: Regressor ( regressor ) => { regressor . read ( ) . test_metrics ( ) . rmse ( ) } _ => unreachable ! ( ) , } } } ; Ok ( result ) }
Read the model, find the training metric value for the given AlertMetric
Read the model find the training metric value for the given AlertMetric
metric
AlertMetric
model_id
Id
context
&App
metric
AlertMetric
model_id
Id
context
&App