Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools as it
- import json
- import pathlib
- from dataclasses import dataclass
- @dataclass
- class Skills:
- id: int
- name: str
- @staticmethod
- def populate(file_name):
- filepath_json = pathlib.Path.cwd() / f"{file_name}"
- json_data = {}
- if filepath_json.exists():
- with filepath_json.open("r", encoding="utf-8") as f:
- try:
- json_data = json.load(f)
- except json.JSONDecodeError:
- pass
- _skills = []
- for i in json_data:
- _skills.append(Skills(int(i["id"]), i["name"]))
- return _skills
- else:
- with filepath_json. open("w", encoding="utf-8"):
- pass
- return []
- skills = Skills.populate("skills.json")
- def get_skill_name(_id):
- for v in skills:
- if v.id == _id:
- return v.name
- @dataclass
- class FoodStates:
- name: str
- modifier: int
- @staticmethod
- def populate(file_name):
- filepath_json = pathlib.Path.cwd() / f"{file_name}"
- json_data = {}
- if filepath_json.exists():
- with filepath_json.open("r", encoding="utf-8") as f:
- try:
- json_data = json.load(f)
- except json.JSONDecodeError:
- pass
- _states = []
- for i in json_data:
- _states.append(Skills(i["name"], i["modifier"]))
- return _states
- else:
- with filepath_json. open("w", encoding="utf-8"):
- pass
- return []
- class Recipe:
- # init method or constructor
- def __init__(self, file_name):
- self.fileName = file_name
- self.filepathJson = pathlib.Path.cwd() / self.fileName / f"{self.fileName}.json"
- self.matches = {}
- self.match_recipes = []
- if self.filepathJson.exists():
- with self.filepathJson.open("r", encoding="utf-8") as f:
- try:
- self.matches = json.load(f)
- except json.JSONDecodeError:
- pass
- else:
- if (not pathlib.Path(pathlib.Path.cwd() / self.fileName).exists() or
- not pathlib.Path(pathlib.Path.cwd() / self.fileName).is_dir()):
- pathlib.Path(pathlib.Path.cwd() / self.fileName).mkdir()
- self.recipe_length = 0
- for values in self.matches.values():
- if len(values) > self.recipe_length:
- self.recipe_length = len(values)
- def simulate(self, ingredients):
- simulated_recipes = list(it.product(*ingredients))
- for recipe in simulated_recipes:
- _sum = 0
- for ingredient in recipe:
- _sum = _sum + ingredient[1]
- affinity_num = (_sum % 138) + 1
- if str(affinity_num) in self.matches.keys():
- continue
- if len(recipe) > self.recipe_length:
- self.recipe_length = len(recipe)
- self.matches[str(affinity_num)] = recipe
- # print(f"Size:{len(self.matches.keys())} {self.matches.keys()}")
- with self.filepathJson.open("w", encoding="utf-8") as f:
- json.dump(self.matches, f)
- filepath_csv = pathlib.Path.cwd() / self.fileName / f"{self.fileName}.csv"
- with filepath_csv.open("w", encoding="utf-8") as f:
- for index in range(1, 139):
- if str(index) not in self.matches.keys():
- f.write(f"{get_skill_name(index)}, {index}\n")
- else:
- v = self.matches[str(index)]
- csv_str = ""
- for value in v:
- csv_str = csv_str + f"{value[0]}, {value[1]}, "
- csv_str = csv_str + f"{get_skill_name(index)}, {index}\n"
- f.write(csv_str)
- def get_options_affinity(self, ingredients, affinity_num):
- simulated_recipes = list(it.product(*ingredients))
- for recipe in simulated_recipes:
- ingredient_sum = 0
- for ingredient in recipe:
- ingredient_sum = ingredient_sum + ingredient[1]
- _affinity_num = (ingredient_sum % 138) + 1
- if _affinity_num != affinity_num:
- continue
- self.match_recipes.append(recipe)
- filepath_match = (pathlib.Path.cwd() / self.fileName /
- f"{get_skill_name(affinity_num)}_{affinity_num}.csv")
- with filepath_match.open("w", encoding="utf-8") as f:
- v = self.match_recipes
- csv_str = ""
- for value in v:
- csv_str = csv_str + f"{value[0]}, {value[1]}, "
- csv_str = csv_str + f"\n"
- f.write(csv_str)
- def unfermented_moonshine():
- toon = [["Ogare", 92]]
- cookers = [["oven", 178]]
- containers = [["cauldron", 351]]
- water = [["water", 6]]
- sugar = [["sugar", 47]]
- grain = [["wheat", 25], ["barley", 23], ["oat", 25], ["rye", 23]]
- pea = [["roasted pea", 62], ["fried pea", 59]]
- corn = [["roasted corn", 48], ["fried corn", 45]]
- garlic = [["roasted garlic", 96], ["fried garlic", 93]]
- tomato = [["roasted tomato", 47], ["fried tomato", 44]]
- pea_pods = [["roasted pea pods", 50], ["fried pea pods", 47]]
- carrot = [["roasted carrot", 45], ["fried carrot", 42]]
- cucumber = [["roasted cucumber", 21], ["fried cucumber", 18]]
- onion = [["roasted onion", 95], ["fried onion", 92]]
- potato = [["roasted potato", 51], ["fried potato", 48]]
- lettuce = [["roasted lettuce", 49], ["fried lettuce", 46]]
- pumpkin = [["roasted pumpkin", 49], ["fried pumpkin", 46]]
- cabbage = [["roasted cabbage", 46], ["fried cabbage", 43]]
- ingredients = [toon, cookers, containers, water, sugar, grain, grain, grain, grain, pea, corn, garlic, tomato,
- pea_pods, carrot, carrot, cucumber, onion, onion, potato, potato, lettuce, pumpkin, pumpkin, cabbage]
- unf_moonshine_recipes = Recipe("unf moonshine")
- unf_moonshine_recipes.simulate(ingredients)
- if __name__ == '__main__':
- unfermented_moonshine()
Add Comment
Please, Sign In to add comment