mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2026-04-30 18:49:09 +00:00
implemented IDStore
This commit is contained in:
@@ -1 +1,67 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
struct TellyID (String);
|
||||
|
||||
struct AttendanceDay {
|
||||
date: String,
|
||||
ids: Vec<TellyID>,
|
||||
}
|
||||
|
||||
struct IDStore {
|
||||
days: HashMap<String,AttendanceDay>
|
||||
}
|
||||
|
||||
impl IDStore {
|
||||
fn new() -> Self {
|
||||
IDStore{
|
||||
days: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn add_id(&mut self, id: TellyID){
|
||||
let day = self.get_current_day();
|
||||
|
||||
day.add_id(id);
|
||||
|
||||
self.clean_map();
|
||||
}
|
||||
|
||||
fn get_current_day(&mut self) -> &mut AttendanceDay {
|
||||
let current_day = get_day_str();
|
||||
|
||||
if self.days.contains_key(¤t_day) {
|
||||
return self.days.get_mut(¤t_day).unwrap();
|
||||
}
|
||||
|
||||
self.days.insert(current_day.clone(), AttendanceDay::new(¤t_day.clone()));
|
||||
|
||||
self.days.get_mut(¤t_day.clone()).unwrap()
|
||||
}
|
||||
|
||||
fn clean_map(&mut self){
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl AttendanceDay {
|
||||
fn new(day: &str) -> Self{
|
||||
Self{
|
||||
date: day.to_owned(),
|
||||
ids: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn add_id(&mut self, id: TellyID){
|
||||
if self.ids.contains(&id) {
|
||||
return
|
||||
}
|
||||
|
||||
self.ids.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_day_str() -> String {
|
||||
let now = chrono::offset::Local::now();
|
||||
now.format("%Y-%m-%d").to_string()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use pm3::run_pm3;
|
||||
|
||||
mod parser;
|
||||
mod pm3;
|
||||
mod id_store;
|
||||
|
||||
fn main() {
|
||||
pm3::RunPm3().unwrap();
|
||||
run_pm3().unwrap();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use regex::Regex;
|
||||
|
||||
pub fn ParseLine(line: &str) -> Option<String> {
|
||||
pub fn parse_line(line: &str) -> Option<String> {
|
||||
let regex = Regex::new(r"(?m)^\[\+\] UID.... (.*)$").unwrap();
|
||||
let result = regex.captures(line);
|
||||
|
||||
|
||||
10
src/pm3.rs
10
src/pm3.rs
@@ -2,7 +2,7 @@ use std::error::Error;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
pub fn RunPm3() -> Result<(), Box<dyn Error>> {
|
||||
pub fn run_pm3() -> Result<(), Box<dyn Error>> {
|
||||
let mut cmd = Command::new("stdbuf")
|
||||
.arg("-oL")
|
||||
.arg("pm3")
|
||||
@@ -17,7 +17,7 @@ pub fn RunPm3() -> Result<(), Box<dyn Error>> {
|
||||
for line_result in reader.lines() {
|
||||
match line_result {
|
||||
Ok(line) => {
|
||||
let parse_result = super::parser::ParseLine(&line);
|
||||
let parse_result = super::parser::parse_line(&line);
|
||||
if let Some(uid) = parse_result {
|
||||
println!("UID: {}",uid);
|
||||
}
|
||||
@@ -30,5 +30,9 @@ pub fn RunPm3() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let status = cmd.wait().expect("Failed to wait on child");
|
||||
|
||||
Ok(())
|
||||
if status.success() {
|
||||
Ok(())
|
||||
}else {
|
||||
Err("pm3 had non zero exit code".into())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user