From 2c5b7da8165e3f8b90748e8ced1de0e3e8d52309 Mon Sep 17 00:00:00 2001 From: lazydancer Date: Sun, 22 Dec 2024 17:33:11 -0500 Subject: Initial --- rust_backend/src/pathfinding/graph.rs | 7 +++ rust_backend/src/pathfinding/mod.rs | 15 ++++++ rust_backend/src/pathfinding/models.rs | 86 ++++++++++++++++++++++++++++++++++ rust_backend/src/pathfinding/parser.rs | 46 ++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 rust_backend/src/pathfinding/graph.rs create mode 100644 rust_backend/src/pathfinding/mod.rs create mode 100644 rust_backend/src/pathfinding/models.rs create mode 100644 rust_backend/src/pathfinding/parser.rs (limited to 'rust_backend/src/pathfinding') diff --git a/rust_backend/src/pathfinding/graph.rs b/rust_backend/src/pathfinding/graph.rs new file mode 100644 index 0000000..0352007 --- /dev/null +++ b/rust_backend/src/pathfinding/graph.rs @@ -0,0 +1,7 @@ +use crate::pathfinding::models::{MapNode, Graph}; + +use std::collections::HashMap; + +pub fn generate_graph(stations: &Vec) -> Graph { + HashMap::new() +} \ No newline at end of file diff --git a/rust_backend/src/pathfinding/mod.rs b/rust_backend/src/pathfinding/mod.rs new file mode 100644 index 0000000..32c2831 --- /dev/null +++ b/rust_backend/src/pathfinding/mod.rs @@ -0,0 +1,15 @@ +mod models; +mod parser; +mod graph; +pub use models::{Location, Graph}; + + +use crate::pathfinding::parser::parse_stations; +use crate::pathfinding::graph::generate_graph; + +pub fn build() { + let stations = parse_stations().unwrap(); + let gates_connnections = parse_gate_connections().unwrap() + let graph = generate_graph(&stations, &gates_connnections); + +} diff --git a/rust_backend/src/pathfinding/models.rs b/rust_backend/src/pathfinding/models.rs new file mode 100644 index 0000000..4bbc580 --- /dev/null +++ b/rust_backend/src/pathfinding/models.rs @@ -0,0 +1,86 @@ +use serde::{Deserialize, Deserializer, Serialize}; +use std::str::FromStr; +use std::collections::HashMap; + + +#[derive(Deserialize, Serialize, Clone)] +pub struct Location { + pub solar_system_id: i32, + pub station_id: Option, + pub structure_id: Option, +} + +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct RawNode { + pub itemID: u64, + pub typeID: u64, + pub groupID: u64, + #[serde(deserialize_with = "deserialize_optional_u64")] + pub solarSystemID: Option, + #[serde(deserialize_with = "deserialize_optional_u64")] + pub constellationID: Option, + #[serde(deserialize_with = "deserialize_optional_u64")] + pub regionID: Option, + #[serde(deserialize_with = "deserialize_optional_u64")] + pub orbitID: Option, + pub x: Option, + pub y: Option, + pub z: Option, + #[serde(deserialize_with = "deserialize_optional_f64")] + pub radius: Option, + pub itemName: Option, + #[serde(deserialize_with = "deserialize_optional_f64")] + pub security: Option, +} + + +fn deserialize_optional_u64<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let s: Option = Option::deserialize(deserializer)?; + match s.as_deref() { + Some("None") | Some("") => Ok(None), // Handle "None" and empty strings + Some(str_val) => u64::from_str(str_val) + .map(Some) + .map_err(serde::de::Error::custom), + None => Ok(None), + } +} + +fn deserialize_optional_f64<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let s: Option = Option::deserialize(deserializer)?; + match s.as_deref() { + Some("None") | Some("") => Ok(None), // Handle "None" and empty strings + Some(str_val) => str_val.parse::() + .map(Some) + .map_err(serde::de::Error::custom), + None => Ok(None), + } +} + +#[derive(Debug)] +pub struct MapNode { + pub item_id: u64, + pub is_station: bool, + pub solar_system_id: u64, + pub region_id: u64, + pub x: f64, + pub y: f64, + pub z: f64, + pub name: String, + pub security: f64, +} + +#[derive(Deserialize, Serialize, Clone, Debug)] +pub struct Connection { + stargate_id: u64, + destination_id: u64, +} + + + +pub type Graph = HashMap>; \ No newline at end of file diff --git a/rust_backend/src/pathfinding/parser.rs b/rust_backend/src/pathfinding/parser.rs new file mode 100644 index 0000000..955a448 --- /dev/null +++ b/rust_backend/src/pathfinding/parser.rs @@ -0,0 +1,46 @@ +use std::error::Error; +use std::fs::File; +use csv; + +use crate::pathfinding::models::{RawNode, MapNode}; + +pub fn parse_stations() -> Result, Box> { + let file_path = "../mapDenormalize.csv"; + let file = File::open(file_path)?; + + let mut rdr = csv::Reader::from_reader(file); + + let mut raw_nodes: Vec = Vec::new(); + for result in rdr.deserialize() { + match result { + Ok(node) => raw_nodes.push(node), + Err(e) => println!("Error deserializing record: {}", e), + } + } + + println!("raw nodes: {:?}", raw_nodes.len()); + + let processed_nodes: Vec = raw_nodes.into_iter() + .filter(|node| [15, 10].contains(&node.groupID)) + .map(|node| MapNode { + item_id: node.itemID, + is_station: node.groupID == 15, + solar_system_id: node.solarSystemID.unwrap_or_default(), + region_id: node.regionID.unwrap_or_default(), + x: node.x.unwrap_or_default(), + y: node.y.unwrap_or_default(), + z: node.z.unwrap_or_default(), + name: node.itemName.unwrap_or_default(), + security: node.security.unwrap_or_default(), + }) + .collect(); + + println!("processed nodes: {:?}", processed_nodes.len()); + + + Ok(processed_nodes) +} + +pub fn parse_gate_connections() -> Result, Box> { + unimplemented!(); +} \ No newline at end of file -- cgit v1.3