intial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/target
|
||||
Generated
+146
@@ -0,0 +1,146 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "drug_chart"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"piechart",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "piechart"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79730372879e285c066c9289e164f4033ff665a866396dfa478f58f5adcd4089"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.149"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.117"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "drug_chart"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
piechart = "1.0.0"
|
||||
serde_json = "1.0.149"
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
use std::process;
|
||||
use std::error::Error;
|
||||
use piechart::{Chart, Color, Data};
|
||||
use serde_json::Value;
|
||||
use std::fs;
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn fetch_json(file_path: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
// fetch the json from the file as a string and deserialize it into an array
|
||||
let string = fs::read_to_string(file_path)?;
|
||||
Ok(string)
|
||||
}
|
||||
|
||||
fn collect_data(json: &String) -> Result<HashMap<String, f64>, Box<dyn std::error::Error>> {
|
||||
let json_object: Value = serde_json::from_str(&json)?;
|
||||
let mut ingestions = HashMap::new();
|
||||
// ITS NOT STUPID IF IT WORKS ITS NOT STUPID IF IT WORKS ITS NOT STUPID IF IT WORKS ITS NOT STUPID IF IT WORKS ITS NOT STUPID IF IT WORKS
|
||||
for x in 0..=200 {
|
||||
for y in 0..=30 {
|
||||
let substance_name = &json_object["experiences"][x]["ingestions"][y]["substanceName"];
|
||||
let ingested_dose = &json_object["experiences"][x]["ingestions"][y]["dose"];
|
||||
if !substance_name.is_null() {
|
||||
let current_dose: &f64 = ingestions.get(&substance_name.as_str().unwrap().to_string()).unwrap_or(&0.0);
|
||||
ingestions.insert(substance_name.as_str().unwrap().to_string(), current_dose + ingested_dose.as_f64().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ingestions)
|
||||
}
|
||||
|
||||
fn run() -> Result<(), Box< dyn Error>> {
|
||||
let json_deserialized = fetch_json("/home/n33r/journal.json")?;
|
||||
let ingestions = collect_data(&json_deserialized)?;
|
||||
let mut ingestions_iterator = ingestions.iter();
|
||||
let ingestions_length = ingestions.len() as i32;
|
||||
let mut substances = Vec::new();
|
||||
for x in 0..ingestions_length {
|
||||
let substance_amount = ingestions_iterator.next().unwrap();
|
||||
let drug = substance_amount.0;
|
||||
let amount = substance_amount.1;
|
||||
|
||||
substances.push(Data { label: drug.into(), value: *amount as f32, color: Some(Color::Purple.into()), fill: '▪' });
|
||||
}
|
||||
Chart::new()
|
||||
.radius(9)
|
||||
.aspect_ratio(5)
|
||||
.legend(true)
|
||||
.draw(&substances);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = run() {
|
||||
println!("{}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user