From 987af19ec87c2da96b9a04c70e1b70262bb910ac Mon Sep 17 00:00:00 2001 From: Nicola Belluti Date: Sun, 16 Jun 2024 17:57:32 +0200 Subject: [PATCH] Added a sample main function to get the data --- Cargo.lock | 8 ++++++++ Cargo.toml | 1 + sample-main/Cargo.toml | 8 ++++++++ sample-main/src/main.rs | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 sample-main/Cargo.toml create mode 100644 sample-main/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 7d69cab..6108661 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,6 +145,14 @@ dependencies = [ "serde", ] +[[package]] +name = "sample-main" +version = "0.1.0" +dependencies = [ + "chrono", + "r701", +] + [[package]] name = "serde" version = "1.0.203" diff --git a/Cargo.toml b/Cargo.toml index bf42f15..b822ffb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,4 +2,5 @@ resolver = "2" members = [ "r701", + "sample-main", ] diff --git a/sample-main/Cargo.toml b/sample-main/Cargo.toml new file mode 100644 index 0000000..a8f675b --- /dev/null +++ b/sample-main/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "sample-main" +version = "0.1.0" +edition = "2021" + +[dependencies] +r701 = { path = "../r701" } +chrono = { version = "0.4.38", default-features = false } diff --git a/sample-main/src/main.rs b/sample-main/src/main.rs new file mode 100644 index 0000000..ed9af83 --- /dev/null +++ b/sample-main/src/main.rs @@ -0,0 +1,39 @@ +use chrono::{Local, TimeZone}; +use r701::R701; +use std::collections::HashMap; + +fn main() { + let start = Local.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(); + let end = Local.with_ymd_and_hms(9999, 1, 1, 0, 0, 0).unwrap(); + let mut names = HashMap::new(); + + let mut r701 = R701::connect("127.0.0.1:5005").unwrap(); + + println!("No\tMchn\tEnNo\t\tName\t\tMode\tIOMd\tDateTime\t"); + r701.into_record_iter() + .unwrap() + .take_while(|record| record.datetime >= start) + .skip_while(|record| record.datetime >= end) + .collect::>() + .iter() + .rev() + .enumerate() + .for_each(|(id, record)| { + let name = names.entry(record.employee_id).or_insert_with(|| { + r701.get_name(record.employee_id) + .unwrap() + .unwrap_or(format!("user #{}", record.employee_id)) + }); + + println!( + "{:0>6}\t{}\t{:0>9}\t{: <10}\t{}\t{}\t{}", + id + 1, + 1, + record.employee_id, + name, + 35, + record.clock as u8, + record.datetime.format("%Y/%m/%d %H:%M:%S"), + ); + }); +}