-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor excel, parser, and file writer modules
- Loading branch information
1 parent
ced9331
commit 074ba2a
Showing
19 changed files
with
346 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Context; | ||
use calamine::{open_workbook, Data, Range, Reader, Xlsx}; | ||
|
||
use crate::db::repository::LecturerSubjectSessionMap; | ||
|
||
pub struct Excel { | ||
pub range: Range<Data>, | ||
pub lecturer_subjects_session_map: LecturerSubjectSessionMap, | ||
} | ||
|
||
impl Excel { | ||
pub fn new(file_path: &PathBuf, sheet_name: &str) -> anyhow::Result<Self> { | ||
println!("Open excel file at {:?}", file_path); | ||
let mut excel: Xlsx<_> = | ||
open_workbook(file_path).with_context(|| "Cannot open excel file")?; | ||
println!("Open excel sheet from {}", sheet_name); | ||
let range = excel.worksheet_range(sheet_name)?; | ||
println!("Successfully open excel file"); | ||
Ok(Self { | ||
range, | ||
lecturer_subjects_session_map: LecturerSubjectSessionMap::default(), | ||
}) | ||
} | ||
|
||
pub fn with_repo_data( | ||
mut self, | ||
lecturer_subjects_session_map: LecturerSubjectSessionMap, | ||
) -> Excel { | ||
self.lecturer_subjects_session_map = lecturer_subjects_session_map; | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
pub mod find_class; | ||
pub mod retrieve; | ||
|
||
use std::path::PathBuf; | ||
|
||
use anyhow::Context; | ||
use calamine::{open_workbook, Data, Range, Reader, Xlsx}; | ||
|
||
use crate::db::repository::LecturerSubjectSessionMap; | ||
|
||
pub struct Excel { | ||
pub range: Range<Data>, | ||
pub lecturer_subjects_session_map: LecturerSubjectSessionMap, | ||
} | ||
|
||
impl Excel { | ||
pub fn new(file_path: &PathBuf, sheet_name: &str) -> anyhow::Result<Self> { | ||
println!("Open excel file at {:?}", file_path); | ||
let mut excel: Xlsx<_> = | ||
open_workbook(file_path).with_context(|| "Cannot open excel file")?; | ||
println!("Open excel sheet from {}", sheet_name); | ||
let range = excel.worksheet_range(sheet_name)?; | ||
println!("Successfully open excel file"); | ||
Ok(Self { | ||
range, | ||
lecturer_subjects_session_map: LecturerSubjectSessionMap::default(), | ||
}) | ||
} | ||
|
||
pub fn with_repo_data( | ||
mut self, | ||
lecturer_subjects_session_map: LecturerSubjectSessionMap, | ||
) -> Excel { | ||
self.lecturer_subjects_session_map = lecturer_subjects_session_map; | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::db::repository::class::ClassFromSchedule; | ||
use crate::file_writer::FileWriter; | ||
|
||
pub trait ClassFileWriter { | ||
fn write_class_info( | ||
&mut self, | ||
prefix: &str, | ||
class: &ClassFromSchedule, | ||
) -> impl std::future::Future<Output = anyhow::Result<()>> + Send; | ||
} | ||
|
||
impl ClassFileWriter for FileWriter { | ||
async fn write_class_info( | ||
&mut self, | ||
prefix: &str, | ||
class: &ClassFromSchedule, | ||
) -> anyhow::Result<()> { | ||
let query = format!( | ||
"{} {} {}, {} {}, {:?}\n", | ||
prefix, | ||
class.subject_name, | ||
class.class_code, | ||
class.day, | ||
class.session_start, | ||
class.lecturer_code | ||
); | ||
self.write(query).await?; | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.