pub async fn seed_single_prediction_event(app: &App, model_id: Id) -> Result<(Id, String)> {
	let data_path = workspace_root().join("heart_disease.csv");
	let table = tangram_table::Table::from_path(&data_path, Default::default(), &mut |_| {})?;

	let id = Id::generate();
	let identifier = NumberOrString::String(id.to_string());

	// NOTE - we use the app's clock for the date, but this code still requires chrono
	// Fix this when we switch entirely
	let now = app.clock().now_utc().unix_timestamp();
	let naive_date = chrono::NaiveDateTime::from_timestamp(now, 0);
	let date = chrono::DateTime::from_utc(naive_date, chrono::Utc);

	let record = get_seeded_random_row(table.view(), 0.5);

	let input = Input {
		age: 63.0,
		gender: Gender::Male,
		chest_pain: ChestPain::TypicalAngina,
		resting_blood_pressure: 145.0,
		cholesterol: 233.0,
		fasting_blood_sugar_greater_than_120: FastingBloodSugarGreaterThan120::True,
		resting_ecg_result: RestingEcgResult::Lvh,
		exercise_max_heart_rate: 150.0,
		exercise_induced_angina: ExerciseInducedAngina::No,
		exercise_st_depression: 2.3,
		exercise_st_slope: ExerciseStSlope::Downsloping,
		fluoroscopy_vessels_colored: FluoroscopyVesselsColored::Zero,
		thallium_stress_test: ThalliumStressTest::FixedDefect,
	};

	// Ask the model to predict for the input
	let bytes = get_model_bytes(app.storage(), model_id).await?;
	let model = tangram::Model::<Input, Output>::from_bytes(&bytes, None)?;
	let output = model.predict_one(input.clone(), None);
	let output_class_name = output.class_name.as_str().to_owned();
	let output = PredictOutput::BinaryClassification(BinaryClassificationPredictOutput {
		class_name: output_class_name.clone(),
		probability: output.probability,
	});

	let result = MonitorEvent::Prediction(PredictionMonitorEvent {
		date,
		identifier,
		input: record,
		model_id,
		options: None,
		output,
	});

	let mut txn = app.begin_transaction().await?;
	app.track_events(&mut txn, vec![result]).await?;
	app.commit_transaction(txn).await?;

	Ok((id, output_class_name))
}
/// Returns the ID of the prediction as well as the predicted value
Returns the ID of the prediction as well as the predicted value
Returns the ID of the prediction as well as the predicted value
pub async fn seed_single_prediction_event(app: &App, model_id: Id) -> Result<(Id, String)> {
	let data_path = workspace_root().join("heart_disease.csv");
	let table = tangram_table::Table::from_path(&data_path, Default::default(), &mut |_| {})?;
	let id = Id::generate();
	let identifier = NumberOrString::String(id.to_string());
	// NOTE - we use the app's clock for the date, but this code still requires chrono
	// Fix this when we switch entirely
	let now = app.clock().now_utc().unix_timestamp();
	let naive_date = chrono::NaiveDateTime::from_timestamp(now, 0);
	let date = chrono::DateTime::from_utc(naive_date, chrono::Utc);
	let record = get_seeded_random_row(table.view(), 0.5);
	let input = Input {
		age: 63.0,
		gender: Gender::Male,
		chest_pain: ChestPain::TypicalAngina,
		resting_blood_pressure: 145.0,
		cholesterol: 233.0,
		fasting_blood_sugar_greater_than_120: FastingBloodSugarGreaterThan120::True,
		resting_ecg_result: RestingEcgResult::Lvh,
		exercise_max_heart_rate: 150.0,
		exercise_induced_angina: ExerciseInducedAngina::No,
		exercise_st_depression: 2.3,
		exercise_st_slope: ExerciseStSlope::Downsloping,
		fluoroscopy_vessels_colored: FluoroscopyVesselsColored::Zero,
		thallium_stress_test: ThalliumStressTest::FixedDefect,
	};
	// Ask the model to predict for the input
	let bytes = get_model_bytes(app.storage(), model_id).await?;
	let model = tangram::Model::<Input, Output>::from_bytes(&bytes, None)?;
	let output = model.predict_one(input.clone(), None);
	let output_class_name = output.class_name.as_str().to_owned();
	let output = PredictOutput::BinaryClassification(BinaryClassificationPredictOutput {
		class_name: output_class_name.clone(),
		probability: output.probability,
	});
	let result = MonitorEvent::Prediction(PredictionMonitorEvent {
		date,
		identifier,
		input: record,
		model_id,
		options: None,
		output,
	});
	let mut txn = app.begin_transaction().await?;
	app.track_events(&mut txn, vec![result]).await?;
	app.commit_transaction(txn).await?;
	Ok((id, output_class_name))
}
pub async fn seed_single_prediction_event ( app : & App , model_id : Id ) -> Result < ( Id , String ) > { let data_path = workspace_root ( ) . join ( " " ) ; let table = tangram_table :: Table :: from_path ( & data_path , Default :: default ( ) , & mut | _ | { } ) ? ; let id = Id :: generate ( ) ; let identifier = NumberOrString :: String ( id . to_string ( ) ) ; // NOTE - we use the app's clock for the date, but this code still requires chrono // Fix this when we switch entirely let now = app . clock ( ) . now_utc ( ) . unix_timestamp ( ) ; let naive_date = chrono :: NaiveDateTime :: from_timestamp ( now , 0 ) ; let date = chrono :: DateTime :: from_utc ( naive_date , chrono :: Utc ) ; let record = get_seeded_random_row ( table . view ( ) , 0.5 ) ; let input = Input { age : 63.0 , gender : Gender :: Male , chest_pain : ChestPain :: TypicalAngina , resting_blood_pressure : 145.0 , cholesterol : 233.0 , fasting_blood_sugar_greater_than_120 : FastingBloodSugarGreaterThan120 :: True , resting_ecg_result : RestingEcgResult :: Lvh , exercise_max_heart_rate : 150.0 , exercise_induced_angina : ExerciseInducedAngina :: No , exercise_st_depression : 2.3 , exercise_st_slope : ExerciseStSlope :: Downsloping , fluoroscopy_vessels_colored : FluoroscopyVesselsColored :: Zero , thallium_stress_test : ThalliumStressTest :: FixedDefect , } ; // Ask the model to predict for the input let bytes = get_model_bytes ( app . storage ( ) , model_id ) . await ? ; let model = tangram :: Model :: < Input , Output > :: from_bytes ( & bytes , None ) ? ; let output = model . predict_one ( input . clone ( ) , None ) ; let output_class_name = output . class_name . as_str ( ) . to_owned ( ) ; let output = PredictOutput :: BinaryClassification ( BinaryClassificationPredictOutput { class_name : output_class_name . clone ( ) , probability : output . probability , } ) ; let result = MonitorEvent :: Prediction ( PredictionMonitorEvent { date , identifier , input : record , model_id , options : None , output , } ) ; let mut txn = app . begin_transaction ( ) . await ? ; app . track_events ( & mut txn , vec ! [ result ] ) . await ? ; app . commit_transaction ( txn ) . await ? ; Ok ( ( id , output_class_name ) ) }
Returns the ID of the prediction as well as the predicted value
Returns the ID of the prediction as well as the predicted value
app
&App
model_id
Id