latest pushes
This commit is contained in:
parent
3768f70eba
commit
b5b7483adb
2
Package/rust/.gitignore
vendored
Normal file
2
Package/rust/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
target
|
||||
Cargo.lock
|
24
Package/rust/Cargo.toml
Normal file
24
Package/rust/Cargo.toml
Normal file
@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "bellande_node_importance"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Bellande Robotics Sensors Research Innovation Center"]
|
||||
description = "A tool for calculating n-dimensional node importance via API or local executable"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/Robotics-Sensors/bellande_node_importance"
|
||||
readme = "README.md"
|
||||
keywords = ["robotics", "algorithms", "research", "spatial-analysis", "node-importance"]
|
||||
categories = ["science", "algorithms", "mathematics"]
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
structopt = "0.3"
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
thiserror = "1.0"
|
||||
anyhow = "1.0"
|
||||
|
||||
[lib]
|
||||
name = "bellande_node_importance"
|
||||
path = "src/bellande_node_importance.rs"
|
166
Package/rust/README.md
Normal file
166
Package/rust/README.md
Normal file
@ -0,0 +1,166 @@
|
||||
# 📦 Bellande Node Importance
|
||||
|
||||
## 🧙 Organization Website
|
||||
- [![Organization Website](https://img.shields.io/badge/Explore%20Our-Website-0099cc?style=for-the-badge)](https://robotics-sensors.github.io)
|
||||
|
||||
## 🧙 Organization Github
|
||||
- [![Organization Github ](https://img.shields.io/badge/Explore%20Our-Github-0099cc?style=for-the-badge)](https://github.com/Robotics-Sensors)
|
||||
|
||||
# Author, Creator and Maintainer
|
||||
- **Ronaldson Bellande**
|
||||
|
||||
## Bellande Node Importance Executables & Models
|
||||
- [![Bellande Node Importance Models & Executables ](https://img.shields.io/badge/Bellande%20Node%20Importance-Models/Executables-0099cc?style=for-the-badge)](https://github.com/Artificial-Intelligence-Computer-Vision/bellande_node_importance_models_executables)
|
||||
|
||||
# API HTTP Usability (BELLANDE FORMAT)
|
||||
```
|
||||
# Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
# GNU General Public License v3.0 or later
|
||||
|
||||
url: https://bellande-robotics-sensors-research-innovation-center.org
|
||||
|
||||
endpoint_path:
|
||||
bellande_node_importance: /api/Bellande_Node_Importance/node_importance
|
||||
|
||||
Bellande_Framework_Access_Key: bellande_web_api_opensource
|
||||
```
|
||||
|
||||
# API HTTP Usability (JSON FORMAT)
|
||||
```
|
||||
{
|
||||
"license": [
|
||||
"Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande",
|
||||
"This program is free software: you can redistribute it and/or modify",
|
||||
"it under the terms of the GNU General Public License as published by",
|
||||
"the Free Software Foundation, either version 3 of the License, or",
|
||||
"(at your option) any later version.",
|
||||
"",
|
||||
"This program is distributed in the hope that it will be useful,",
|
||||
"but WITHOUT ANY WARRANTY; without even the implied warranty of",
|
||||
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
|
||||
"GNU General Public License for more details.",
|
||||
"",
|
||||
"You should have received a copy of the GNU General Public License",
|
||||
"along with this program. If not, see <https://www.gnu.org/licenses/>.",
|
||||
"GNU General Public License v3.0 or later"
|
||||
],
|
||||
"url": "https://bellande-robotics-sensors-research-innovation-center.org",
|
||||
"endpoint_path": {
|
||||
"bellande_node_importance": "/api/Bellande_Node_Importance/node_importance"
|
||||
},
|
||||
"Bellande_Framework_Access_Key": "bellande_web_api_opensource"
|
||||
}
|
||||
```
|
||||
|
||||
# API Payload Example
|
||||
```
|
||||
{
|
||||
"node": {
|
||||
"coords": [5.0, 5.0, 5.0],
|
||||
"segment": 1
|
||||
},
|
||||
"nodes": [
|
||||
{"coords": [4.0, 4.0, 4.0], "segment": 1},
|
||||
{"coords": [6.0, 6.0, 6.0], "segment": 1}
|
||||
],
|
||||
"important_nodes": {
|
||||
"1": [{"coords": [4.0, 4.0, 4.0], "segment": 1}],
|
||||
"2": [{"coords": [15.0, 15.0, 15.0], "segment": 2}]
|
||||
},
|
||||
"adjacent_segments": {
|
||||
"1": [2],
|
||||
"2": [1]
|
||||
},
|
||||
"grid_steps": [10.0, 10.0, 10.0],
|
||||
"min_segment_coverage": 0.5,
|
||||
"auth": {
|
||||
"authorization_key": "bellande_web_api_opensource"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# 🧙 Website Bellande API Testing
|
||||
- [![Website API Testing](https://img.shields.io/badge/Bellande%20API-Testing-0099cc?style=for-the-badge)](https://bellande-robotics-sensors-research-innovation-center.org/api/bellande_node_importance_experiment)
|
||||
|
||||
# Quick Bellande API Testing
|
||||
```
|
||||
curl -X 'POST' \
|
||||
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Node_Importance/node_importance' \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
"node": {
|
||||
"coords": [5.0, 5.0, 5.0],
|
||||
"segment": 1
|
||||
},
|
||||
"nodes": [
|
||||
{"coords": [4.0, 4.0, 4.0], "segment": 1},
|
||||
{"coords": [6.0, 6.0, 6.0], "segment": 1}
|
||||
],
|
||||
"important_nodes": {
|
||||
"1": [{"coords": [4.0, 4.0, 4.0], "segment": 1}],
|
||||
"2": [{"coords": [15.0, 15.0, 15.0], "segment": 2}]
|
||||
},
|
||||
"adjacent_segments": {
|
||||
"1": [2],
|
||||
"2": [1]
|
||||
},
|
||||
"grid_steps": [10.0, 10.0, 10.0],
|
||||
"min_segment_coverage": 0.5,
|
||||
"auth": {
|
||||
"authorization_key": "bellande_web_api_opensource"
|
||||
}
|
||||
}'
|
||||
```
|
||||
|
||||
## Website PYPI
|
||||
- https://pypi.org/project/bellande_node_importance
|
||||
|
||||
### Installation
|
||||
- `$ pip install bellande_node_importance`
|
||||
|
||||
### Usage
|
||||
```
|
||||
bellande_node_importance_api \
|
||||
--node '{"coords": [5.0, 5.0, 5.0], "segment": 1}' \
|
||||
--nodes '[{"coords": [4.0, 4.0, 4.0], "segment": 1}, {"coords": [6.0, 6.0, 6.0], "segment": 1}]' \
|
||||
--important-nodes '{"1": [{"coords": [4.0, 4.0, 4.0], "segment": 1}], "2": [{"coords": [15.0, 15.0, 15.0], "segment": 2}]}' \
|
||||
--adjacent-segments '{"1": [2], "2": [1]}' \
|
||||
--grid-steps '[10.0, 10.0, 10.0]' \
|
||||
--min-segment-coverage 0.5
|
||||
```
|
||||
|
||||
### Upgrade (if not upgraded)
|
||||
- `$ pip install --upgrade bellande_node_importance`
|
||||
|
||||
```
|
||||
Name: bellande_node_importance
|
||||
Summary: Determines node importance in n-dimensional space based on coverage and connectivity
|
||||
Home-page: github.com/RonaldsonBellande/bellande_node_importance
|
||||
Author: Ronaldson Bellande
|
||||
Author-email: ronaldsonbellande@gmail.com
|
||||
License: GNU General Public License v3.0
|
||||
```
|
||||
|
||||
## Published Paper
|
||||
```
|
||||
Coming Soon
|
||||
```
|
||||
|
||||
## Preprint
|
||||
- [![Preprint](https://img.shields.io/badge/Preprint-Bellande%20Node%20Importance-0099cc?style=for-the-badge)](https://dapp.orvium.io/deposits/6650ccb8afb407dc8beb0ff2/view)
|
||||
|
||||
## License
|
||||
This Algorithm or Models is distributed under the [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/), see [LICENSE](https://github.com/RonaldsonBellande/bellande_node_importance/blob/main/LICENSE) and [NOTICE](https://github.com/RonaldsonBellande/bellande_node_importance/blob/main/LICENSE) for more information.
|
4
Package/rust/publish.sh
Executable file
4
Package/rust/publish.sh
Executable file
@ -0,0 +1,4 @@
|
||||
cp ../../README.md .
|
||||
bash ../../git_scripts/push.sh
|
||||
cargo publish
|
||||
rm -f README.md
|
196
Package/rust/src/bellande_node_importance.rs
Normal file
196
Package/rust/src/bellande_node_importance.rs
Normal file
@ -0,0 +1,196 @@
|
||||
// Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use reqwest;
|
||||
use serde_json::{json, Value};
|
||||
use std::error::Error;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{self, Command};
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "bellande_node_importance", about = "Bellande Node Importance Tool")]
|
||||
struct Opt {
|
||||
#[structopt(long, help = "Node to evaluate as JSON object with coordinates and segment")]
|
||||
node: String,
|
||||
|
||||
#[structopt(long, help = "List of recent nodes as JSON array")]
|
||||
recent_nodes: String,
|
||||
|
||||
#[structopt(long, help = "Dictionary of important nodes by segment as JSON object")]
|
||||
important_nodes: String,
|
||||
|
||||
#[structopt(long, help = "Dictionary of adjacent segments as JSON object")]
|
||||
adjacent_segments: String,
|
||||
|
||||
#[structopt(long, help = "Grid steps for each dimension as JSON array")]
|
||||
grid_steps: String,
|
||||
|
||||
#[structopt(long, help = "Minimum required segment coverage ratio", default_value = "0.5")]
|
||||
min_segment_coverage: f64,
|
||||
|
||||
#[structopt(long, help = "Use local executable instead of API")]
|
||||
use_executable: bool,
|
||||
}
|
||||
|
||||
async fn make_node_importance_request(
|
||||
node: Value,
|
||||
recent_nodes: Value,
|
||||
important_nodes: Value,
|
||||
adjacent_segments: Value,
|
||||
grid_steps: Value,
|
||||
min_segment_coverage: f64,
|
||||
) -> Result<Value, Box<dyn Error>> {
|
||||
let client = reqwest::Client::new();
|
||||
let url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Node_Importance/node_importance";
|
||||
|
||||
let payload = json!({
|
||||
"node": node,
|
||||
"nodes": recent_nodes,
|
||||
"important_nodes": important_nodes,
|
||||
"adjacent_segments": adjacent_segments,
|
||||
"grid_steps": grid_steps,
|
||||
"min_segment_coverage": min_segment_coverage,
|
||||
"auth": {
|
||||
"authorization_key": "bellande_web_api_opensource"
|
||||
}
|
||||
});
|
||||
|
||||
let response = client
|
||||
.post(url)
|
||||
.header("accept", "application/json")
|
||||
.header("Content-Type", "application/json")
|
||||
.json(&payload)
|
||||
.send()
|
||||
.await?
|
||||
.json::<Value>()
|
||||
.await?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn get_executable_path() -> PathBuf {
|
||||
if cfg!(target_os = "windows") {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("Bellande_Node_Importance.exe")
|
||||
} else {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("Bellande_Node_Importance")
|
||||
}
|
||||
}
|
||||
|
||||
fn run_node_importance_executable(
|
||||
node: &str,
|
||||
recent_nodes: &str,
|
||||
important_nodes: &str,
|
||||
adjacent_segments: &str,
|
||||
grid_steps: &str,
|
||||
min_segment_coverage: f64,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let executable_path = get_executable_path();
|
||||
let passcode = "bellande_node_importance_executable_access_key";
|
||||
|
||||
// Parse and validate input
|
||||
let node_obj: Value = serde_json::from_str(node)?;
|
||||
let grid_steps_list: Value = serde_json::from_str(grid_steps)?;
|
||||
|
||||
// Validate dimensions
|
||||
if let (Some(coords), Some(steps)) = (
|
||||
node_obj["coords"].as_array(),
|
||||
grid_steps_list.as_array()
|
||||
) {
|
||||
if coords.len() != steps.len() {
|
||||
return Err(format!(
|
||||
"Node coordinates must match grid steps dimensions ({})",
|
||||
steps.len()
|
||||
).into());
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare and run command
|
||||
let output = Command::new(executable_path)
|
||||
.args(&[
|
||||
passcode,
|
||||
node,
|
||||
recent_nodes,
|
||||
important_nodes,
|
||||
adjacent_segments,
|
||||
grid_steps,
|
||||
&min_segment_coverage.to_string(),
|
||||
])
|
||||
.output()?;
|
||||
|
||||
if output.status.success() {
|
||||
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!(
|
||||
"Process failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
).into())
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
// Parse JSON strings to Values for validation
|
||||
let node: Value = serde_json::from_str(&opt.node)
|
||||
.map_err(|e| format!("Error parsing node: {}", e))?;
|
||||
let recent_nodes: Value = serde_json::from_str(&opt.recent_nodes)
|
||||
.map_err(|e| format!("Error parsing recent nodes: {}", e))?;
|
||||
let important_nodes: Value = serde_json::from_str(&opt.important_nodes)
|
||||
.map_err(|e| format!("Error parsing important nodes: {}", e))?;
|
||||
let adjacent_segments: Value = serde_json::from_str(&opt.adjacent_segments)
|
||||
.map_err(|e| format!("Error parsing adjacent segments: {}", e))?;
|
||||
let grid_steps: Value = serde_json::from_str(&opt.grid_steps)
|
||||
.map_err(|e| format!("Error parsing grid steps: {}", e))?;
|
||||
|
||||
if opt.use_executable {
|
||||
// Run using local executable
|
||||
if let Err(e) = run_node_importance_executable(
|
||||
&opt.node,
|
||||
&opt.recent_nodes,
|
||||
&opt.important_nodes,
|
||||
&opt.adjacent_segments,
|
||||
&opt.grid_steps,
|
||||
opt.min_segment_coverage,
|
||||
) {
|
||||
eprintln!("Error: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
} else {
|
||||
// Run using API
|
||||
match make_node_importance_request(
|
||||
node,
|
||||
recent_nodes,
|
||||
important_nodes,
|
||||
adjacent_segments,
|
||||
grid_steps,
|
||||
opt.min_segment_coverage,
|
||||
).await {
|
||||
Ok(result) => {
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user