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