This commit is contained in:
JMARyA 2024-08-27 23:33:09 +02:00
parent 0be7fff77d
commit 74b07a0ea3
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
8 changed files with 107 additions and 10 deletions

View file

@ -1,10 +1,14 @@
# CDB
cdb is a powerful software tool designed to automate economic calculations by managing a database of items, their relations, quantities, and tracking demands. This tool facilitates the estimation of demand and supply, aiding in making informed decisions on production, imports, and purchases to meet market needs efficiently.
CDB is an inventory database for economic planning. It can manage your inventory and log supply and demand.
What does the `C` in `CDB` stand for? You can choose:
- eConomicDB
- CommunismDB
- CraftDB
## Features
- Data Input: Start with a root dataset of items and their relations, including details such as item names, categories, and dependencies.
- Inventory Tracking: Record and update the quantities of items within the database based on real-world transactions, production, and consumption.
- Demand Tracking: Monitor the demand for each item, keeping track of how many units are required over time.
- Supply Calculation: Automatically calculate and update the estimated supply needed to meet the current demand.
- Automated Economics: Utilize the collected data to automate economic decisions, determining optimal production levels, imports, and purchases to fulfill market needs.
- Flexible Reporting: Generate reports and visualizations to analyze the economic trends
- ItemDB: Root Dataset, Items, Variants, Categories
- Inventory: Transactions, Supply, Demand
- Planned Supply: Calculate Supply Needs based on Demand
- Automation
- Stats: Statistics, Graphs, Reports

View file

@ -1,3 +1,3 @@
# Transaction
A transaction can be either a supply, demand or batch transaction.
A Transaction represents an actual instance of an Item. This is a one to one mapping to a physical Variant of an Item. It can be consumed either manually or by a Process.
This makes individual physical goods traceable.

23
schema/item.json Normal file
View file

@ -0,0 +1,23 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "Item",
"description": "Item Metadata",
"properties": {
"name": {
"type": "string",
"title": "Item Name",
"description": "The name of the Item"
},
"variants": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"title": "Item Variant",
"description": "A Variant of an Item",
"properties": {}
}
}
}
}

33
schema/process.json Normal file
View file

@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Process",
"description": "Process Description",
"properties": {
"name": {
"type": "string",
"title": "Process Name",
"description": "The name of the Process"
},
"depends": {
"type": "array",
"title": "Process Dependencies",
"description": "List of Items a Process depends on",
"items": {
"type": "string"
}
},
"next": {
"type": "string",
"title": "Next Process",
"description": "The Process that succeeds this one."
},
"produces": {
"type": "array",
"title": "Produced Items",
"description": "Items this Process will produce",
"items": {
"type": "string"
}
}
}
}

View file

@ -3,6 +3,7 @@ use rocket::{http::Method, launch};
mod db;
mod item;
mod process;
mod routes;
mod transaction;
mod variant;
@ -51,7 +52,8 @@ async fn rocket() -> _ {
routes::item::supply_route,
routes::item::demand_route,
routes::item::transaction_route,
routes::item::inventory_route
routes::item::inventory_route,
routes::item::variant_stat_route
],
)
.manage(itemdb)

8
src/process.rs Normal file
View file

@ -0,0 +1,8 @@
use std::collections::HashMap;
pub struct ProcessInfo {
pub name: String,
pub depends: HashMap<String, i64>,
pub next: Option<String>,
pub produces: Option<Vec<String>>,
}

View file

@ -76,3 +76,18 @@ pub async fn inventory_route(
.map(|x| x.api_json())
.collect::<Vec<_>>()))
}
#[get("/item/<item_id>/<variant_id>/stat")]
pub async fn variant_stat_route(
item_id: &str,
variant_id: &str,
itemdb: &State<ItemDB>,
) -> FallibleApiResponse {
let variant = itemdb
.get_item(item_id)
.ok_or_else(item_does_not_exist_error)?
.variant(variant_id)
.ok_or_else(variant_does_not_exist_error)?;
Ok(variant.stat().await)
}

View file

@ -128,6 +128,18 @@ impl Variant {
t._id
}
pub async fn stat(&self) -> serde_json::Value {
let active_transactions = self.inventory().await;
// fix : ignores currency
let total_price: f64 = active_transactions.iter().map(|x| x.price.value).sum();
json!({
"amount": active_transactions.len(),
"total_price": total_price
})
}
pub fn api_json(&self) -> serde_json::Value {
json!({
"item": self.item,