Skip to content

Commit 7a978f0

Browse files
committed
feat: Update at attendance formatting by group
1 parent 39ea4ec commit 7a978f0

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

src/graphql/models.rs

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ pub struct Member {
5252
pub struct AttendanceRecord {
5353
pub name: String,
5454
pub year: i32,
55+
#[serde(rename = "groupId")]
56+
pub group_id: i32,
5557
#[serde(rename = "isPresent")]
5658
pub is_present: bool,
5759
#[serde(rename = "timeIn")]

src/graphql/queries.rs

+1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ pub async fn fetch_attendance() -> anyhow::Result<Vec<AttendanceRecord>> {
230230
attendanceByDate(date: "{}") {{
231231
name,
232232
year,
233+
groupId,
233234
isPresent,
234235
timeIn,
235236
}}

src/tasks/lab_attendance.rs

+36-13
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,47 @@ fn format_attendance_list(title: &str, list: &[AttendanceRecord]) -> String {
184184
);
185185
}
186186

187-
let mut by_year: HashMap<i32, Vec<&str>> = HashMap::new();
187+
let mut by_group: HashMap<i32, HashMap<i32, Vec<&str>>> = HashMap::new();
188188
for record in list {
189-
if record.year >= 1 && record.year <= 3 {
190-
by_year.entry(record.year).or_default().push(&record.name);
191-
}
189+
by_group
190+
.entry(record.group_id)
191+
.or_default()
192+
.entry(record.year)
193+
.or_default()
194+
.push(&record.name);
192195
}
193196

194197
let mut result = format!("# {}\n", title);
195-
196-
for year in 1..=3 {
197-
if let Some(names) = by_year.get(&year) {
198-
if !names.is_empty() {
199-
result.push_str(&format!("### Year {}\n", year));
200-
201-
for name in names {
202-
result.push_str(&format!("- {}\n", name));
198+
let mut group_ids: Vec<i32> = by_group.keys().cloned().collect();
199+
group_ids.sort();
200+
201+
for group_id in group_ids {
202+
result.push_str(&format!("## Group {}\n", group_id));
203+
204+
let by_year = &by_group[&group_id];
205+
let mut years: Vec<i32> = by_year.keys().cloned().collect();
206+
years.sort();
207+
208+
let mut group_counts: Vec<(i32, usize)> = by_group
209+
.iter()
210+
.map(|(&group_id, year_map)| {
211+
let total_count = year_map.values().map(|names| names.len()).sum();
212+
(group_id, total_count)
213+
})
214+
.collect();
215+
group_counts.sort_by(|a, b| b.1.cmp(&a.1));
216+
217+
for year in 1..=3 {
218+
if let Some(names) = by_year.get(&year) {
219+
if !names.is_empty() {
220+
let mut sorted_names = names.clone();
221+
sorted_names.sort();
222+
223+
for name in sorted_names {
224+
result.push_str(&format!("- {}\n", name));
225+
}
226+
result.push('\n');
203227
}
204-
result.push('\n');
205228
}
206229
}
207230
}

0 commit comments

Comments
 (0)