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/parser.rs | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 rust_backend/src/pathfinding/parser.rs (limited to 'rust_backend/src/pathfinding/parser.rs') 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