Added a sample main function to get the data

This commit is contained in:
Nicola Belluti 2024-06-16 17:57:32 +02:00
parent 35e75745db
commit 987af19ec8
4 changed files with 56 additions and 0 deletions

8
Cargo.lock generated
View File

@ -145,6 +145,14 @@ dependencies = [
"serde",
]
[[package]]
name = "sample-main"
version = "0.1.0"
dependencies = [
"chrono",
"r701",
]
[[package]]
name = "serde"
version = "1.0.203"

View File

@ -2,4 +2,5 @@
resolver = "2"
members = [
"r701",
"sample-main",
]

8
sample-main/Cargo.toml Normal file
View File

@ -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 }

39
sample-main/src/main.rs Normal file
View File

@ -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::<Vec<_>>()
.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"),
);
});
}