major refactor

This commit is contained in:
xqtc 2024-10-26 16:31:10 +02:00
parent 86736b77ab
commit a7a6bb36ed
Signed by: xqtc
GPG key ID: 2C064D095926D9D1
9 changed files with 3943 additions and 410 deletions

File diff suppressed because it is too large Load diff

1
client/src/drugs/mod.rs Normal file
View file

@ -0,0 +1 @@
mod drug_schema;

View file

@ -17,12 +17,12 @@ mod util;
mod drugs_parser; mod drugs_parser;
mod substances_new; mod drugs;
mod ingestions; // mod ingestions;
mod ingestions_util; // mod ingestions_util;
mod substance_util; // mod substance_util;
mod substances; // mod substances;
// mod drug_parser; // mod drug_parser;
@ -77,19 +77,19 @@ fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
fn main() { fn main() {
drugs_parser::parse(); drugs_parser::parse();
ensure_files(); // ensure_files();
let cli = Cli::parse(); let cli = Cli::parse();
match cli.command { match cli.command {
Some(Commands::AddIngestion) => ingestions::add_ingestion(), // Some(Commands::AddIngestion) => ingestions::add_ingestion(),
Some(Commands::EditIngestion) => ingestions::edit_ingestion().unwrap(), // Some(Commands::EditIngestion) => ingestions::edit_ingestion().unwrap(),
Some(Commands::ListIngestions) => ingestions::list_ingestions().unwrap(), // Some(Commands::ListIngestions) => ingestions::list_ingestions().unwrap(),
Some(Commands::RemoveIngestion) => {} // Some(Commands::RemoveIngestion) => {}
Some(Commands::AddSubstance) => substances::add_substance().unwrap(), // Some(Commands::AddSubstance) => substances::add_substance().unwrap(),
Some(Commands::EditSubstance) => substances::edit_substance().unwrap(), // Some(Commands::EditSubstance) => substances::edit_substance().unwrap(),
Some(Commands::ListSubstances) => substances::list_substances().unwrap(), // Some(Commands::ListSubstances) => substances::list_substances().unwrap(),
Some(Commands::RemoveSubstance) => substances::remove_substance().unwrap(), // Some(Commands::RemoveSubstance) => substances::remove_substance().unwrap(),
Some(Commands::GenerateCompletions { shell }) => { Some(Commands::GenerateCompletions { shell }) => {
let mut cmd = Cli::command(); let mut cmd = Cli::command();
eprintln!("Generating completion file for {shell}..."); eprintln!("Generating completion file for {shell}...");
@ -103,45 +103,46 @@ fn main() {
} }
None => {} None => {}
_ => {}
} }
} }
fn ensure_files() { // fn ensure_files() {
if !util::path_exists(LOCAL_PATH.to_string()) { // if !util::path_exists(LOCAL_PATH.to_string()) {
match std::fs::create_dir(LOCAL_PATH.to_string()) { // match std::fs::create_dir(LOCAL_PATH.to_string()) {
Ok(_) => {} // Ok(_) => {}
Err(e) => { // Err(e) => {
eprintln!("Could not create data directory with error: {:?}", e); // eprintln!("Could not create data directory with error: {:?}", e);
std::process::exit(1); // std::process::exit(1);
} // }
} // }
} // }
if !util::path_exists(SUBSTANCES_FILE.to_string()) { // if !util::path_exists(SUBSTANCES_FILE.to_string()) {
match substance_util::create_substances_file() { // match substance_util::create_substances_file() {
Ok(_) => { // Ok(_) => {
println!( // println!(
"Created substances file at {:?}", // "Created substances file at {:?}",
SUBSTANCES_FILE.to_string() // SUBSTANCES_FILE.to_string()
) // )
} // }
Err(_) => { // Err(_) => {
eprintln!("Could not create substances file"); // eprintln!("Could not create substances file");
panic!() // panic!()
} // }
}; // };
} // }
if !util::path_exists(INGESTIONS_FILE.to_string()) { // if !util::path_exists(INGESTIONS_FILE.to_string()) {
match ingestions::create_ingestions_file() { // match ingestions::create_ingestions_file() {
Ok(_) => { // Ok(_) => {
println!( // println!(
"Created ingestions file at {:?}", // "Created ingestions file at {:?}",
INGESTIONS_FILE.to_string() // INGESTIONS_FILE.to_string()
) // )
} // }
Err(_) => { // Err(_) => {
eprintln!("Could not create substances file"); // eprintln!("Could not create substances file");
panic!() // panic!()
} // }
}; // };
} // }
} // }

View file

@ -1,356 +0,0 @@
// export type Drug = {
// aliases?: string[];
// categories?: Category[];
// formatted_aftereffects?: Duration;
// formatted_dose?: Dose;
// formatted_duration?: Duration;
// formatted_effects?: string[];
// formatted_onset?: Duration;
// links?: Links;
// name: string;
// pretty_name: string;
// properties: Properties;
// pweffects?: { [key: string]: string };
// dose_note?: string;
// sources?: Sources;
// combos?: Interactions;
// };
//
// export enum Category {
// Barbiturate = "barbiturate",
// Benzodiazepine = "benzodiazepine",
// Common = "common",
// Deliriant = "deliriant",
// Depressant = "depressant",
// Dissociative = "dissociative",
// Empathogen = "empathogen",
// HabitForming = "habit-forming",
// Inactive = "inactive",
// Nootropic = "nootropic",
// Opioid = "opioid",
// Psychedelic = "psychedelic",
// ResearchChemical = "research-chemical",
// Ssri = "ssri",
// Stimulant = "stimulant",
// Supplement = "supplement",
// Tentative = "tentative",
// }
//
// export type Duration = {
// _unit: Unit;
// value?: string;
// insufflated?: string;
// oral?: string;
// rectal?: string;
// vapourized?: string;
// smoked?: string;
// Oral_ER?: string;
// Oral_IR?: string;
// Oral_MAOI?: string;
// intramuscular?: string;
// intravenous?: string;
// metabolites?: string;
// parent?: string;
// oralMAOI?: string;
// buccal?: string;
// transdermal?: string;
// sublingual?: string;
// Insufflated_IR?: string;
// Insufflated_XR?: string;
// };
//
// export type Dose = {
// oral?: Dosage;
// insufflated?: Dosage;
// rectal?: Dosage;
// vapourized?: Dosage;
// intravenous?: Dosage;
// smoked?: Dosage;
// sublingual?: Dosage;
// buccal?: Dosage;
// intramuscular?: Dosage;
// transdermal?: Dosage;
// hbwr?: Dosage;
// Morning_Glory?: Dosage;
// dried?: Dosage;
// fresh?: Dosage;
// "Insufflated(Pure)"?: Dosage;
// "Oral(Benzedrex)"?: Dosage;
// "Oral(Pure)"?: Dosage;
// dry?: Dosage;
// wet?: Dosage;
// };
//
// export type Dosage = {
// common?: string;
// light?: string;
// strong?: string;
// threshold?: string;
// heavy?: string;
// dangerous?: string;
// fatal?: string;
// note?: string;
// };
//
// export type Links = {
// experiences: string;
// pihkal?: string;
// tihkal?: string;
// };
//
// export type Properties = {
// "after-effects"?: string;
// aliases?: string[];
// avoid?: string;
// categories?: Category[];
// dose?: string;
// duration?: string;
// "half-life"?: string;
// onset?: string;
// summary?: string;
// "test-kits"?: string;
// experiences?: string;
// warning?: string;
// marquis?: string;
// effects?: string;
// risks?: string;
// comeup?: string;
// note?: string;
// detection?: string;
// wiki?: string;
// mdma?: string;
// tolerance?: string;
// bioavailability?: string;
// dose_to_diazepam?: string;
// "adverse-effects"?: string;
// chemistry?: string;
// contraindications?: string;
// legal?: string;
// "overdose-symptoms"?: string;
// pharmacokinetics?: string;
// pharmacology?: string;
// obtain?: string;
// pharmacodynamics?: string;
// "side-effects"?: string;
// molecule?: string;
// vaporization?: string;
// calculator?: string;
// chart?: string;
// oral?: string;
// "general-advice"?: string;
// potentiators?: string;
// };
//
// export interface Combos {
// "2c-t-x": Interactions;
// "2c-x": Interactions;
// "5-meo-xxt": Interactions;
// alcohol: Interactions;
// amphetamines: Interactions;
// amt: Interactions;
// benzodiazepines: Interactions;
// caffeine: Interactions;
// cannabis: Interactions;
// cocaine: Interactions;
// diphenhydramine: Interactions;
// dextromethorphan: Interactions;
// dmt: Interactions;
// dox: Interactions;
// "ghb/gbl": Interactions;
// ketamine: Interactions;
// lithium: Interactions;
// lsd: Interactions;
// maois: Interactions;
// mdma: Interactions;
// mephedrone: Interactions;
// mescaline: Interactions;
// mushrooms: Interactions;
// mxe: Interactions;
// nbomes: Interactions;
// nitrous: Interactions;
// opioids: Interactions;
// pcp: Interactions;
// ssris: Interactions;
// tramadol: Interactions;
// }
//
// export interface Interactions {
// "2c-t-x"?: ComboData;
// "2c-x"?: ComboData;
// "5-meo-xxt"?: ComboData;
// alcohol?: ComboData;
// amphetamines?: ComboData;
// amt?: ComboData;
// benzodiazepines?: ComboData;
// caffeine?: ComboData;
// cannabis?: ComboData;
// cocaine?: ComboData;
// diphenhydramine?: ComboData;
// dextromethorphan?: ComboData;
// dmt?: ComboData;
// dox?: ComboData;
// "ghb/gbl"?: ComboData;
// lithium?: ComboData;
// ketamine?: ComboData;
// lsd?: ComboData;
// maois?: ComboData;
// mdma?: ComboData;
// mephedrone?: ComboData;
// mescaline?: ComboData;
// mushrooms?: ComboData;
// mxe?: ComboData;
// nbomes?: ComboData;
// nitrous?: ComboData;
// opioids?: ComboData;
// pcp?: ComboData;
// ssris?: ComboData;
// tramadol?: ComboData;
// }
//
// export interface ComboData {
// note?: string;
// sources?: {
// author: string;
// title: string;
// url: string;
// }[];
// status: Status;
// }
//
// export enum Status {
// Caution = "Caution",
// Dangerous = "Dangerous",
// LowRiskDecrease = "Low Risk & Decrease",
// LowRiskNoSynergy = "Low Risk & No Synergy",
// LowRiskSynergy = "Low Risk & Synergy",
// Self = "Self",
// Unsafe = "Unsafe",
// }
//
// export type ComboDefinitions = {
// status: Status;
// emoji: string;
// color: string;
// definition: string;
// thumbnail: string;
// }
//
// export enum Unit {
// Hours = "hours",
// Minutes = "minutes",
// }
//
// export type Sources = {
// general?: string[];
// dose?: string[];
// duration?: string[];
// bioavailability?: string[];
// legality?: string[];
// onset?: string[];
// };
pub struct Dug {
aliases: Option<Vec<String>>,
categories: Option<Vec<Category>>,
formatted_aftereffects: Option<Duration>,
formatted_dose: Option<Dose>,
formatted_duration: Option<Duration>,
formatted_effects: Option<Vec<String>>,
formatted_onset: Option<Duration>,
links: Option<Links>,
name: String,
pretty_name: String,
properties: Properties,
pweffects: Option<(String, Strin)>,
dose_note: Option<String>,
sources: Option<Sources>,
combos: Option<Interactions>,
}
pub enum Category {
Barbiturate,
Benzodiazepine,
Common,
Deliriant,
Depressant,
Dissociative,
Empathogen,
HabitForming,
Inactive,
Nootropic,
Opioid,
Psychedelic,
ResearchChemical,
Ssri,
Stimulant,
Supplement,
Tentative,
}
pub struct Duration {
unit: Unit,
value: Option<String>,
insufflated: Option<String>,
oral: Option<String>,
rectal: Option<String>,
vapourized: Option<String>,
smoked: Option<String>,
oral_ER: Option<String>,
oral_IR: Option<String>,
oral_MAOI: Option<String>,
intramuscular: Option<String>,
intravenous: Option<String>,
metabolites: Option<String>,
parent: Option<String>,
oralMAOI: Option<String>,
buccal: Option<String>,
transdermal: Option<String>,
sublingual: Option<String>,
Insufflated_IR: Option<String>,
Insufflated_XR: Option<String>,
}
pub struct Dose {
oral: Option<Dosage>,
insufflated: Option<Dosage>,
rectal: Option<Dosage>,
vapourized: Option<Dosage>,
intravenous: Option<Dosage>,
smoked: Option<Dosage>,
sublingual: Option<Dosage>,
buccal: Option<Dosage>,
intramuscular: Option<Dosage>,
transdermal: Option<Dosage>,
hbwr: Option<Dosage>,
morning_glory: Option<Dosage>,
dried: Option<Dosage>,
fresh: Option<Dosage>,
insufflated_pure: Option<Dosage>,
oral_benzedrex: Option<Dosage>,
oral_pure: Option<Dosage>,
dry: Option<Dosage>,
wet: Option<Dosage>,
}
pub struct Dosage {
common: Option<String>,
light: Option<String>,
strong: Option<String>,
threshold: Option<String>,
heavy: Option<String>,
dangerous: Option<String>,
fatal: Option<String>,
note: Option<String>,
}
pub struct Links {
experiences: String,
pihkal: Option<String>,
tihkal: Option<String>,
}
pub struct Properties {
after_effects: Option<String>,
aliases: Option<Vec<String>>,
avoid: Option<String>,
}

View file

@ -1,6 +1,6 @@
use tonic; use tonic;
fn main() { fn main() {
let addr = "[::1]:50051".parse(); // let addr = "[::1]:50051".parse();
println!("Hello, world!"); println!("Hello, world!");
} }