-
Couldn't load subscription status.
- Fork 2
Calculate rank per track #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
|
|
||
| pub fn map_start_number_to_track_rank(&mut self) { | ||
| let tracks = self.tracks.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need clone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunatelly yes - otherwise I need to somehow specify the self.tracks is immutable in calculate_track_rank function
9dad819 to
a487ff4
Compare
|
However I'm still not satisfied how the rank is displayed. I will most probably separate the result list from the registration lists. With info like start number, time, track rank and category rank. |
|
Ok, lets have it in one table for now. :) |
| pub racers: Vec<Racer>, | ||
| pub categories: Vec<String>, | ||
| pub tracks: Vec<String>, | ||
| pub tracks_rank: HashMap<String, HashMap<u32, u32>>, // track -> (start_number -> rank) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of comments we should do proper datatypes to ensure type-safety
struct Track(String);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, but in that case also tracks attribute shall be changed to tracks: Vec and that type shall be defined.
src/race.rs
Outdated
| racers, | ||
| categories: categories.into_iter().collect(), | ||
| tracks, | ||
| tracks_rank: HashMap::new(), // tracks_rank initialized as empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does comment add something more then HashMap::new()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about having Track type and assigning ranks there? We will get rid of HashMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How you mean that? Simply have new type Track which will have attribute rank, which shall be hashmap I guess, since I need to map start_number to rank.
src/race.rs
Outdated
| let racer = self | ||
| .racers | ||
| .iter_mut() | ||
| .find(|r| r.tag == tag && r.start.is_some()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add r.finished.is_none() as well? ... but we should have some initial timeout if racers starts with enabled rfids
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added - timer, could be, but not necessary right now since start/finish are on different place :)
src/components/racers.rs
Outdated
| td { | ||
| "{race.tracks_rank.get(&racer.track) | ||
| .and_then(|m| m.get(&racer.start_number)) | ||
| .map_or(String::new(), |rank| rank.to_string())}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map_or_else is better as it doesnt allocate String::new()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used map and then unwrap_or_default instead
No description provided.