Unified · Split
| @@ -155,34 +155,35 @@ fn main() -> anyhow::Result<()> { · 154 unmodified lines | |||
| 155 | .expect("at least one commit at this point"); | 155 | .expect("at least one commit at this point"); |
| 156 | writeln!( | 156 | writeln!( |
| 157 | io::stdout(), | 157 | io::stdout(), |
| 158 | "total hours: {}, total commits = {}", | 158 | "total hours: {:.02}\ntotal 8h days: {:.02}\ntotal commits = {}", |
| 159 | total_hours, | 159 | total_hours, |
| 160 | total_hours / HOURS_PER_WORKDAY, | ||
| 160 | total_commits | 161 | total_commits |
| 161 | )?; | 162 | )?; |
| 162 | assert_eq!(total_commits, all_commits.len() as u32, "need to get all commits"); | 163 | assert_eq!(total_commits, all_commits.len() as u32, "need to get all commits"); |
| 163 | Ok(()) | 164 | Ok(()) |
| 164 | } | 165 | } |
| 165 | 166 | ||
| 167 | const MINUTES_PER_HOUR: f32 = 60.0; | ||
| 168 | const HOURS_PER_WORKDAY: f32 = 8.0; | ||
| 169 | |||
| 166 | fn estimate_hours(commits: &[CommitInfo]) -> WorkByPerson { | 170 | fn estimate_hours(commits: &[CommitInfo]) -> WorkByPerson { |
| 167 | assert!(!commits.is_empty()); | 171 | assert!(!commits.is_empty()); |
| 168 | const MAX_COMMIT_DIFFERENCE_IN_MINUTES: f32 = 2.0 * 60.0; | 172 | const MAX_COMMIT_DIFFERENCE_IN_MINUTES: f32 = 2.0 * MINUTES_PER_HOUR; |
| 169 | const FIRST_COMMIT_ADDITION_IN_MINUTES: f32 = 2.0 * 60.0; | 173 | const FIRST_COMMIT_ADDITION_IN_MINUTES: f32 = 2.0 * MINUTES_PER_HOUR; |
| 170 | 174 | ||
| 171 | let hours = if commits.len() > 1 { | 175 | let hours = FIRST_COMMIT_ADDITION_IN_MINUTES / 60.0 |
| 172 | commits.iter().rev().tuple_windows().fold( | 176 | + commits.iter().rev().tuple_windows().fold( |
| 173 | 0_f32, | 177 | 0_f32, |
| 174 | |hours, (cur, next): (&git_object::mutable::Signature, &git_object::mutable::Signature)| { | 178 | |hours, (cur, next): (&git_object::mutable::Signature, &git_object::mutable::Signature)| { |
| 175 | let change_in_minutes = (next.time.time - cur.time.time) as f32 / 60.0; | 179 | let change_in_minutes = (next.time.time - cur.time.time) as f32 / MINUTES_PER_HOUR; |
| 176 | if change_in_minutes < MAX_COMMIT_DIFFERENCE_IN_MINUTES { | 180 | if change_in_minutes < MAX_COMMIT_DIFFERENCE_IN_MINUTES { |
| 177 | hours + change_in_minutes as f32 / 60_f32 | 181 | hours + change_in_minutes as f32 / MINUTES_PER_HOUR |
| 178 | } else { | 182 | } else { |
| 179 | hours + (FIRST_COMMIT_ADDITION_IN_MINUTES / 60.0) | 183 | hours + (FIRST_COMMIT_ADDITION_IN_MINUTES / MINUTES_PER_HOUR) |
| 180 | } | 184 | } |
| 181 | }, | 185 | }, |
| 182 | ) | 186 | ); |
| 183 | } else { | ||
| 184 | FIRST_COMMIT_ADDITION_IN_MINUTES / 60.0 | ||
| 185 | }; | ||
| 186 | let author = &commits[0]; | 187 | let author = &commits[0]; |
| 187 | WorkByPerson { | 188 | WorkByPerson { |
| 188 | name: author.name.to_owned(), | 189 | name: author.name.to_owned(), |
| @@ -208,7 +209,7 @@ impl Display for WorkByPerson { · 19 unmodified lines | |||
| 208 | f, | 209 | f, |
| 209 | "total time spent: {:.02}h ({:.02} 8h days)", | 210 | "total time spent: {:.02}h ({:.02} 8h days)", |
| 210 | self.hours, | 211 | self.hours, |
| 211 | self.hours / 8.0 | 212 | self.hours / HOURS_PER_WORKDAY |
| 212 | ) | 213 | ) |
| 213 | } | 214 | } |
| 214 | } | 215 | } |