Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions heatmap-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bincode = "2.0.1"
chrono = "0.4.38"
leptos = "0.6.12"
serde = "1.0.204"
Expand Down
7 changes: 4 additions & 3 deletions heatmap-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};

pub trait ToPartialString {
Expand Down Expand Up @@ -76,16 +77,16 @@ pub struct HeatmapQuery {

// Server sends this back to client after a query,
// contains the granule data
#[derive(Deserialize, Serialize, Debug, PartialEq)]
#[derive(Decode, Encode, Deserialize, Serialize, Debug, PartialEq)]
pub struct HeatmapResponse {
pub data: HeatmapData,
}

#[derive(Deserialize, Serialize, Debug, PartialEq)]
#[derive(Encode, Decode, Deserialize, Serialize, Debug, PartialEq)]
pub struct HeatmapData {
pub data: InteriorData,
}
#[derive(Deserialize, Serialize, Debug, PartialEq)]
#[derive(Encode, Decode, Deserialize, Serialize, Debug, PartialEq)]
pub struct InteriorData {
pub length: i32,
pub positions: Vec<Vec<(f64, f64)>>,
Expand Down
1 change: 1 addition & 0 deletions heatmap-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ png = "0.17.13"
urlencoding = "2.1.3"
base64 = "0.22.1"
text-to-png = "0.2.0"
bincode = "2.0.1"

[lints.clippy]
unwrap_used = "warn"
12 changes: 6 additions & 6 deletions heatmap-client/src/canvas/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl ApplicationHandler<UserMessage<'static>> for App<'_> {
self.exiting(event_loop);
}

Err(e) => eprintln!("{:?}", e),
Err(e) => eprintln!("{e:?}",),
}
}

Expand Down Expand Up @@ -149,7 +149,7 @@ impl ApplicationHandler<UserMessage<'static>> for App<'_> {
web_sys::console::log_1(&"Assign state values in application handler...".into());

self.state = State {
render_context: Some(render_context),
render_context: Some(*render_context),
window: self.state.window.clone(),
init_stage: InitStage::Complete,
geometry: None,
Expand Down Expand Up @@ -256,7 +256,7 @@ impl ApplicationHandler<UserMessage<'static>> for App<'_> {
}
}

web_sys::console::log_1(&format!("Max: {:?}", max).into());
web_sys::console::log_1(&format!("Max: {max:?}").into());

// We now update the uniform buffer with our max weight
// so that we can read the max value in the colormap render pass
Expand Down Expand Up @@ -314,7 +314,7 @@ impl ApplicationHandler<UserMessage<'static>> for App<'_> {
.base64_png = Some(base64_encoded_png.clone());
}

web_sys::console::log_1(&format!("PNG Bytes: {:X?}", base64_encoded_png).into());
web_sys::console::log_1(&format!("PNG Bytes: {base64_encoded_png:X?}").into());

// We dynamically generate this anchor element to download the generated png, it is removed after it goes out of scope
{
Expand All @@ -339,9 +339,9 @@ impl ApplicationHandler<UserMessage<'static>> for App<'_> {
}
}
}
// All user events that can be sent to the event loop
/// All user events that can be sent to the event loop
pub enum UserMessage<'a> {
StateMessage(RenderContext<'a>),
StateMessage(Box<RenderContext<'a>>),
IncomingData(Vec<BufferStorage>, Vec<BufferStorage>),
MaxWeightMapped,
ExportMapped,
Expand Down
4 changes: 2 additions & 2 deletions heatmap-client/src/canvas/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn gen_lod_layers(
render_context
.device
.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some(&(format!("{:?} LOD {:?} Vertex Buffer", label, i))),
label: Some(&(format!("{label:?} LOD {i:?} Vertex Buffer"))),
contents: bytemuck::cast_slice(layer.vertices.as_slice()),
usage: wgpu::BufferUsages::VERTEX,
});
Expand All @@ -111,7 +111,7 @@ fn gen_lod_layers(
render_context
.device
.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some(&(format!("{:?} LOD {:?} Index Buffer", label, i))),
label: Some(&(format!("{label:?} LOD {i:?} Index Buffer"))),
contents: bytemuck::cast_slice(layer.indices.as_slice()),
usage: wgpu::BufferUsages::INDEX,
});
Expand Down
6 changes: 2 additions & 4 deletions heatmap-client/src/canvas/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn generate_heatmap_image(render_context: &mut RenderContext, filter: Filter
color_data.push(f32::from_le_bytes([*raw[0], *raw[1], *raw[2], *raw[3]]));
}

web_sys::console::log_1(&format!("Freshley decoded: {:?}", color_data).into());
web_sys::console::log_1(&format!("Freshley decoded: {color_data:?}").into());

// Convert the raw image data into an ImageBuffer that can be saved, must use copy texture width here,
// Copy Texture is 256 byte aligned so copy_texture.width() is larger than displayed size and so
Expand Down Expand Up @@ -168,9 +168,7 @@ pub fn generate_export_image(
last_upper = upper;
layer += 1;

web_sys::console::log_1(
&format!("Upper: {:?}\nRunning Total: {:?}", upper, last_upper).into(),
);
web_sys::console::log_1(&format!("Upper: {upper:?}\nRunning Total: {last_upper:?}").into());
}

// Last range in legend, formatting is unique so it cant be done in the loop
Expand Down
2 changes: 1 addition & 1 deletion heatmap-client/src/canvas/render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub async fn generate_render_context(
web_sys::console::log_1(&"Done Generating State".into());
// Because this is a wasm application we cannot block on async calls so we instead send a message
// back to the application handler when this function completes
let _ = event_loop_proxy.send_event(UserMessage::StateMessage(message));
let _ = event_loop_proxy.send_event(UserMessage::StateMessage(Box::new(message)));
}

/// Contains a texture and buffer used to map a texture onto the CPU
Expand Down
2 changes: 1 addition & 1 deletion heatmap-client/src/canvas/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl State<'_> {
render_context.export_texture_context =
generate_export_texture(&render_context.device, new_size);

web_sys::console::log_1(&format!("New Size: {:?}", new_size).into());
web_sys::console::log_1(&format!("New Size: {new_size:?}").into());
}
}

Expand Down
36 changes: 16 additions & 20 deletions heatmap-client/src/ingest/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ use heatmap_api::{HeatmapData, OutlineResponse};
pub async fn request(filter: heatmap_api::Filter) -> (HeatmapData, OutlineResponse) {
let client = reqwest::Client::new();

// Send a POST request to the service with the filter as a json payload
let data = client
.post("http://localhost:8000/heatmap") // TODO, some configuration mechanism for this
.json(&heatmap_api::HeatmapQuery { filter })
.send()
.await
.expect("ERROR: Failed to recive data from post request");

// Deserialize response into json string
let str = data
.text()
.await
.expect("ERROR: Failed to deserialize Response into json str");

web_sys::console::log_2(&"Data text: ".into(), &format!("{:?}", str).into());

// Convert json string into a HeatmapData struct
let json_data: heatmap_api::HeatmapData =
serde_json::from_str(&str).expect("ERROR: Failed to deserialized json data");
// Get the granule data from the service
let heatmap_data: HeatmapData = bincode::decode_from_slice(
&client
.post("http://localhost:8000/heatmap") // TODO, some configuration mechanism for this
.json(&heatmap_api::HeatmapQuery { filter })
.send()
.await
.expect("ERROR: Failed to recive data from post request")
.bytes()
.await
.expect("ERROR: Failed to convert response into Bytes"),
bincode::config::standard(),
)
.expect("ERROR: Failed to deserialized json data")
.0;

// Get the outline data from the service
// *** This should be broken out into its own function so we only get and mesh the world outline once ***
Expand All @@ -40,5 +36,5 @@ pub async fn request(filter: heatmap_api::Filter) -> (HeatmapData, OutlineRespon

// Deserialize the json into a HeatmapData struct
web_sys::console::log_1(&"Data succesfully deserialized".into());
(json_data, outline_data)
(heatmap_data, outline_data)
}
1 change: 1 addition & 0 deletions heatmap-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ serde_with = "2.0.0"
heatmap-api = { path = "../heatmap-api" }
rust-embed = "8.5.0"
rayon = "1.10.0"
bincode = "2.0.1"
3 changes: 2 additions & 1 deletion heatmap-service/src/heatmap_data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};

use crate::granule::Granule;

#[derive(Deserialize, Serialize, Debug, PartialEq)]
#[derive(Serialize, Deserialize, Decode, Encode, Debug, PartialEq)]
pub struct HeatmapData {
pub length: i32,
pub positions: Vec<Vec<(f64, f64)>>,
Expand Down
3 changes: 2 additions & 1 deletion heatmap-service/src/heatmap_response.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use bincode::{Decode, Encode};
use chrono::NaiveDate;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};

use crate::{granule::Granule, heatmap_data::HeatmapData};

#[derive(Deserialize, Serialize, Debug, PartialEq)]
#[derive(Serialize, Deserialize, Decode, Encode, Debug, PartialEq)]
pub struct HeatmapResponse {
pub data: HeatmapData,
}
Expand Down
2 changes: 1 addition & 1 deletion heatmap-service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
let cors = Cors::default()
.allowed_origin("https://asfadmin.github.io") // The client is hosted on github pages
.allowed_origin("localhost") // Allowed for debug purposes
.allowed_origin("http://localhost:8080") // Allowed for debug purposes
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
Expand Down
7 changes: 6 additions & 1 deletion heatmap-service/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use actix_web::{
body::BoxBody,
web::{Data, Json},
Error, HttpRequest, HttpResponse,
};
Expand Down Expand Up @@ -38,7 +39,11 @@ async fn heatmap_query(

let response_data = HeatmapResponse::from_geojson(query.filter, feature_collection);

let response = HttpResponse::Ok().json(&response_data);
let response = HttpResponse::Ok()
.message_body(BoxBody::new(
bincode::encode_to_vec(&response_data, bincode::config::standard()).unwrap(),
))
.expect("Failed to create HttpResponse for heatmap granules");

if let Some(redis_pool) = redis_wrapped {
redis::cache_put(
Expand Down
Loading