at least it runs

This commit is contained in:
Bel LaPointe
2023-11-29 05:51:49 -07:00
parent b2df61a235
commit 2fc3fc605b
3 changed files with 221 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ use std::fs::File;
use std::time::{SystemTime, UNIX_EPOCH, Duration};
use std::ops::{Add, Sub};
use clap::Parser;
use std::collections::HashMap;
use chrono::DateTime;
#[derive(Debug, Parser)]
struct Flags {
@@ -48,27 +48,42 @@ fn add(f: &String, x: &Option<String>, tag: &Option<String>) -> Result<(), Strin
Ok(())
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, Clone)]
struct Log {
t: String,
d: u8,
xs: Vec<LogX>,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, Clone)]
struct LogX {
d: u8,
x: String,
xs: Vec<String>,
}
fn log(f: &String, since: &Option<String>) -> Result<(), String> {
let since = parse_time(since)?;
let tsheet = load(&f)?;
let tsheet = tsheet.since(since);
let mut logs = HashMap::new();
for &x in &tsheet.xs {
let tsheet = tsheet.sorted();
let mut result = vec![];
let mut curr = Log{t: "".to_string(), xs: vec![]};
for x in &tsheet.xs {
if curr.t != x.timestamp() {
if curr.xs.len() > 0 {
result.push(curr.clone());
}
curr.xs.truncate(0);
curr.t = x.timestamp();
}
curr.t = x.timestamp();
curr.xs.push(LogX{d: 0, x: x.x.clone()});
}
println!("{:?}", logs);
if curr.xs.len() > 0 {
result.push(curr.clone());
}
println!("{}", serde_yaml::to_string(&result).unwrap());
Err("not impl".to_string())
}
@@ -86,7 +101,7 @@ struct TSheet {
xs: Vec<X>,
}
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Ord, Eq, PartialOrd)]
struct X {
t: i64,
x: String,
@@ -165,12 +180,23 @@ impl TSheet {
fn add(&mut self, x: String, tag: String) {
self.xs.push(new_x(SystemTime::now(), x, tag));
}
fn sorted(&self) -> TSheet {
let mut result = TSheet{xs: self.xs.clone()};
result.xs.sort();
return result;
}
}
impl X {
fn ts(&self) -> SystemTime {
UNIX_EPOCH.add(Duration::from_secs(self.t.try_into().unwrap()))
}
fn timestamp(&self) -> String {
let dt = DateTime::from_timestamp(self.t, 0).unwrap();
dt.format("%Y-%m-%d").to_string()
}
}
fn new_x(t: SystemTime, x: String, tag: String) -> X {