+fn merge_message(presses: &mut HashMap<MessageKey, Range>, message: Message) {
+ let key = message.key();
+ if let Some(r) = presses.get_mut(&key) {
+ if !r.contains(&message.t) {
+ r.extend(&message.t);
+ }
+ } else {
+ presses.insert(key, Range::new(&message.t));
+ }
+}
+
+fn replay_log() -> HashMap<MessageKey, Range> {
+ let mut presses = HashMap::new();
+ if std::path::Path::new(LOGFILENAME).exists() {
+ let mut log = csv::Reader::from_path(LOGFILENAME).expect("Couldn't open log for replay");
+ for message in log.deserialize() {
+ merge_message(
+ &mut presses,
+ message.expect("Error reading log during replay"),
+ );
+ }
+ }
+ presses
+}
+