From 00da7c29fca2d723deefad8835831f46252d50e9 Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Wed, 4 Dec 2024 03:37:14 -0500 Subject: [PATCH] latest pushes --- .gitignore | 0 Package/python/publish.sh | 2 + Package/python/setup.py | 43 +++++++ Package/python/src/.gitignore | 1 + Package/python/src/__init__.py | 0 .../src/bellande_probabilistic/__init__.py | 3 + .../bellande_probabilistic_api.py | 81 +++++++++++++ Package/rust/.gitignore | 2 + Package/rust/Cargo.toml | 24 ++++ Package/rust/publish.sh | 4 + Package/rust/src/bellande_probability.rs | 110 ++++++++++++++++++ README.md | 70 ++++++----- git_scripts/.gitignore | 3 + 13 files changed, 311 insertions(+), 32 deletions(-) create mode 100644 .gitignore create mode 100755 Package/python/publish.sh create mode 100644 Package/python/setup.py create mode 100644 Package/python/src/.gitignore create mode 100644 Package/python/src/__init__.py create mode 100644 Package/python/src/bellande_probabilistic/__init__.py create mode 100644 Package/python/src/bellande_probabilistic/bellande_probabilistic_api.py create mode 100644 Package/rust/.gitignore create mode 100644 Package/rust/Cargo.toml create mode 100755 Package/rust/publish.sh create mode 100644 Package/rust/src/bellande_probability.rs create mode 100644 git_scripts/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Package/python/publish.sh b/Package/python/publish.sh new file mode 100755 index 0000000..48934a9 --- /dev/null +++ b/Package/python/publish.sh @@ -0,0 +1,2 @@ +python setup.py sdist +twine upload dist/* diff --git a/Package/python/setup.py b/Package/python/setup.py new file mode 100644 index 0000000..478e9a0 --- /dev/null +++ b/Package/python/setup.py @@ -0,0 +1,43 @@ +from setuptools import setup, find_packages + +with open("../../README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + +setup( + name="bellande_probability", + version="0.0.3", + description="Robots Probability", + long_description=long_description, + long_description_content_type="text/markdown", + author="RonaldsonBellande", + author_email="ronaldsonbellande@gmail.com", + packages=find_packages(where="src"), + package_dir={"": "src"}, + include_package_data=True, + install_requires=[ + "numpy", + ], + classifiers=[ + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Programming Language :: Python", + ], + keywords=["package", "setuptools"], + python_requires=">=3.0", + extras_require={ + "dev": ["pytest", "pytest-cov[all]", "mypy", "black"], + }, + package_data={ + 'bellande_probability': ['Bellande_Probability'], + }, + entry_points={ + 'console_scripts': [ + 'bellande_probability_api = bellande_probability.bellande_probability_api:main', + ], + }, + project_urls={ + "Home": "https://github.com/Robotics-Sensors/bellande_probability", + "Homepage": "https://github.com/Robotics-Sensors/bellande_probability", + "documentation": "https://github.com/Robotics-Sensors/bellande_probability", + "repository": "https://github.com/Robotics-Sensors/bellande_probability", + }, +) diff --git a/Package/python/src/.gitignore b/Package/python/src/.gitignore new file mode 100644 index 0000000..ffe92f2 --- /dev/null +++ b/Package/python/src/.gitignore @@ -0,0 +1 @@ +bellande_probability.egg-info diff --git a/Package/python/src/__init__.py b/Package/python/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Package/python/src/bellande_probabilistic/__init__.py b/Package/python/src/bellande_probabilistic/__init__.py new file mode 100644 index 0000000..14b2a3f --- /dev/null +++ b/Package/python/src/bellande_probabilistic/__init__.py @@ -0,0 +1,3 @@ +""" +ros_extension +""" diff --git a/Package/python/src/bellande_probabilistic/bellande_probabilistic_api.py b/Package/python/src/bellande_probabilistic/bellande_probabilistic_api.py new file mode 100644 index 0000000..71f272d --- /dev/null +++ b/Package/python/src/bellande_probabilistic/bellande_probabilistic_api.py @@ -0,0 +1,81 @@ +# 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 . + +#!/usr/bin/env python3 +import requests +import argparse +import json +import sys + +def make_bellande_probability_distribution_request(mu_func, sigma_func, x, dimensions, full_auth=False): + base_url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Probability" + + endpoint = f"{base_url}/bellande_probability_full_auth" if full_auth else \ + f"{base_url}/bellande_probability" + + # Convert string input to list if it's a string + if isinstance(x, str): + x = json.loads(x) + + auth = { + "full_authorization_key": "bellande_web_api_full_auth" + } if full_auth else { + "authorization_key": "bellande_web_api_opensource" + } + + payload = { + "mu_func": mu_func, + "sigma_func": sigma_func, + "x": x, + "dimensions": dimensions, + "auth": auth + } + + headers = { + 'accept': 'application/json', + 'Content-Type': 'application/json' + } + + try: + response = requests.post(endpoint, json=payload, headers=headers) + response.raise_for_status() + return response.json() + except requests.RequestException as e: + print(f"Error making request: {e}", file=sys.stderr) + sys.exit(1) + +def main(): + parser = argparse.ArgumentParser(description="Run Bellande Distribution API") + parser.add_argument("--mu-func", required=True, help="mu function as string") + parser.add_argument("--sigma-func", required=True, help="sigma function as string") + parser.add_argument("--x", required=True, help="Input vector as JSON-formatted list") + parser.add_argument("--dimensions", type=int, required=True, help="Number of dimensions") + parser.add_argument("--full-auth", action="store_true", help="Use full authentication") + + args = parser.parse_args() + + try: + result = make_bellande_probability_distribution_request( + args.mu_func, + args.sigma_func, + args.x, + args.dimensions, + args.full_auth + ) + + print(json.dumps(result, indent=2)) + except json.JSONDecodeError as e: + print(f"Error: Invalid JSON format in input - {e}", file=sys.stderr) + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/Package/rust/.gitignore b/Package/rust/.gitignore new file mode 100644 index 0000000..a9d37c5 --- /dev/null +++ b/Package/rust/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/Package/rust/Cargo.toml b/Package/rust/Cargo.toml new file mode 100644 index 0000000..c68f86e --- /dev/null +++ b/Package/rust/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "bellande_probability" +version = "0.1.0" +edition = "2021" +authors = ["Bellande Robotics Sensors Research Innovation Center"] +description = "A tool for running Bellande Probability calculations via API" +license = "GPL-3.0-or-later" +repository = "https://github.com/Robotics-Sensors/bellande_probability" +readme = "README.md" +keywords = ["robotics", "algorithms", "research"] +categories = ["science", "algorithms"] + +[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_probability" +path = "src/bellande_probability.rs" diff --git a/Package/rust/publish.sh b/Package/rust/publish.sh new file mode 100755 index 0000000..7d4afa0 --- /dev/null +++ b/Package/rust/publish.sh @@ -0,0 +1,4 @@ +cp ../../README.md . +bash ../../git_scripts/push.sh +cargo publish +rm -f README.md diff --git a/Package/rust/src/bellande_probability.rs b/Package/rust/src/bellande_probability.rs new file mode 100644 index 0000000..7bbed5e --- /dev/null +++ b/Package/rust/src/bellande_probability.rs @@ -0,0 +1,110 @@ +// 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 . + +use reqwest; +use serde_json::{json, Value}; +use std::error::Error; +use structopt::StructOpt; + +#[derive(StructOpt, Debug)] +#[structopt(name = "bellande_probability", about = "Bellande Probability Tool")] +struct Opt { + #[structopt(long, help = "First coordinate as JSON-formatted list")] + node0: String, + + #[structopt(long, help = "Second coordinate as JSON-formatted list")] + node1: String, + + #[structopt(long, help = "Probability threshold value")] + threshold: f64, + + #[structopt(long, help = "Number of dimensions")] + dimensions: i32, + + #[structopt(long, help = "Use full authentication")] + full_auth: bool, +} + +async fn make_bellande_probability_request( + node0: Value, + node1: Value, + threshold: f64, + dimensions: i32, + full_auth: bool, +) -> Result> { + let client = reqwest::Client::new(); + let base_url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Probability"; + + let endpoint = if full_auth { + format!("{}/bellande_probability_full_auth", base_url) + } else { + format!("{}/bellande_probability", base_url) + }; + + let auth = if full_auth { + json!({ + "full_authorization_key": "bellande_web_api_full_auth" + }) + } else { + json!({ + "authorization_key": "bellande_web_api_opensource" + }) + }; + + let payload = json!({ + "node0": node0, + "node1": node1, + "threshold": threshold, + "dimensions": dimensions, + "auth": auth + }); + + let response = client + .post(&endpoint) + .header("accept", "application/json") + .header("Content-Type", "application/json") + .json(&payload) + .send() + .await? + .json::() + .await?; + + Ok(response) +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let opt = Opt::from_args(); + + let node0: Value = serde_json::from_str(&opt.node0) + .map_err(|e| format!("Error parsing node0: {}", e))?; + let node1: Value = serde_json::from_str(&opt.node1) + .map_err(|e| format!("Error parsing node1: {}", e))?; + + match make_bellande_probability_request( + node0, + node1, + opt.threshold, + opt.dimensions, + opt.full_auth + ).await { + Ok(result) => { + println!("{}", serde_json::to_string_pretty(&result)?); + } + Err(e) => { + eprintln!("Error: {}", e); + std::process::exit(1); + } + } + + Ok(()) +} diff --git a/README.md b/README.md index da8c09b..2c63bde 100644 --- a/README.md +++ b/README.md @@ -10,32 +10,7 @@ # Author, Creator and Maintainer - **Ronaldson Bellande** -# 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 . -# GNU General Public License v3.0 or later - -url: https://bellande-robotics-sensors-research-innovation-center.org - -endpoint_path: - bellande_probabilistic: /api/Bellande_Probabilistic/bellande_probabilistic - -Bellande_Framework_Access_Key: bellande_web_api_opensource -``` - -# API HTTP Usability (JSON FORMAT) +# API Usability ``` { "license": [ @@ -56,12 +31,11 @@ Bellande_Framework_Access_Key: bellande_web_api_opensource ], "url": "https://bellande-robotics-sensors-research-innovation-center.org", "endpoint_path": { - "bellande_probabilistic": "/api/Bellande_Probabilistic/bellande_probabilistic" + "bellande_probabilistic": "/api/Bellande_Probability/bellande_probability" }, "Bellande_Framework_Access_Key": "bellande_web_api_opensource" } ``` - # API Payload Example ``` { @@ -81,7 +55,7 @@ Bellande_Framework_Access_Key: bellande_web_api_opensource # Quick Bellande API Testing ``` curl -X 'POST' \ - 'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Distribution/bellande_distribution_function_nd' \ + 'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Probability/bellande_probability' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ @@ -95,6 +69,40 @@ curl -X 'POST' \ }' ``` +# Bellande Limit Usage + +## Website Crates +- https://crates.io/crates/bellande_probability + +### Installation +- `cargo add bellande_probability` + +## Website PYPI +- https://pypi.org/project/bellande_probability + +### Installation +- `$ pip install bellande_probability` + +### Usage +``` +bellande_distribution \ + --mu-func "i * 2" \ + --sigma-func "1 + i * 0.1" \ + --x "[1.0, 2.0, 3.0]" \ + --dimensions 3 +``` + +### Upgrade (if not upgraded) +- `$ pip install --upgrade bellande_probability` + +``` +Name: bellande_probability +Summary: Computes the next step towards a target node +Home-page: github.com/RonaldsonBellande/bellande_probability +Author: Ronaldson Bellande +Author-email: ronaldsonbellande@gmail.com +License: GNU General Public License v3.0 +``` ## Published Paper ``` @@ -102,7 +110,5 @@ Coming Soon ``` ## License -Bellande Probabilistic 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_probabilistic/blob/main/LICENSE) and [NOTICE](https://github.com/RonaldsonBellande/bellande_probabilistic/blob/main/LICENSE) for more information. +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_probabilistic/blob/main/LICENSE) and [NOTICE](https://github.com/RonaldsonBellande/bellande_probabilistic/blob/main/LICENSE) for more information. -## Code of Conduct -Bellande Probabilistic is distributed under the [CODE_OF_CONDUCT](https://github.com/Robotics-Sensors/bellande_step/blob/main/CODE_OF_CONDUCT.md) and [NOTICE](https://github.com/Robotics-Sensors/bellande_step/blob/main/CODE_OF_CONDUCT.md) for more information. diff --git a/git_scripts/.gitignore b/git_scripts/.gitignore new file mode 100644 index 0000000..e5a7a9c --- /dev/null +++ b/git_scripts/.gitignore @@ -0,0 +1,3 @@ +fix_errors.sh +push.sh +repository_recal.sh