mirror of
https://github.com/alvierahman90/rabbit.git
synced 2024-12-15 11:01:59 +00:00
create structs to model habit tracking data
This commit is contained in:
parent
c87177a409
commit
e8332ee093
@ -12,6 +12,7 @@ default = ["console_error_panic_hook"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2.84"
|
||||
chrono = { version = "0.4.31", features = [ "clock" ] }
|
||||
|
||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||
# logging them with `console.error`. This is great for development, but requires
|
||||
|
11
src/lib.rs
11
src/lib.rs
@ -1,13 +1,4 @@
|
||||
mod utils;
|
||||
pub mod models;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
fn alert(s: &str);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn greet() {
|
||||
alert("Hello, rabbit!");
|
||||
}
|
||||
|
9
src/models.rs
Normal file
9
src/models.rs
Normal file
@ -0,0 +1,9 @@
|
||||
pub mod category;
|
||||
pub mod series;
|
||||
pub mod series_point;
|
||||
pub mod series_type;
|
||||
|
||||
pub use category::*;
|
||||
pub use series::*;
|
||||
pub use series_point::*;
|
||||
pub use series_type::*;
|
22
src/models/category.rs
Normal file
22
src/models/category.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use crate::models::Series;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Category {
|
||||
id: i32,
|
||||
name: String,
|
||||
series: Vec<Series>,
|
||||
}
|
||||
|
||||
impl Category {
|
||||
pub fn new(id: i32, name: String) -> Category {
|
||||
Category {
|
||||
id,
|
||||
name,
|
||||
series: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_series(&mut self, series: Series) {
|
||||
self.series.push(series);
|
||||
}
|
||||
}
|
27
src/models/series.rs
Normal file
27
src/models/series.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use chrono;
|
||||
use super::series_point::SeriesPoint;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Series {
|
||||
id: i32,
|
||||
name: String,
|
||||
repeat: chrono::Duration,
|
||||
good: bool,
|
||||
points: Vec<SeriesPoint>,
|
||||
}
|
||||
|
||||
impl Series {
|
||||
pub fn new(id: i32, name: String, repeat: chrono::Duration, good: bool) -> Series {
|
||||
Series {
|
||||
id,
|
||||
name,
|
||||
repeat,
|
||||
good,
|
||||
points: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_point(&mut self, point: SeriesPoint) {
|
||||
self.points.push(point);
|
||||
}
|
||||
}
|
19
src/models/series_point.rs
Normal file
19
src/models/series_point.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use chrono;
|
||||
use super::series_type::SeriesType;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SeriesPoint {
|
||||
id: i32,
|
||||
timestamp: chrono::NaiveDateTime,
|
||||
value: SeriesType,
|
||||
}
|
||||
|
||||
impl SeriesPoint {
|
||||
pub fn new(id: i32, timestamp: chrono::NaiveDateTime, value: SeriesType) -> SeriesPoint {
|
||||
SeriesPoint {
|
||||
id,
|
||||
timestamp,
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
7
src/models/series_type.rs
Normal file
7
src/models/series_type.rs
Normal file
@ -0,0 +1,7 @@
|
||||
#[derive(Debug)]
|
||||
pub enum SeriesType {
|
||||
Bool(bool),
|
||||
Count(u32),
|
||||
Signed(i32),
|
||||
Float(f32),
|
||||
}
|
Loading…
Reference in New Issue
Block a user