Add avgResolutionDays to issueStat query - #239
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #239 +/- ##
==========================================
+ Coverage 35.51% 36.92% +1.41%
==========================================
Files 17 17
Lines 1025 1048 +23
==========================================
+ Hits 364 387 +23
Misses 661 661 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| - Added `avgResolutionDays` field to the `issueStat` GraphQL query. This field | ||
| calculates the average resolution time in days for issues marked as 'resolved'. |
There was a problem hiding this comment.
Could you move this entry to the end of the "Added" section? I think it reads more naturally in order of addition.
| .sum(); | ||
|
|
||
| let avg_resolution_days = if resolved_issue_count > 0 { | ||
| Some(total_resolution_days / f64::from(resolved_issue_count)) |
There was a problem hiding this comment.
How about synchronizing the sources of sum and count? If an error occurs during summation, the average may be inaccurate.
There was a problem hiding this comment.
Thanks for the suggestion. I’ve updated it.
1970dbb to
ea5f856
Compare
| let avg_resolution_days = if !resolution_days.is_empty() { | ||
| Some(resolution_days.iter().sum::<f64>() / resolution_days.len() as f64) |
There was a problem hiding this comment.
There are two Clippy warnings:
casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss
-W clippy::cast-precision-loss implied by -W clippy::pedantic
to override -W clippy::pedantic add #[allow(clippy::cast_precision_loss)]
unnecessary boolean not operation
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
-W clippy::if-not-else implied by -W clippy::pedantic
to override -W clippy::pedantic add #[allow(clippy::if_not_else)]
Could you fix these warnings?
There was a problem hiding this comment.
Sorry — fixed right after the CI failure.
| let count: i32 = resolution_days | ||
| .len() | ||
| .try_into() | ||
| .expect("The number of resolution days will not exceed i32::MAX"); | ||
| Some(resolution_days.iter().sum::<f64>() / f64::from(count)) |
There was a problem hiding this comment.
Could you follow the convention in pull_request_stat.rs? Converting usize => i32 => f64 seems inefficient.
There was a problem hiding this comment.
I fixed it using a cast. Do you have any better suggestions?
| .total(SpanTotal::from(Unit::Day).days_are_24_hours()) | ||
| .ok()?; | ||
|
|
||
| Some(resolution_days - pending_days) |
There was a problem hiding this comment.
If someone mistakenly sets a large value for pending_days, it could skew the average.
How about guarding against negative values with Some(f64::max(resolution_days - pending_days, 0.0))?
There was a problem hiding this comment.
I’ve made the changes and also added the corresponding test cases
509b987 to
711bb08
Compare
| let count: f64 = cast(resolution_days.len()).unwrap_or(0.0); | ||
|
|
||
| if count == 0.0 { | ||
| None | ||
| } else { | ||
| Some(resolution_days.iter().sum::<f64>() / count) | ||
| } |
There was a problem hiding this comment.
| let count: f64 = cast(resolution_days.len()).unwrap_or(0.0); | |
| if count == 0.0 { | |
| None | |
| } else { | |
| Some(resolution_days.iter().sum::<f64>() / count) | |
| } | |
| Some( | |
| resolution_days.iter().sum::<f64>() | |
| / resolution_days | |
| .len() | |
| .to_f64() | |
| .context("Failed to convert usize to f64")?, | |
| ) |
I meant using to_f64().context(...), which seems simpler.
| - Added `avgResolutionDays` field to the `issueStat` GraphQL query. This field | ||
| calculates the average resolution time in days for issues marked as 'resolved'. |
There was a problem hiding this comment.
Could you move this under the issueStat entry? (line 23)
711bb08 to
606b326
Compare
| pub(crate) const TODO_LIST_PROJECT_TITLE: &str = "to-do list"; | ||
| pub(crate) const TODO_LIST_STATUS_DONE: &str = "Done"; |
There was a problem hiding this comment.
이거 혹시 api.rs 로 옮기는게 나을지 봐주실 수 있을까요?
There was a problem hiding this comment.
옮기는게 좋을 것 같습니다. 옮기도록 하겠습니다.
| } else { | ||
| Some( | ||
| resolution_days.iter().sum::<f64>() | ||
| / resolution_days |
There was a problem hiding this comment.
전체 코드는 다음과 같습니다. vector가 비어있을 경우, None으로 처리되어 0인 경우는 예외처리됩니다.
let avg_resolution_days = if resolution_days.is_empty() {
None
} else {
Some(
resolution_days.iter().sum::<f64>()
/ resolution_days
.len()
.to_f64()
.context("Failed to convert usize to f64")?,
)
};606b326 to
617e6a6
Compare
Close #198