feat : update name grouping
This commit is contained in:
@@ -16,8 +16,8 @@ pub struct Student {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AttendanceRecord {
|
||||
pub student: Student,
|
||||
// Date and attendance count (1.0 for present)
|
||||
pub attendance: Vec<(NaiveDate, f64)>,
|
||||
// Date, Teacher Name, and attendance count (1.0 for present)
|
||||
pub attendance: Vec<(NaiveDate, Option<String>, f64)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -67,6 +67,30 @@ pub fn read_attendance_file<P: AsRef<Path>>(path: P) -> Result<Vec<ClassData>> {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find Teacher Row
|
||||
// Scan all rows to find "授课教师确认签名"
|
||||
let mut teacher_names = vec![None; dates.len()];
|
||||
for row in range.rows() {
|
||||
if let Some(first_cell) = row.first() {
|
||||
if let Data::String(s) = first_cell {
|
||||
if s.contains("授课教师确认签名") {
|
||||
// Found teacher row
|
||||
for (i, &col_idx) in date_col_indices.iter().enumerate() {
|
||||
if col_idx < row.len() {
|
||||
if let Data::String(name) = &row[col_idx] {
|
||||
let trimmed = name.trim();
|
||||
if !trimmed.is_empty() {
|
||||
teacher_names[i] = Some(trimmed.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate over data rows (starting from row 4, index 3)
|
||||
// Row 1: Title, Row 2: Headers, Row 3: Weekdays, Row 4: Data
|
||||
for row in range.rows().skip(3) {
|
||||
@@ -78,7 +102,7 @@ pub fn read_attendance_file<P: AsRef<Path>>(path: P) -> Result<Vec<ClassData>> {
|
||||
_ => continue, // Skip if no name
|
||||
};
|
||||
|
||||
if name.is_empty() || name == "姓名" {
|
||||
if name.is_empty() || name == "姓名" || name == "到班人数" || name.contains("授课教师") {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -110,7 +134,7 @@ pub fn read_attendance_file<P: AsRef<Path>>(path: P) -> Result<Vec<ClassData>> {
|
||||
|
||||
if is_present {
|
||||
if i < dates.len() {
|
||||
attendance_entries.push((dates[i], 1.0));
|
||||
attendance_entries.push((dates[i], teacher_names[i].clone(), 1.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user