import pyoe2_craftpath as pc
import json
from pathlib import Path
COE_MAP = {
"./cache/coe2.json": "https://www.craftofexile.com/json/poe2/main/poec_data.json",
}
ECONOMY_MAP = {
"./cache/pn_abyss.json": "https://poe.ninja/poe2/api/economy/exchange/current/overview?league=Standard&type=Abyss",
"./cache/pn_currency.json": "https://poe.ninja/poe2/api/economy/exchange/current/overview?league=Standard&type=Currency",
"./cache/pn_essences.json": "https://poe.ninja/poe2/api/economy/exchange/current/overview?league=Standard&type=Essences",
"./cache/pn_ritual.json": "https://poe.ninja/poe2/api/economy/exchange/current/overview?league=Standard&type=Ritual"
}
def main():
raw_fetched_responses_coe = pc.retrieve_contents_from_urls_with_cache_unstable_order(
cache_url_map=COE_MAP,
max_cache_duration_in_sec=60 * 60 * 24
)
raw_fetched_responses_economy = pc.retrieve_contents_from_urls_with_cache_unstable_order(
cache_url_map=ECONOMY_MAP,
max_cache_duration_in_sec=60 * 60
)
coe_data = pc.CraftOfExileItemInfoProvider.parse_from_json(
raw_fetched_responses_coe[0])
economy = pc.PoeNinjaMarketPriceProvider.parse_from_json_list(
raw_fetched_responses_economy)
with open('example_items/start_item_magic_1_affix_bow.json', 'r', encoding='utf-8') as f:
start_raw_string = f.read()
with open('example_items/target_item_desecrated_essence_rare_4_affix_bow.json', 'r', encoding='utf-8') as f:
end_raw_string = f.read()
start_item = pc.CraftOfExileEmulatorItemImport.parse_itemsnapshot_from_string(
start_raw_string, coe_data)
end_item = pc.CraftOfExileEmulatorItemImport.parse_itemsnapshot_from_string(
end_raw_string, coe_data)
print(start_item.to_pretty_string(coe_data, True))
print(end_item.to_pretty_string(coe_data, True))
group_chance_instance = pc.MatrixBuilderPreset.HappyPathMatrixBuilder.get_instance()
print(group_chance_instance)
calc = pc.Calculator.generate_item_matrix(
starting_item=start_item,
target=end_item,
item_provider=coe_data,
market_info=economy,
matrix_builder=pc.MatrixBuilderPreset.HappyPathMatrixBuilder.get_instance())
print("Matrix contains", calc.matrix.__len__(), "items")
unique_path_chance_instance = pc.StatisticAnalyzerPathPreset.UniquePathChance.get_instance()
print(unique_path_chance_instance)
unique_path_chance_res = calc.calculate_statistics(
item_provider=coe_data,
market_provider=economy,
max_routes=5,
max_ram_in_bytes=1000000000, statistic_analyzer=unique_path_chance_instance)
unique_path_efficiency_instance = pc.StatisticAnalyzerPathPreset.UniquePathEfficiency.get_instance()
print(unique_path_efficiency_instance)
unique_path_efficiency_res = calc.calculate_statistics(
item_provider=coe_data,
market_provider=economy,
max_routes=5,
max_ram_in_bytes=1000000000, statistic_analyzer=unique_path_efficiency_instance)
unique_path_cost_instance = pc.StatisticAnalyzerPathPreset.UniquePathCost.get_instance()
print(unique_path_cost_instance)
unique_path_cost_res = calc.calculate_statistics(
item_provider=coe_data,
market_provider=economy,
max_routes=5,
max_ram_in_bytes=1000000000, statistic_analyzer=unique_path_cost_instance)
group_chance_instance = pc.StatisticAnalyzerCurrencyGroupPreset.CurrencyGroupChance.get_instance()
groups = calc.calculate_statistics_currency_group(
item_provider=coe_data,
market_provider=economy,
max_ram_in_bytes=1000000000, statistic_analyzer=group_chance_instance
)
for index, g in enumerate(groups[:3]):
print("Group #", index + 1, "-", g.to_pretty_string(
item_provider=coe_data,
market_provider=economy,
statistic_analyzer=group_chance_instance
))
for (results, analyzer_instance) in [
(unique_path_chance_res, unique_path_chance_instance),
(unique_path_efficiency_res, unique_path_efficiency_instance),
(unique_path_cost_res, unique_path_chance_instance)
]:
for route in results[:3]:
group = route.locate_group(calculated_groups=groups)
if group is not None:
print("Manual lookup group chance: ", group.chance)
pretty = route.to_pretty_string(
item_provider=coe_data,
market_provider=economy,
calculator=calc,
groups=groups,
statistic_analyzer=analyzer_instance,
)
print(pretty)
if __name__ == "__main__":
main()