latest pushes

This commit is contained in:
Ronaldson Bellande 2024-12-18 10:08:35 -05:00
parent 378a112ab5
commit b3a416b2bc
5 changed files with 438 additions and 137 deletions

View File

@ -19,27 +19,58 @@ import argparse
import json
import sys
def make_bellande_particles_request(particle, movement=None, world=None, count=None):
url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particles/bellande_particles"
def make_bellande_particle_move_request(particle_state, rotation1, translation, rotation2):
url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/move"
# Convert string inputs to lists/dicts if they're strings
if isinstance(particle, str):
particle = json.loads(particle)
if isinstance(movement, str):
movement = json.loads(movement)
if isinstance(world, str):
world = json.loads(world)
payload = {
"particle": particle,
"movement": movement,
"world": world,
"count": count,
"particle": {
"x": particle_state[0],
"y": particle_state[1],
"heading": particle_state[2],
"weight": particle_state[3] if len(particle_state) > 3 else 1.0
},
"rotation1": rotation1,
"translation": translation,
"rotation2": rotation2,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}
return send_request(url, payload)
def make_bellande_particle_read_markers_request(particle_state, world_info):
url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/read_markers"
payload = {
"particle": {
"x": particle_state[0],
"y": particle_state[1],
"heading": particle_state[2],
"weight": particle_state[3] if len(particle_state) > 3 else 1.0
},
"world": world_info,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}
return send_request(url, payload)
def make_bellande_particle_create_random_request(count, world_info):
url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/create_random"
payload = {
"count": count,
"world": world_info,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}
return send_request(url, payload)
def send_request(url, payload):
headers = {
'accept': 'application/json',
'Content-Type': 'application/json'
@ -54,25 +85,58 @@ def make_bellande_particles_request(particle, movement=None, world=None, count=N
sys.exit(1)
def main():
parser = argparse.ArgumentParser(description="Run Bellande Particles API")
parser.add_argument("--particle", required=True,
help="Particle state as JSON-formatted list [x, y, heading, weight]")
parser.add_argument("--movement",
help="Movement parameters as JSON-formatted list [rotation1, translation, rotation2]")
parser.add_argument("--world",
help="world information as JSON object with width, height, and markers")
parser.add_argument("--count", type=int,
help="Particle count for random generation")
parser = argparse.ArgumentParser(description="Run Bellande Particle API")
subparsers = parser.add_subparsers(dest='command', required=True)
# Move command
move_parser = subparsers.add_parser('move', help='Move particle')
move_parser.add_argument("--particle-state", required=True,
help="Particle state as JSON-formatted list [x, y, heading, weight]")
move_parser.add_argument("--rotation1", type=float, required=True,
help="First rotation angle")
move_parser.add_argument("--translation", type=float, required=True,
help="Translation distance")
move_parser.add_argument("--rotation2", type=float, required=True,
help="Second rotation angle")
# Read markers command
read_parser = subparsers.add_parser('read-markers', help='Read markers')
read_parser.add_argument("--particle-state", required=True,
help="Particle state as JSON-formatted list [x, y, heading, weight]")
read_parser.add_argument("--world", required=True,
help="World information as JSON object")
# Create random command
random_parser = subparsers.add_parser('create-random', help='Create random particles')
random_parser.add_argument("--count", type=int, required=True,
help="Number of particles to create")
random_parser.add_argument("--world", required=True,
help="World information as JSON object")
args = parser.parse_args()
try:
result = make_bellande_particles_request(
args.particle,
args.movement,
args.world,
args.count
)
if args.command == 'move':
particle_state = json.loads(args.particle_state)
result = make_bellande_particle_move_request(
particle_state,
args.rotation1,
args.translation,
args.rotation2
)
elif args.command == 'read-markers':
particle_state = json.loads(args.particle_state)
world_info = json.loads(args.world)
result = make_bellande_particle_read_markers_request(
particle_state,
world_info
)
elif args.command == 'create-random':
world_info = json.loads(args.world)
result = make_bellande_particle_create_random_request(
args.count,
world_info
)
print(json.dumps(result, indent=2))
except json.JSONDecodeError as e:

View File

@ -19,49 +19,122 @@ use std::error::Error;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
#[structopt(name = "bellande_particle", about = "Bellande Particles Tool")]
struct Opt {
#[structopt(
long,
help = "Particle state as JSON-formatted list [x, y, heading, weight]"
)]
particle: String,
enum Command {
#[structopt(name = "move", about = "Move particle")]
Move {
#[structopt(
long,
help = "Particle state as JSON-formatted list [x, y, heading, weight]"
)]
particle_state: String,
#[structopt(
long,
help = "Movement parameters as JSON-formatted list [rotation1, translation, rotation2]"
)]
movement: Option<String>,
#[structopt(long, help = "First rotation angle")]
rotation1: f64,
#[structopt(
long,
help = "World information as JSON object with width, height, and markers"
)]
world: Option<String>,
#[structopt(long, help = "Translation distance")]
translation: f64,
#[structopt(long, help = "Particle count for random generation")]
count: Option<i32>,
#[structopt(long, help = "Second rotation angle")]
rotation2: f64,
},
#[structopt(name = "read-markers", about = "Read markers")]
ReadMarkers {
#[structopt(
long,
help = "Particle state as JSON-formatted list [x, y, heading, weight]"
)]
particle_state: String,
#[structopt(long, help = "World information as JSON object")]
world: String,
},
#[structopt(name = "create-random", about = "Create random particles")]
CreateRandom {
#[structopt(long, help = "Number of particles to create")]
count: i32,
#[structopt(long, help = "World information as JSON object")]
world: String,
},
}
async fn make_bellande_particles_request(
particle: Value,
movement: Option<Value>,
world: Option<Value>,
count: Option<i32>,
#[derive(StructOpt, Debug)]
#[structopt(name = "bellande_particle", about = "Bellande Particle Tool")]
struct Opt {
#[structopt(subcommand)]
cmd: Command,
}
async fn make_bellande_particle_move_request(
particle_state: Value,
rotation1: f64,
translation: f64,
rotation2: f64,
) -> Result<Value, Box<dyn Error>> {
let client = reqwest::Client::new();
let url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/bellande_particle";
let url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/move";
let payload = json!({
"particle": particle,
"movement": movement,
"world": world,
"count": count,
"particle": {
"x": particle_state[0],
"y": particle_state[1],
"heading": particle_state[2],
"weight": particle_state.get(3).unwrap_or(&json!(1.0))
},
"rotation1": rotation1,
"translation": translation,
"rotation2": rotation2,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
});
send_request(url, payload).await
}
async fn make_bellande_particle_read_markers_request(
particle_state: Value,
world: Value,
) -> Result<Value, Box<dyn Error>> {
let url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/read_markers";
let payload = json!({
"particle": {
"x": particle_state[0],
"y": particle_state[1],
"heading": particle_state[2],
"weight": particle_state.get(3).unwrap_or(&json!(1.0))
},
"world": world,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
});
send_request(url, payload).await
}
async fn make_bellande_particle_create_random_request(
count: i32,
world: Value,
) -> Result<Value, Box<dyn Error>> {
let url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/create_random";
let payload = json!({
"count": count,
"world": world,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
});
send_request(url, payload).await
}
async fn send_request(url: &str, payload: Value) -> Result<Value, Box<dyn Error>> {
let client = reqwest::Client::new();
let response = client
.post(url)
.header("accept", "application/json")
@ -79,36 +152,38 @@ async fn make_bellande_particles_request(
async fn main() -> Result<(), Box<dyn Error>> {
let opt = Opt::from_args();
// Parse JSON strings to Values for validation
let particle: Value = serde_json::from_str(&opt.particle)
.map_err(|e| format!("Error parsing particle: {}", e))?;
let result = match opt.cmd {
Command::Move {
particle_state,
rotation1,
translation,
rotation2,
} => {
let particle_state: Value = serde_json::from_str(&particle_state)
.map_err(|e| format!("Error parsing particle state: {}", e))?;
// Parse optional movement
let movement: Option<Value> = match opt.movement {
Some(ref m) => {
Some(serde_json::from_str(m).map_err(|e| format!("Error parsing movement: {}", e))?)
make_bellande_particle_move_request(particle_state, rotation1, translation, rotation2)
.await?
}
Command::ReadMarkers {
particle_state,
world,
} => {
let particle_state: Value = serde_json::from_str(&particle_state)
.map_err(|e| format!("Error parsing particle state: {}", e))?;
let world: Value = serde_json::from_str(&world)
.map_err(|e| format!("Error parsing world info: {}", e))?;
make_bellande_particle_read_markers_request(particle_state, world).await?
}
Command::CreateRandom { count, world } => {
let world: Value = serde_json::from_str(&world)
.map_err(|e| format!("Error parsing world info: {}", e))?;
make_bellande_particle_create_random_request(count, world).await?
}
None => None,
};
// Parse optional world
let world: Option<Value> = match opt.world {
Some(ref w) => {
Some(serde_json::from_str(w).map_err(|e| format!("Error parsing world: {}", e))?)
}
None => None,
};
// Run using API
match make_bellande_particles_request(particle, movement, world, opt.count).await {
Ok(result) => {
println!("{}", serde_json::to_string_pretty(&result)?);
}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
println!("{}", serde_json::to_string_pretty(&result)?);
Ok(())
}

166
README.md
View File

@ -1,4 +1,4 @@
# 📦 Bellande Particles
# 📦 Bellande Particle
## 🧙 Organization Website
- [![Organization Website](https://img.shields.io/badge/Explore%20Our-Website-0099cc?style=for-the-badge)](https://robotics-sensors.github.io)
@ -28,14 +28,16 @@
url: https://bellande-robotics-sensors-research-innovation-center.org
endpoint_path:
bellande_particle: /api/Bellande_Particle/bellande_particle
endpoint_paths:
move: /api/Bellande_Particle/move
read_markers: /api/Bellande_Particle/read_markers
create_random: /api/Bellande_Particle/create_random
Bellande_Framework_Access_Key: bellande_web_api_opensource
```
# API HTTP Usability (JSON FORMAT)
```
```json
{
"license": [
"Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande",
@ -54,28 +56,64 @@ Bellande_Framework_Access_Key: bellande_web_api_opensource
"GNU General Public License v3.0 or later"
],
"url": "https://bellande-robotics-sensors-research-innovation-center.org",
"endpoint_path": {
"bellande_particle": "/api/Bellande_Particle/bellande_particle"
"endpoint_paths": {
"move": "/api/Bellande_Particle/move",
"read_markers": "/api/Bellande_Particle/read_markers",
"create_random": "/api/Bellande_Particle/create_random"
},
"Bellande_Framework_Access_Key": "bellande_web_api_opensource"
}
```
# API Payload Example
```
# API Payload Examples
## Move Particle
```json
{
"particle": [0, 0, 0, 1.0],
"movement": {
"rotation1": 45.0,
"translation": 1.0,
"rotation2": -45.0
"particle": {
"x": 0,
"y": 0,
"heading": 0,
"weight": 1.0
},
"rotation1": 45.0,
"translation": 1.0,
"rotation2": -45.0,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}
```
## Read Markers
```json
{
"particle": {
"x": 0,
"y": 0,
"heading": 0,
"weight": 1.0
},
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}
```
## Create Random
```json
{
"count": 10,
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
@ -83,34 +121,76 @@ Bellande_Framework_Access_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_particles_experiment)
- [![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_particle_experiment)
# Quick Bellande API Testing
```
# Quick Bellande API Testing Examples
## Move Particle
```bash
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/bellande_particle' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/move' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"particle": [0, 0, 0, 1.0],
"movement": {
"rotation1": 45.0,
"translation": 1.0,
"rotation2": -45.0
"particle": {
"x": 0,
"y": 0,
"heading": 0,
"weight": 1.0
},
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"count": 10,
"rotation1": 45.0,
"translation": 1.0,
"rotation2": -45.0,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
```
# Bellande Particles Usage
## Read Markers
```bash
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/read_markers' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"particle": {
"x": 0,
"y": 0,
"heading": 0,
"weight": 1.0
},
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
```
## Create Random
```bash
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/create_random' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"count": 10,
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
```
# Bellande Particle Usage
## Website Crates
- https://crates.io/crates/bellande_particle
@ -124,16 +204,28 @@ curl -X 'POST' \
### Installation
- `$ pip install bellande_particle`
### Usage
```
bellande_particle \
--particle "[0, 0, 0, 1.0]" \
--movement '{"rotation1": 45.0, "translation": 1.0, "rotation2": -45.0}' \
--world '{"width": 10.0, "height": 10.0, "markers": [[1.0, 1.0]]}' \
--count 10
### Command Line Usage Examples
```bash
# Move particle
bellande_particle move \
--particle-state "[0,0,0,1.0]" \
--rotation1 45.0 \
--translation 1.0 \
--rotation2 -45.0
# Read markers
bellande_particle read-markers \
--particle-state "[0,0,0,1.0]" \
--world '{"width":10.0,"height":10.0,"markers":[[1.0,1.0]]}'
# Create random particles
bellande_particle create-random \
--count 10 \
--world '{"width":10.0,"height":10.0,"markers":[[1.0,1.0]]}'
```
### Upgrade (if not upgraded)
### Upgrade
- `$ pip install --upgrade bellande_particle`
```

View File

@ -1,22 +1,57 @@
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/bellande_particle' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/move' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"particle": [0, 0, 0, 1.0],
"movement": {
"rotation1": 45.0,
"translation": 1.0,
"rotation2": -45.0
"particle": {
"x": 0,
"y": 0,
"heading": 0,
"weight": 1.0
},
"rotation1": 45.0,
"translation": 1.0,
"rotation2": -45.0,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/read_markers' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"particle": {
"x": 0,
"y": 0,
"heading": 0,
"weight": 1.0
},
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"count": 10,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/create_random' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"count": 10,
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
echo ""

View File

@ -1,22 +1,57 @@
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/bellande_particle' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/move' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"particle": [0, 0, 0, 1.0],
"movement": {
"rotation1": 45.0,
"translation": 1.0,
"rotation2": -45.0
"particle": {
"x": 0,
"y": 0,
"heading": 0,
"weight": 1.0
},
"rotation1": 45.0,
"translation": 1.0,
"rotation2": -45.0,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/read_markers' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"particle": {
"x": 0,
"y": 0,
"heading": 0,
"weight": 1.0
},
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"count": 10,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
curl -X 'POST' \
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/create_random' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"count": 10,
"world": {
"width": 10.0,
"height": 10.0,
"markers": [[1.0, 1.0]]
},
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}'
echo ""