Fixed a bug that was miscounting the best time occurences for cars
This commit is contained in:
parent
5dd278b8f1
commit
4a21a552d7
1 changed files with 6 additions and 6 deletions
|
|
@ -98,21 +98,21 @@ fn print_best_times() {
|
||||||
}
|
}
|
||||||
fn print_best_cars() {
|
fn print_best_cars() {
|
||||||
let best_cars = BEST_CARS.lock().unwrap();
|
let best_cars = BEST_CARS.lock().unwrap();
|
||||||
let mut car_count: HashMap<String, (usize, u8, BestCarRecord)> = HashMap::new();
|
let mut car_count: HashMap<String, (BestCarRecord, usize)> = HashMap::new();
|
||||||
|
|
||||||
// Count occurrences and store RQ
|
// Count occurrences and store RQ
|
||||||
for ((_, rq, _), best_car) in best_cars.iter() {
|
for (_key, best_car) in best_cars.iter() {
|
||||||
let entry = car_count
|
let entry = car_count
|
||||||
.entry(best_car.car_rid.clone())
|
.entry(best_car.car_rid.clone())
|
||||||
.or_insert((0, *rq, best_car.clone()));
|
.or_insert((best_car.clone(), 0));
|
||||||
entry.0 += 1;
|
entry.1 += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to vector and sort by RQ first, then frequency
|
// Convert to vector and sort by RQ first, then frequency
|
||||||
let mut car_count_vec: Vec<_> = car_count.iter().collect();
|
let mut car_count_vec: Vec<_> = car_count.iter().collect();
|
||||||
car_count_vec.sort_by(|a, b| a.1.2.rq.cmp(&b.1.2.rq).then(a.0.cmp(b.0)));
|
car_count_vec.sort_by(|a, b| a.1.0.rq.cmp(&b.1.0.rq).then(a.1.1.cmp(&b.1.1)));
|
||||||
|
|
||||||
for (_car_rid, (count, _rq, car_record)) in car_count_vec {
|
for (_car_rid, (car_record, count)) in car_count_vec {
|
||||||
println!(
|
println!(
|
||||||
"{},{},{},{},{}",
|
"{},{},{},{},{}",
|
||||||
car_record.rq, car_record.brand, car_record.only_name, car_record.year, count
|
car_record.rq, car_record.brand, car_record.only_name, car_record.year, count
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue