Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer committed Nov 24, 2023
1 parent 33d62f4 commit 6e44f94
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 23 deletions.
13 changes: 10 additions & 3 deletions src/bounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,20 @@ mod tests {
let actual = bounding_ellipse(points, tolerance);
assert!(
distance(&expected, &actual) < 1e-3,
"{}", "Expected: {expected}, got: {actual}"
"{}",
"Expected: {expected}, got: {actual}"
);
let extended_actual = Ellipse {a: actual.a+tolerance, b: actual.b+tolerance, ..actual};
let extended_actual = Ellipse {
a: actual.a + tolerance,
b: actual.b + tolerance,
..actual
};
for point in points {
assert!(
extended_actual.contains_vec(point),
"Post-check failed: input point {} must be in expected area: {}", point, extended_actual
"Post-check failed: input point {} must be in expected area: {}",
point,
extended_actual
)
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/chat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{RUNTIME, CONTEXT};
use crate::{CONTEXT, RUNTIME};
use arma_rs::{Context, Group};
use chatgpt::{converse::Conversation, prelude::{ChatGPT}, config::ModelConfigurationBuilder};
use std::{collections::HashMap, env, time::Duration, sync::Arc};
use chatgpt::{config::ModelConfigurationBuilder, converse::Conversation, prelude::ChatGPT};
use std::{collections::HashMap, env, sync::Arc, time::Duration};
use tokio::sync::{Mutex, RwLock};
use tokio::time::sleep;

Expand All @@ -18,13 +18,18 @@ pub fn group() -> Group {

fn init_chat_gpt() -> ChatGPT {
let key = env::var("CHATGPT_KEY").unwrap();
let config = ModelConfigurationBuilder::default().timeout(Duration::from_secs(30)).build().unwrap();
let config = ModelConfigurationBuilder::default()
.timeout(Duration::from_secs(30))
.build()
.unwrap();
ChatGPT::new_with_config(key, config).unwrap()
}

fn init(context: Context, uid: String, prompt: String) {
let mut conversations = CONVERSATIONS.blocking_lock();
if conversations.contains_key(&uid) { return; }
if conversations.contains_key(&uid) {
return;
}

let conversation = CLIENT.new_conversation_directed(prompt);
conversations.insert(uid, Arc::new(Mutex::new(conversation)));
Expand All @@ -39,7 +44,11 @@ fn message(uid: String, message: String) {
return;
};
sleep(Duration::from_millis(5)).await;
_ = context.callback_data("dynops", "systemChat", "The person heard you and is thinking of response");
_ = context.callback_data(
"dynops",
"systemChat",
"The person heard you and is thinking of response",
);

let conversation_store = {
let mut conversations = CONVERSATIONS.lock().await;
Expand Down
17 changes: 12 additions & 5 deletions src/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bounding::bounding_ellipse};
use crate::bounding::bounding_ellipse;
use nalgebra::Vector2;
use std::collections::HashMap;

Expand Down Expand Up @@ -30,10 +30,12 @@ pub fn entrypoint(data: &String) -> Result<String, String> {
))?;
let x: f64 = parts
.0
.parse::<f64>().map_err(|_| format!("Failed to parse value {}", parts.0))?;
.parse::<f64>()
.map_err(|_| format!("Failed to parse value {}", parts.0))?;
let y: f64 = parts
.1
.parse::<f64>().map_err(|_| format!("Failed to parse value {}", parts.1))?;
.parse::<f64>()
.map_err(|_| format!("Failed to parse value {}", parts.1))?;
points.push(Vector2::new(x, y));
}

Expand All @@ -59,14 +61,19 @@ pub fn entrypoint(data: &String) -> Result<String, String> {
_ => {}
}
}
let centers: Vec<String> = clusters.values().map(|cluster_points| bounding_ellipse(cluster_points, 0.1))
let centers: Vec<String> = clusters
.values()
.map(|cluster_points| bounding_ellipse(cluster_points, 0.1))
.map(|area| format_area(&area))
.collect();
Ok(format!("[\n{}\n]", centers.join(",\n")))
}

fn format_area(_area: &crate::shape::Ellipse) -> String {
format!("[{},{},{},{},{}]", _area.x, _area.y, _area.a, _area.b, _area.r)
format!(
"[{},{},{},{},{}]",
_area.x, _area.y, _area.a, _area.b, _area.r
)
}

// https://github.com/lazear/dbscan/blob/master/src/lib.rs
Expand Down
2 changes: 0 additions & 2 deletions src/kdtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl<T: PartialOrd + Copy> KdTree<T> {
}
}


#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -100,7 +99,6 @@ mod tests {
assert_eq!(tree.search(&[7, 8]), Some(&vec![7, 8]));
}


#[test]
fn test_search() {
let mut tree = KdTree::new();
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
mod bounding;
mod chat;
mod cluster;
mod kdtree;
mod shape;
mod chat;

use arma_rs::{arma, Context, Extension};
use tokio::sync::RwLock;
use lazy_static;
use std::result::Result;
use tokio::sync::RwLock;
use uuid::Uuid;
use lazy_static;

lazy_static::lazy_static! {
static ref RUNTIME: tokio::runtime::Runtime = tokio::runtime::Builder::new_multi_thread()
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use image::{ImageFormat, Rgba, RgbaImage};
use std::{fs, env};
use std::path::Path;
use std::{env, fs};

fn main() {
let input = std::env::args().nth(1).expect("No input file given");
Expand Down
6 changes: 5 additions & 1 deletion src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ pub struct Ellipse {

impl fmt::Display for Ellipse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}±{}, {}±{}, α={}]", self.x, self.a, self.y, self.b, self.r)
write!(
f,
"[{}±{}, {}±{}, α={}]",
self.x, self.a, self.y, self.b, self.r
)
}
}

Expand Down
2 changes: 0 additions & 2 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#[cfg(test)]
mod integration {



// fn test_map_data(data: &str) {
// let mut c_chars = vec![0; 1024 * 128];
Expand Down

0 comments on commit 6e44f94

Please sign in to comment.