|
1 | | -use std::collections::{HashMap, HashSet}; |
| 1 | +#[path = "aggregate/buckets.rs"] |
| 2 | +mod buckets; |
| 3 | +#[path = "aggregate/overview.rs"] |
| 4 | +mod overview; |
2 | 5 |
|
3 | | -use crate::review; |
4 | | - |
5 | | -use super::super::super::{FeedbackEvalComment, FeedbackEvalReport, LoadedFeedbackEvalInput}; |
| 6 | +use super::super::super::{FeedbackEvalReport, LoadedFeedbackEvalInput}; |
6 | 7 | use super::super::examples::{build_showcase_candidates, build_vague_rejections}; |
7 | | -use super::stats::{ |
8 | | - add_bucket_count, buckets_from_counts, build_bucket, build_threshold_metrics, ratio, |
9 | | -}; |
| 8 | +use super::stats::{buckets_from_counts, build_threshold_metrics, ratio}; |
| 9 | +use buckets::collect_feedback_bucket_counts; |
| 10 | +use overview::build_feedback_overview; |
| 11 | + |
| 12 | +#[cfg(test)] |
| 13 | +use super::super::super::FeedbackEvalComment; |
10 | 14 |
|
11 | 15 | pub(in super::super::super) fn build_feedback_eval_report( |
12 | 16 | loaded: &LoadedFeedbackEvalInput, |
13 | 17 | confidence_threshold: f32, |
14 | 18 | ) -> FeedbackEvalReport { |
15 | | - let accepted = loaded |
16 | | - .comments |
17 | | - .iter() |
18 | | - .filter(|comment| comment.accepted) |
19 | | - .count(); |
20 | | - let rejected = loaded.comments.len().saturating_sub(accepted); |
21 | | - let labeled_reviews = loaded |
22 | | - .comments |
23 | | - .iter() |
24 | | - .filter_map(|comment| comment.review_id.as_ref()) |
25 | | - .collect::<HashSet<_>>() |
26 | | - .len(); |
27 | | - |
28 | | - let vague_comments: Vec<&FeedbackEvalComment> = loaded |
29 | | - .comments |
30 | | - .iter() |
31 | | - .filter(|comment| review::is_vague_comment_text(&comment.content)) |
32 | | - .collect(); |
33 | | - let vague_accepted = vague_comments |
34 | | - .iter() |
35 | | - .filter(|comment| comment.accepted) |
36 | | - .count(); |
37 | | - let vague_bucket = build_bucket("vague".to_string(), vague_comments.len(), vague_accepted); |
38 | | - |
39 | | - let mut category_counts = HashMap::new(); |
40 | | - let mut severity_counts = HashMap::new(); |
41 | | - let mut repo_counts = HashMap::new(); |
42 | | - let mut file_pattern_counts = HashMap::new(); |
43 | | - |
44 | | - for comment in &loaded.comments { |
45 | | - add_bucket_count(&mut category_counts, &comment.category, comment.accepted); |
46 | | - |
47 | | - let severity = comment.severity.as_deref().unwrap_or("unknown"); |
48 | | - add_bucket_count(&mut severity_counts, severity, comment.accepted); |
49 | | - |
50 | | - if let Some(repo) = comment.repo.as_deref() { |
51 | | - add_bucket_count(&mut repo_counts, repo, comment.accepted); |
52 | | - } |
53 | | - |
54 | | - let unique_patterns = comment |
55 | | - .file_patterns |
56 | | - .iter() |
57 | | - .map(String::as_str) |
58 | | - .collect::<HashSet<_>>(); |
59 | | - for pattern in unique_patterns { |
60 | | - add_bucket_count(&mut file_pattern_counts, pattern, comment.accepted); |
61 | | - } |
62 | | - } |
| 19 | + let overview = build_feedback_overview(loaded); |
| 20 | + let bucket_counts = collect_feedback_bucket_counts(&loaded.comments); |
63 | 21 |
|
64 | 22 | FeedbackEvalReport { |
65 | 23 | total_comments_seen: loaded.total_comments_seen, |
66 | 24 | total_reviews_seen: loaded.total_reviews_seen, |
67 | 25 | labeled_comments: loaded.comments.len(), |
68 | | - labeled_reviews, |
69 | | - accepted, |
70 | | - rejected, |
71 | | - acceptance_rate: ratio(accepted, loaded.comments.len()), |
| 26 | + labeled_reviews: overview.labeled_reviews, |
| 27 | + accepted: overview.accepted, |
| 28 | + rejected: overview.rejected, |
| 29 | + acceptance_rate: ratio(overview.accepted, loaded.comments.len()), |
72 | 30 | confidence_threshold, |
73 | | - vague_comments: vague_bucket, |
| 31 | + vague_comments: overview.vague_bucket, |
74 | 32 | confidence_metrics: build_threshold_metrics(&loaded.comments, confidence_threshold), |
75 | | - by_category: buckets_from_counts(category_counts), |
76 | | - by_severity: buckets_from_counts(severity_counts), |
77 | | - by_repo: buckets_from_counts(repo_counts), |
78 | | - by_file_pattern: buckets_from_counts(file_pattern_counts), |
| 33 | + by_category: buckets_from_counts(bucket_counts.category_counts), |
| 34 | + by_severity: buckets_from_counts(bucket_counts.severity_counts), |
| 35 | + by_repo: buckets_from_counts(bucket_counts.repo_counts), |
| 36 | + by_file_pattern: buckets_from_counts(bucket_counts.file_pattern_counts), |
79 | 37 | showcase_candidates: build_showcase_candidates(&loaded.comments, confidence_threshold), |
80 | 38 | vague_rejections: build_vague_rejections(&loaded.comments), |
81 | 39 | } |
|
0 commit comments