From 3a9e070ec0ea309d935d6ce92b64ca094addc0c3 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Fri, 2 Apr 2021 22:27:39 +0200 Subject: [PATCH] create economy tree graph --- world/examples/economy_tree.rs | 90 ++++++++++++++++++++++++++++++++++ world/src/site/economy.gv | 68 ------------------------- 2 files changed, 90 insertions(+), 68 deletions(-) create mode 100644 world/examples/economy_tree.rs delete mode 100644 world/src/site/economy.gv diff --git a/world/examples/economy_tree.rs b/world/examples/economy_tree.rs new file mode 100644 index 0000000000..f2fd2b4867 --- /dev/null +++ b/world/examples/economy_tree.rs @@ -0,0 +1,90 @@ +use common::trade::Good; +use std::io::Write; +use veloren_world::site::economy::{self, good_list, Economy}; +//use regex::Regex::replace_all; + +fn good_name(g: Good) -> String { + let res = format!("{:?}", g); + let res = res.replace("(", "_"); + let res = res.replace(")", "_"); + res +} + +fn labor_name(l: economy::Labor) -> String { + let res = format!("{:?}", l); + let res = res.replace(" ", "_"); + res +} + +fn main() -> Result<(), std::io::Error> { + let eco = Economy::default(); + let o = eco.get_orders(); + let p = eco.get_productivity(); + + let mut f = std::fs::File::create("economy.gv")?; + writeln!(f, "digraph economy {{")?; + for i in good_list().iter() { + let color = if economy::direct_use_goods().contains(i) { + "green" + } else { + "orange" + }; + writeln!(f, "{:?} [color=\"{}\"];", good_name(*i), color)?; // shape doubleoctagon ? + } + + writeln!(f, "")?; + writeln!(f, "// Professions")?; + writeln!(f, "Everyone [shape=doubleoctagon];")?; + for i in economy::Labor::list() { + writeln!(f, "{:?} [shape=box];", labor_name(i))?; + } + + writeln!(f, "")?; + writeln!(f, "// Orders")?; + for i in o.iter() { + for j in i.1.iter() { + if i.0.is_some() { + let style = if matches!(j.0, Good::Tools) + || matches!(j.0, Good::Armor) + || matches!(j.0, Good::Potions) + { + ", style=dashed, color=orange" + } else { + "" + }; + writeln!( + f, + "{:?} -> {:?} [label=\"{:.1}\"{}];", + good_name(j.0), + labor_name(i.0.unwrap()), + j.1, + style + )?; + } else { + writeln!( + f, + "{:?} -> Everyone [label=\"{:.1}\"];", + good_name(j.0), + j.1 + )?; + } + } + } + + writeln!(f, "")?; + writeln!(f, "// Products")?; + for i in p.iter() { + for j in i.1.iter() { + writeln!( + f, + "{:?} -> {:?} [label=\"{:.1}\"];", + labor_name(i.0), + good_name(j.0), + j.1 + )?; + } + } + + writeln!(f, "}}")?; + Ok(()) +} diff --git a/world/src/site/economy.gv b/world/src/site/economy.gv deleted file mode 100644 index 9bf2987aa5..0000000000 --- a/world/src/site/economy.gv +++ /dev/null @@ -1,68 +0,0 @@ -digraph economy { -Farmland [color="green"]; -Flour [color="orange"]; -Meat [color="orange"]; -Fish [color="green"]; -Game [color="green"]; -Food [color="orange"]; -Logs [color="green"]; -Wood [color="orange"]; -Rock [color="green"]; -Stone [color="orange"]; -Tools [color="orange"]; -Armor [color="orange"]; -Ingredients [color="green"]; -Potions [color="orange"]; -ControlledArea [color="green", shape=doubleoctagon]; - -// Professions -Everyone [shape=doubleoctagon]; -Farmer [shape=box]; -Lumberjack [shape=box]; -Miner [shape=box]; -Fisher [shape=box]; -Hunter [shape=box]; -Cook [shape=box]; -Brewer [shape=box]; -Blacksmith [shape=box]; -Bladesmith [shape=box]; -Guard [shape=box]; - -// Orders -Food -> Everyone [label= "0.5", style=dashed, weight=4]; -Flour -> Cook [label="12.0", penwidth=2.0]; -Meat -> Cook [label="4.0", penwidth=1.5]; -Wood -> Cook [label="1.5"]; -Stone -> Cook [label="1.0"]; -Logs -> Lumberjack [label="0.5", style=dashed, weight=4]; -Tools -> Lumberjack [label="0.1", color="orange", style=dashed]; -Rock -> Miner [label="0.5", style=dashed, weight=4]; -Tools -> Miner [label="0.1", color="orange", style=dashed]; -Fish -> Fisher [label="4.0", penwidth=1.5, weight=4]; -Tools -> Fisher [label="0.02", color="orange", style=dotted]; -Game -> Hunter [label="1.0", weight=4]; -Tools -> Hunter [label="0.1", color="orange", style=dashed]; -Farmland -> Farmer [label="2.0", weight=4]; -Tools -> Farmer [label="0.05", color="orange", style=dotted]; -Ingredients -> Brewer [label="2.0", penwidth=1.0]; -Flour -> Brewer [label="2.0", penwidth=1.0]; -Ingredients -> Blacksmith [label="8.0", penwidth=2.0]; -Wood -> Blacksmith [label="2.0", penwidth=1.0]; -Ingredients -> Bladesmith [label="4.0", penwidth=1.5]; -Wood -> Bladesmith [label="1.0", penwidth=1.0]; -Armor -> Guard [label="0.5", style=dashed]; -Tools -> Guard [label="0.3", color="orange", style=dashed]; -Potions -> Guard [label="3.0", penwidth=1.5]; - -// Products -Farmer -> Flour [label="2.0"]; -Lumberjack -> Wood [label="0.5", style=dashed]; -Miner -> Stone [label="0.5", style=dashed]; -Fisher -> Meat [label="4.0", penwidth=1.5]; -Hunter -> Meat [label="1.0"]; -Cook -> Food [label="16.0", penwidth=2.0]; -Blacksmith -> Armor [label="4.0"]; -Bladesmith -> Tools [label="2.0", color="orange"]; -Brewer -> Potions [label="6.0"]; -Guard -> ControlledArea [label="50.0", penwidth=2.0]; -}