Last active
February 7, 2019 00:57
-
-
Save satiani/2227d422d7cc3f32790bef426116402e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mut guard_stats: HashMap<u16, (u16, [u16; 60])> = HashMap::new(); | |
let mut current_guard_id: u16 = 0; | |
let mut current_sleep_start_time: NaiveDateTime = NaiveDateTime::from_timestamp(0, 0); | |
for entry in log_entries { | |
match entry.entry_type { | |
EntryType::StartedShift(guard_id) => current_guard_id = guard_id, | |
EntryType::StartedSleeping => current_sleep_start_time = entry.date_time, | |
EntryType::WokeUp => { | |
let _entry = guard_stats.entry(current_guard_id); | |
let mut _temp0 = 0; | |
let mut _temp1 = [0u16; 60]; | |
let stats = _entry.or_insert((_temp0, _temp1)); | |
let sleep_start_min = current_sleep_start_time.minute() as u8; | |
let sleep_end_min = entry.date_time.minute() as u8; | |
for i in sleep_start_min..=sleep_end_min { | |
stats.1[i as usize] += 1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment