pyoe2_craftpath/utils/
pretty_print_utils.rs1use num_format::{Locale, ToFormattedString};
2
3use crate::api::{
4 calculator::{DynStatisticAnalyzerCurrencyGroups, GroupRoute, StatisticAnalyzerCurrencyGroups},
5 provider::{
6 item_info::ItemInfoProvider,
7 market_prices::{MarketPriceProvider, PriceInDivines, PriceKind},
8 },
9};
10use std::fmt::Write;
11
12impl GroupRoute {
13 pub fn to_pretty_string(
14 &self,
15 item_provider: &ItemInfoProvider,
16 market_provider: &MarketPriceProvider,
17 grouped_statistic_analyzer: &dyn StatisticAnalyzerCurrencyGroups,
18 ) -> String {
19 let mut out = String::new();
20
21 let cost_per_1 = grouped_statistic_analyzer.calculate_cost_per_craft(
22 &self.group,
23 &item_provider,
24 &market_provider,
25 );
26
27 let tries_for_60 = ((((1.0_f64 - 0.6_f64).ln()
28 / (1.0_f64 - self.chance.get_raw_value()).ln())
29 .ceil()) as u64)
30 .max(1);
31
32 let cost_per_60 =
33 PriceInDivines::new((tries_for_60 as f64) * cost_per_1.get_divine_value());
34
35 writeln!(
36 &mut out,
37 "Group Chance: {:.5}% | Unique Routes: {} | Tries needed for 60%: {} | Cost per Craft: {} | Cost for 60%: {}{}",
38 self.chance.get_raw_value() * 100_f64,
39 self.amount_subpaths.get_raw_value().to_formatted_string(&Locale::en),
40 tries_for_60.to_formatted_string(&Locale::en),
41 format!(
42 "{} EX",
43 (market_provider
44 .currency_convert(&cost_per_1, &PriceKind::Exalted)
45 .ceil() as u64)
46 .to_formatted_string(&Locale::en)
47 ),
48 format!(
49 "{} EX",
50 (market_provider
51 .currency_convert(&cost_per_60, &PriceKind::Exalted)
52 .ceil() as u64)
53 .to_formatted_string(&Locale::en)
54 ),
55 match grouped_statistic_analyzer.format_display_more_info(
56 &self,
57 &item_provider,
58 &market_provider
59 ) {
60 Some(e) => e,
61 None => "".to_string(),
62 }
63 )
64 .unwrap();
65
66 for (index, currency_list) in self.group.iter().enumerate() {
67 let index_weight = grouped_statistic_analyzer.calculate_chance_for_group_step_index(
68 &self.unique_route_weights,
69 self.amount_subpaths.clone(),
70 index,
71 );
72
73 writeln!(
74 &mut out,
75 "{}. {} [ROUGH (!) avg. chance: {:.5}%]",
76 index + 1,
77 currency_list
78 .list
79 .iter()
80 .map(|e| {
81 let currency_value = market_provider
82 .try_lookup_currency_in_divines_default_if_fail(&e, &item_provider);
83 let currency_value_ex = market_provider
84 .currency_convert(¤cy_value, &PriceKind::Exalted)
85 .ceil() as u32;
86
87 format!(
88 "{} ({} EX)",
89 e.get_item_name(&item_provider),
90 currency_value_ex.to_formatted_string(&Locale::en)
91 )
92 })
93 .collect::<Vec<String>>()
94 .join(" + "),
95 index_weight.get_raw_value() * 100_f64
96 )
97 .unwrap();
98 }
99
100 out
101 }
102}
103
104#[cfg(feature = "python")]
105#[cfg_attr(feature = "python", pyo3_stub_gen::derive::gen_stub_pymethods)]
106#[cfg_attr(feature = "python", pyo3::prelude::pymethods)]
107impl GroupRoute {
108 #[pyo3(name = "to_pretty_string")]
109 pub fn to_pretty_string_py(
110 &self,
111 item_provider: &ItemInfoProvider,
112 market_provider: &MarketPriceProvider,
113 statistic_analyzer: &DynStatisticAnalyzerCurrencyGroups,
114 ) -> String {
115 self.to_pretty_string(
116 item_provider,
117 market_provider,
118 statistic_analyzer.0.as_ref(),
119 )
120 }
121}