History

[hours-demo] computation now seems sound

Sebastian Thiel committed 5 years ago

Commit 935fa9c1 parent 26ecca21 file · +14 −13Browse files

Unified · Split

examples/hours/src/main.rs+14−13
@@ -155,34 +155,35 @@ fn main() -> anyhow::Result<()> { · 154 unmodified lines
155155 .expect("at least one commit at this point");
156156 writeln!(
157157 io::stdout(),
158− "total hours: {}, total commits = {}",
158+ "total hours: {:.02}\ntotal 8h days: {:.02}\ntotal commits = {}",
159159 total_hours,
160+ total_hours / HOURS_PER_WORKDAY,
160161 total_commits
161162 )?;
162163 assert_eq!(total_commits, all_commits.len() as u32, "need to get all commits");
163164 Ok(())
164165 }
165166
167+const MINUTES_PER_HOUR: f32 = 60.0;
168+const HOURS_PER_WORKDAY: f32 = 8.0;
169+
166170 fn estimate_hours(commits: &[CommitInfo]) -> WorkByPerson {
167171 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;
170174
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(
173177 0_f32,
174178 |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;
176180 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
178182 } else {
179− hours + (FIRST_COMMIT_ADDITION_IN_MINUTES / 60.0)
183+ hours + (FIRST_COMMIT_ADDITION_IN_MINUTES / MINUTES_PER_HOUR)
180184 }
181185 },
182− )
183− } else {
184− FIRST_COMMIT_ADDITION_IN_MINUTES / 60.0
185− };
186+ );
186187 let author = &commits[0];
187188 WorkByPerson {
188189 name: author.name.to_owned(),
@@ -208,7 +209,7 @@ impl Display for WorkByPerson { · 19 unmodified lines
208209 f,
209210 "total time spent: {:.02}h ({:.02} 8h days)",
210211 self.hours,
211− self.hours / 8.0
212+ self.hours / HOURS_PER_WORKDAY
212213 )
213214 }
214215 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t