mirror of
https://git.alemi.dev/mood.git
synced 2024-11-25 01:24:48 +01:00
feat: use vec in mood-counter to be able to sort
This commit is contained in:
parent
933cf0c762
commit
1dc9d8575f
1 changed files with 6 additions and 6 deletions
|
@ -1,5 +1,3 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
let file = std::env::var("MOOD_FILE").expect("missing MOOD_FILE env variable");
|
||||
let content = std::fs::read_to_string(file).expect("could not read MOOD_FILE contents");
|
||||
|
@ -10,15 +8,17 @@ fn main() {
|
|||
.collect();
|
||||
|
||||
let sum = lines.iter().map(|(x,_)| x).sum::<u64>() as f32;
|
||||
let mut probabilities = HashMap::new();
|
||||
let mut probabilities = Vec::new();
|
||||
|
||||
for (count, line) in &lines {
|
||||
probabilities.insert(line, *count as f32 / sum);
|
||||
probabilities.push((line, *count, *count as f32 / sum));
|
||||
}
|
||||
|
||||
probabilities.sort_by_key(|x| x.1);
|
||||
|
||||
println!("{{");
|
||||
for (line, chance) in probabilities {
|
||||
println!(" \"{}\": {:.6},", line.replace('"', "\\\""), chance);
|
||||
for (line, count, chance) in probabilities {
|
||||
println!(" \"{}\": [{}, {:.4}],", l, count, chance*100.);
|
||||
}
|
||||
println!(" \"count\": {},", lines.len());
|
||||
println!(" \"total\": {}", sum);
|
||||
|
|
Loading…
Reference in a new issue