Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "trane-cli"
version = "0.28.0"
version = "0.29.0"
build = "build.rs"
default-run = "trane"

Expand Down Expand Up @@ -29,7 +29,7 @@ rustyline-derive = "0.11.1"
tempfile = "3.27.0"
serde_json = "1.0.149"
termimad = "0.34.1"
trane = "0.28.0"
trane = "0.29.0"
# Commented out for use in local development.
# trane = { path = "../trane" }
ustr = { version = "1.1.0", features = ["serde"] }
Expand Down
28 changes: 25 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use trane::{
exercise_scorer::{ExerciseScorer, PowerLawScorer},
filter_manager::FilterManager,
graph::UnitGraph,
practice_deltas::PracticeDeltas,
practice_rewards::PracticeRewards,
practice_stats::PracticeStats,
preferences_manager::PreferencesManager,
Expand Down Expand Up @@ -269,6 +270,17 @@ impl TraneApp {
}
}

/// Prints the current batch of exercises to the terminal.
pub fn show_batch(&self) -> Result<()> {
ensure!(self.trane.is_some(), "no Trane instance is open");

println!("Batch size: {}", self.batch.len());
for exercise in &self.batch {
println!("Exercise ID: {}", exercise.id);
}
Ok(())
}

/// Exports the dependent graph as a DOT file to the given path.
pub fn export_graph(&self, path: &Path, courses_only: bool) -> Result<()> {
ensure!(self.trane.is_some(), "no Trane instance is open");
Expand Down Expand Up @@ -935,9 +947,19 @@ impl TraneApp {
// Compute the score, reward, and decide if it needs to be applied.
let scorer = PowerLawScorer {};
let reward_scorer = WeightedRewardScorer {};
let score = scorer.score(exercise_type, &previous_trials)?;
let deltas = self
.trane
.as_ref()
.unwrap()
.get_deltas(exercise_id, num_scores)?;
let score = scorer.score(
exercise_type,
&previous_trials,
&deltas,
Utc::now().timestamp(),
)?;
let mut reward = reward_scorer.score_rewards(&course_rewards, &lesson_rewards)?;
let mut total_score = score;
let mut total_score = score.value;
let apply_reward = reward_scorer.apply_reward(reward, &previous_trials);
if apply_reward {
total_score += reward;
Expand All @@ -950,7 +972,7 @@ impl TraneApp {
println!();
println!("Note: Rewards are only applied to exercises with previous scores");
println!();
println!("Score: {score:.2}");
println!("Score: {:.2}", score.value);
println!("Reward: {reward:.2}");
println!("Final score: {total_score:.2}");
println!();
Expand Down
7 changes: 7 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub(crate) enum BlacklistSubcommands {
/// Contains subcommands used for debugging.
#[derive(Clone, Debug, Subcommand)]
pub(crate) enum DebugSubcommands {
#[clap(about = "Prints the IDs of all the exercises in the current batch")]
Batch,

#[clap(about = "Exports the dependent graph as a DOT file to the given path")]
ExportGraph {
#[clap(help = "The path to the DOT file")]
Expand Down Expand Up @@ -549,6 +552,10 @@ impl TraneCli {
}

Subcommands::Debug(subcommand) => match subcommand {
DebugSubcommands::Batch => {
app.show_batch()?;
Ok(true)
}
DebugSubcommands::ExportGraph { path, courses_only } => {
app.export_graph(Path::new(&path), courses_only)?;
println!("Exported graph to {path}");
Expand Down
Loading