Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Add avgResolutionDays to issueStat query - #239

Merged
danbi2990 merged 1 commit into
mainfrom
kai/avg-resolution-days
Sep 16, 2025
Merged

Add avgResolutionDays to issueStat query#239
danbi2990 merged 1 commit into
mainfrom
kai/avg-resolution-days

Conversation

@Goder-0

@Goder-0 Goder-0 commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

Close #198

@codecov

codecov Bot commented Sep 9, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 36.92%. Comparing base (a4d6075) to head (617e6a6).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danbi2990
danbi2990 self-requested a review September 9, 2025 06:07
Comment thread CHANGELOG.md Outdated
Comment on lines +11 to +12
- Added `avgResolutionDays` field to the `issueStat` GraphQL query. This field
calculates the average resolution time in days for issues marked as 'resolved'.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this entry to the end of the "Added" section? I think it reads more naturally in order of addition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment thread src/api/issue_stat.rs Outdated
.sum();

let avg_resolution_days = if resolved_issue_count > 0 {
Some(total_resolution_days / f64::from(resolved_issue_count))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about synchronizing the sources of sum and count? If an error occurs during summation, the average may be inaccurate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I’ve updated it.

@Goder-0
Goder-0 force-pushed the kai/avg-resolution-days branch 2 times, most recently from 1970dbb to ea5f856 Compare September 11, 2025 08:15
Comment thread src/api/issue_stat.rs Outdated
Comment on lines +114 to +115
let avg_resolution_days = if !resolution_days.is_empty() {
Some(resolution_days.iter().sum::<f64>() / resolution_days.len() as f64)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry — fixed right after the CI failure.

Comment thread src/api/issue_stat.rs Outdated
Comment on lines +117 to +121
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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you follow the convention in pull_request_stat.rs? Converting usize => i32 => f64 seems inefficient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it using a cast. Do you have any better suggestions?

Comment thread src/api/issue_stat.rs Outdated
.total(SpanTotal::from(Unit::Day).days_are_24_hours())
.ok()?;

Some(resolution_days - pending_days)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve made the changes and also added the corresponding test cases

@Goder-0
Goder-0 force-pushed the kai/avg-resolution-days branch 2 times, most recently from 509b987 to 711bb08 Compare September 15, 2025 01:39
Comment thread src/api/issue_stat.rs Outdated
Comment on lines +119 to +176
let count: f64 = cast(resolution_days.len()).unwrap_or(0.0);

if count == 0.0 {
None
} else {
Some(resolution_days.iter().sum::<f64>() / count)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment thread CHANGELOG.md Outdated
Comment on lines +44 to +45
- Added `avgResolutionDays` field to the `issueStat` GraphQL query. This field
calculates the average resolution time in days for issues marked as 'resolved'.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this under the issueStat entry? (line 23)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@Goder-0
Goder-0 force-pushed the kai/avg-resolution-days branch from 711bb08 to 606b326 Compare September 15, 2025 02:28
Comment thread src/api/issue.rs Outdated
Comment on lines +115 to +116
pub(crate) const TODO_LIST_PROJECT_TITLE: &str = "to-do list";
pub(crate) const TODO_LIST_STATUS_DONE: &str = "Done";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 혹시 api.rs 로 옮기는게 나을지 봐주실 수 있을까요?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옮기는게 좋을 것 같습니다. 옮기도록 하겠습니다.

Comment thread src/api/issue_stat.rs
} else {
Some(
resolution_days.iter().sum::<f64>()
/ resolution_days

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolution_days 가 0일 수도 있을까요?

@Goder-0 Goder-0 Sep 15, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체 코드는 다음과 같습니다. 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")?,
    )
};

@Goder-0
Goder-0 force-pushed the kai/avg-resolution-days branch from 606b326 to 617e6a6 Compare September 15, 2025 08:42
@danbi2990
danbi2990 merged commit a36d456 into main Sep 16, 2025
12 checks passed
@danbi2990
danbi2990 deleted the kai/avg-resolution-days branch September 16, 2025 00:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

통계 구현: 인원, 기간, 저장소별 할당 & resolved 이슈의 평균 처리 기간

3 participants