Skip to content

Commit

Permalink
#3 Added another unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
esride-jts committed Oct 24, 2024
1 parent 7d0a4ca commit 22f9f6e
Showing 1 changed file with 56 additions and 44 deletions.
100 changes: 56 additions & 44 deletions spatial-data-science/src/platformshell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ mod utils;

#[cfg(test)]
mod tests {
use geo::Point;
use platformshell::LocationServicesError;
use serde_esri::features::Feature;
use serde_esri::places::query::{PlacesClient, WithinExtentQueryParamsBuilder, PLACES_API_URL};
use std::env;

use super::utils;



#[test]
fn test_env_var_exists() {
// Check whether or not an ArcGIS API key was set using the environment
Expand Down Expand Up @@ -51,60 +58,65 @@ mod tests {
let res = client.within_extent(params);
assert!(res.is_ok());
}
}

#[test]
fn test_query_feature_service() {
// Create a Point with latitude and longitude
let location = Point::new(7.116108, 50.719725);

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a Point with latitude and longitude
let location = Point::new(7.116108, 50.719725);
// Query the feature service
let urban_hri_url = env::var("URBAN_HEAT_RISK_INDEX_FEATURE_SERVICE_URL").unwrap();

// Query the feature service
let urban_hri_url = env::var("URBAN_HEAT_RISK_INDEX_FEATURE_SERVICE_URL")?;
// Define the filtering logic using polygon geometry
let polygon_filter_fn = |feature: &Feature<2>| {
if let Some(geometry) = &feature.geometry {
geometry.clone().as_polygon().is_some()
} else {
false
}
};

// Define the filtering logic using polygon geometry
let polygon_filter_fn = |feature: &Feature<2>| {
if let Some(geometry) = &feature.geometry {
geometry.clone().as_polygon().is_some()
} else {
false
}
};

// Define the filtering logic using high HRI value
let hri_filter_fn = |feature: &Feature<2>| {
if let Some(attributes) = &feature.attributes {
if let Some(hri_value) = attributes.get("HRI") {
if let Some(hri_value) = hri_value.as_f64() {
return hri_value > 7.0;
// Define the filtering logic using high HRI value
let hri_filter_fn = |feature: &Feature<2>| {
if let Some(attributes) = &feature.attributes {
if let Some(hri_value) = attributes.get("HRI") {
if let Some(hri_value) = hri_value.as_f64() {
return hri_value > 7.0;
}
}
}
false
};

/*
match utils::query_heat_risk_index(urban_hri_url, "1=1", Some(location), hri_filter_fn) {
Ok(hri_featureset) => {
let json = serde_json::to_string_pretty(&hri_featureset)?;
println!("{}", json);
}
Err(e) => {
eprintln!("Error querying heat risk index: {}", e);
return Err(Box::new(LocationServicesError { code:9999, message:"Error querying heat risk index!".to_string() }));
}
}
false
};

/*
match utils::query_heat_risk_index(urban_hri_url, "1=1", Some(location), hri_filter_fn) {
Ok(hri_featureset) => {
let json = serde_json::to_string_pretty(&hri_featureset)?;
println!("{}", json);
}
Err(e) => {
eprintln!("Error querying heat risk index: {}", e);
return Err(Box::new(LocationServicesError { code:9999, message:"Error querying heat risk index!".to_string() }));
}
}
*/
*/

match utils::query_heat_risk_index(urban_hri_url, "1=1", None, hri_filter_fn) {
Ok(hri_featureset) => {
let json = serde_json::to_string_pretty(&hri_featureset)?;
println!("{}", json);
}
Err(e) => {
eprintln!("Error querying heat risk index: {}", e);
return Err(Box::new(LocationServicesError { code:9999, message:"Error querying heat risk index!".to_string() }));
match utils::query_heat_risk_index(urban_hri_url, "1=1", None, hri_filter_fn) {
Ok(hri_featureset) => {
let json = serde_json::to_string_pretty(&hri_featureset).unwrap();
//println!("{}", json);
}
Err(e) => {
eprintln!("Error querying heat risk index: {}", e);
//return Err(Box::new(LocationServicesError { code:9999, message:"Error querying heat risk index!".to_string() }));
}
}
}
}


fn main() -> Result<(), Box<dyn std::error::Error>> {


Ok(())
}

0 comments on commit 22f9f6e

Please sign in to comment.