Skip to content

Commit

Permalink
refactor(cli): ♻️ add diesel orm
Browse files Browse the repository at this point in the history
  • Loading branch information
keinsell committed Jun 20, 2024
1 parent c7938e2 commit 09879b5
Show file tree
Hide file tree
Showing 31 changed files with 4,507 additions and 60 deletions.
1 change: 1 addition & 0 deletions .idea/neuronek.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 136 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ members = [
"db/rust-seaorm-client",
"apps/cli",
"apps/rust-server"
]
, "db/rust-diesel-client"]
resolver = "2"
2 changes: 1 addition & 1 deletion apps/cli/src/cli/ingestion/create_ingestion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use structopt::StructOpt;
use db::sea_orm::DatabaseConnection;
use structopt::StructOpt;

use crate::core::route_of_administration::RouteOfAdministrationClassification;
use crate::ingestion_analyzer::analyze_future_ingestion;
Expand Down
4 changes: 3 additions & 1 deletion apps/cli/src/cli/ingestion/delete_ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub struct DeleteIngestion {
}

pub async fn delete_ingestion(db: &DatabaseConnection, ingestion_id: i32) {
let res = db::ingestion::Entity::delete_by_id(ingestion_id).exec(db).await;
let res = db::ingestion::Entity::delete_by_id(ingestion_id)
.exec(db)
.await;
let delete_response = res.expect("Error deleting ingestion");

assert_eq!(delete_response.rows_affected, 1);
Expand Down
5 changes: 2 additions & 3 deletions apps/cli/src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use structopt::StructOpt;
use crate::cli::dashboard::handle_show_dashboard;
use crate::cli::ingestion::create_ingestion::handle_create_ingestion;
use crate::cli::ingestion::delete_ingestion::delete_ingestion;
use crate::cli::ingestion::IngestionCommand;
use crate::cli::ingestion::plan_ingestion::handle_plan_ingestion;
use crate::cli::ingestion::IngestionCommand;
use crate::cli::substance::list_substances::list_substances;
use crate::orm;
use crate::orm::migrate_database;
Expand Down Expand Up @@ -59,8 +59,7 @@ enum DataManagementCommand {

#[derive(StructOpt, Debug)]
#[structopt(name = "dashboard")]
struct DashboardCommand {
}
struct DashboardCommand {}

pub async fn cli() {
// Initialize panic hook
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod bin;
mod dashboard;
pub mod ingestion;
pub mod main;
mod substance;
mod dashboard;
4 changes: 1 addition & 3 deletions apps/cli/src/core/dosage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub enum DosageRange {
Inclusive(Range<Dosage>),
}


impl DosageRange {
pub fn contains(&self, mass: Dosage) -> bool {
match self {
Expand All @@ -68,7 +67,6 @@ impl DosageRange {
}
}


pub fn test_measurements() {
for power in -12..12 {
let val: f64 = 123.456 * (10f64.powf(f64::from(power)));
Expand Down Expand Up @@ -101,4 +99,4 @@ pub struct RouteOfAdministrationDosage {
pub route_of_administration_id: String,
pub dosage_classification: DosageClassification,
pub dosage_range: DosageRange,
}
}
4 changes: 2 additions & 2 deletions apps/cli/src/core/mass.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::core::dosage::Dosage;
use std::num::ParseFloatError;
use std::str::FromStr;
use crate::core::dosage::Dosage;

pub type Mass = Dosage;

pub fn deserialize_dosage(mass_str: &str) -> Result<Mass, ParseFloatError> {
return Dosage::from_str(mass_str);
return Dosage::from_str(mass_str);
}
2 changes: 1 addition & 1 deletion apps/cli/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod dosage;
pub mod ingestion;
pub mod mass;
pub mod phase;
pub mod route_of_administration;
pub mod dosage;
pub mod substance;
6 changes: 4 additions & 2 deletions apps/cli/src/core/phase.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use std::ops::Range;
use std::str::FromStr;
use std::time::Duration;
use serde::{Deserialize, Serialize};
use tabled::Tabled;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash, PartialOrd, Ord, Copy, Tabled)]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash, PartialOrd, Ord, Copy, Tabled,
)]
#[serde(rename_all = "snake_case")]
pub enum PhaseClassification {
Onset,
Expand Down
10 changes: 5 additions & 5 deletions apps/cli/src/core/route_of_administration.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::core::dosage::{Dosage, DosageClassification, RouteOfAdministrationDosage};
use crate::core::phase::{Phase, PhaseClassification};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt::Display;
use std::str::FromStr;
use serde::{Deserialize, Serialize};
use strsim::normalized_levenshtein;
use crate::core::phase::{Phase, PhaseClassification};
use crate::core::dosage::{Dosage, DosageClassification, RouteOfAdministrationDosage};

#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Eq, Hash)]
#[serde(rename_all = "snake_case")]
Expand Down Expand Up @@ -93,7 +93,7 @@ impl From<RouteOfAdministrationClassification> for String {
RouteOfAdministrationClassification::Rectal => String::from("rectal"),
RouteOfAdministrationClassification::Smoked => String::from("smoked"),
RouteOfAdministrationClassification::Sublingual => String::from("sublingual"),
RouteOfAdministrationClassification::Transdermal => String::from("transdermal")
RouteOfAdministrationClassification::Transdermal => String::from("transdermal"),
}
}
}
Expand Down Expand Up @@ -127,4 +127,4 @@ pub fn get_dosage_classification_by_mass_and_route_of_administration(
}
}
Err("No classification found for the given mass and route of administration")
}
}
12 changes: 6 additions & 6 deletions apps/cli/src/ingestion_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt::{Debug, Display};
use std::time::Duration;

use chrono::{DateTime, Local, TimeZone};
use chrono_english::{Dialect, parse_date_string};
use chrono_english::{parse_date_string, Dialect};
use chrono_humanize::HumanTime;
use log::{debug, error};
use measurements::Measurement;
Expand Down Expand Up @@ -232,16 +232,16 @@ pub fn pretty_print_ingestion_analysis(ingestion_analysis: &IngestionAnalysis) {
.to_string()
));
markdown.push_str(&format!("{}", "-".repeat(40) + "\n"));
markdown.push_str(&format!(
"🧪 {}\n",
ingestion_analysis.substance_name
));
markdown.push_str(&format!("🧪 {}\n", ingestion_analysis.substance_name));
markdown.push_str(&format!("{}", "-".repeat(3) + "\n"));
markdown.push_str(&format!(
"🥤 Route of Administration: **{:?}**\n",
ingestion_analysis.route_of_administration_classification
));
markdown.push_str(&format!("🧮 Dosage: **{0:.0}**\n", ingestion_analysis.dosage));
markdown.push_str(&format!(
"🧮 Dosage: **{0:.0}**\n",
ingestion_analysis.dosage
));
markdown.push_str(&format!(
"🧮 Dosage Classification: **{:?}**\n",
ingestion_analysis.dosage_classification
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
mod cli;
mod core;
mod ingestion_analyzer;
mod ingestion_intelligence;
mod orm;
mod service;
mod ingestion_intelligence;

fn main() {
cli::bin::main()
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/orm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use log::debug;
use xdg::BaseDirectories;

use db::{ConnectionTrait, DbErr, IntoSchemaManagerConnection, Migrator, MigratorTrait};
use db::sea_orm::{Database, DatabaseConnection, DbBackend};
use db::{ConnectionTrait, DbErr, IntoSchemaManagerConnection, Migrator, MigratorTrait};

use crate::orm;

Expand Down
Loading

0 comments on commit 09879b5

Please sign in to comment.