Ogare65z

affinities

Jan 15th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.46 KB | None | 0 0
  1. import itertools as it
  2. import json
  3. import pathlib
  4. import more_itertools
  5. import random
  6. import csv
  7.  
  8.  
  9. def main():
  10.     recipies = []
  11.     affinities = []
  12.     filepath = pathlib.Path.cwd() / "food combanitions.json"
  13.     with filepath.open("r", encoding ="utf-8") as f:
  14.         try:
  15.             recipies = json.load(f)
  16.             for recipe in recipies:
  17.                 sum = 0
  18.                 for ingredient in recipe:
  19.                     sum = sum + ingredient[1]
  20.  
  21.                 afinityNum = (sum % 138) + 1
  22.                 if afinityNum in affinities:
  23.                     continue
  24.                 affinities.append(afinityNum)
  25.         except json.JSONDecodeError:
  26.             pass
  27.  
  28.     print(f"Size:{len(affinities)}   {affinities}")
  29.     # make breakfast: oven 178, pottery bowl 77,
  30.     # Ogare's shift 92
  31.     # All veggies are chopped and then cooked. Mashed coud be subtituted
  32.     # for chopped but it doesn't make a differnce.
  33.     # roasted is +4, fried is +1
  34.     # material all vegetarian 22
  35.     # all values have 128 added for some ood reason
  36.     # modulo'd all summed values(templateID + material + state + 128) by 138.
  37.     pea = [["roasted pea", 62], ["fried pea", 59]] # 1150
  38.     corn =[["roasted corn", 48], ["fried corn", 45]] # 32
  39.     garlic = [["roasted garlic", 96], ["fried garlic", 93]] # 356
  40.     tomato = [["roasted tomato", 47], ["fried tomato", 44]] # 1135
  41.     peaPods = [["roasted pea pods", 50], ["fried pea pods", 47]] # 1138
  42.     carrot = [["roasted carrot", 45], ["fried carrot", 42]] # 1133
  43.     cucumber = [["roasted cucumber", 21], ["fried cucumber", 18]] #1247
  44.     onion = [["roasted onion", 95], ["fried onion", 92]] # 355
  45.     potato = [["roasted potato", 51], ["fried potato", 48]] #35
  46.  
  47.     # all meat is diced, minced and then fried. meat id 92
  48.     # material types:
  49.     # bear  72, beef    73, canine  74, feline  75, dragon  76, fowl    77,
  50.     # game  78, horse   79, human   80, humanoid    81, insect  82, lamb    83,
  51.     # pork  84, seafood 85, snake   86, tough   87
  52.     # modulo'd all summed values(templateID + material + state + 128) by 138.
  53.     meat = [["fried meat, bear", 17], ["fried meat, canine", 19],
  54.             ["fried meat, feline", 20], ["fried meat, game", 23],
  55.             ["fried meat, horse", 24], ["fried meat, human", 25],
  56.             ["fried meat, humanoid", 26], ["fried meat, insect", 27]]
  57.  
  58.     # herbs
  59.     # chopped and ground are +16, material all vegetarian 22
  60.     # modulo'd all summed values(templateID + material + state + 128) by 138.
  61.     lovage = [["chopped lovage", 105], ["lovage", 89]]# 353
  62.     rosemary =  [["chopped rosemary", 115], ["rosemary", 99]]# 363
  63.     basil = [["chopped basil", 111], ["basil", 95]] # 359
  64.     belladonna = [["chopped belladonna", 113], ["belladonna", 97]] # 361
  65.     fennelSeed = [["ground fennel seed", 75], ["fennel seed", 59]] # 1151
  66.     mint = [["chopped mintmint", 54], ["mint", 38]] # 1130
  67.     oregano = [["chopped oregano", 109], ["oregano", 93]] # 357
  68.     parsley = [["chopped parsley", 110], ["parsley", 94]] # 358
  69.     sage = [["chopped sage", 106], ["sage", 90]] # 354
  70.     thyme = [["chopped thyme", 112], ["thyme", 96]] # 360
  71.     cumin = [["ground cumin", 64], ["cumin", 48]] # 1140
  72.     paprika =  [["ground paprika", 67], ["paprika", 51]] # 1143
  73.     turmeric = [["ground turmeric", 68], ["turmeric", 52]] # 1144
  74.     ginger = [["ground ginger", 65], ["ginger", 49]] # 1141
  75.     herbs = (lovage, rosemary, basil, belladonna, fennelSeed, mint, oregano,
  76.             parsley, sage, thyme, cumin, paprika, turmeric, ginger)
  77.     herbSample = []
  78.     herbGroups = list(it.combinations_with_replacement(
  79.                         (0,1,2,3,4,5,6,7,8,9,10,11,12,13), 2))
  80.     for herbIndexs in herbGroups:
  81.         ingredients = [pea, corn, garlic, tomato, peaPods, carrot, cucumber, onion, potato,
  82.                 meat]
  83.         for index in herbIndexs:
  84.             ingredients.append(herbs[index])
  85.         simulatedRecipies = list(it.product(*ingredients))
  86.         for recipe in simulatedRecipies:
  87.             sum = 0
  88.             for ingredient in recipe:
  89.                 sum = sum + ingredient[1]
  90.  
  91.             afinityNum = (sum % 138) + 1
  92.             if afinityNum in affinities:
  93.                 continue
  94.             recipies.append(recipe)
  95.             affinities.append(afinityNum)
  96.             with filepath.open("w", encoding ="utf-8") as f:
  97.                 json.dump(recipies, f)
  98.             print(f"Size:{len(affinities)}   {affinities}")
  99.  
  100.     filepath1 = pathlib.Path.cwd() / "food combanitions1.csv"
  101.     with filepath1.open("w", encoding ="utf-8") as f:
  102.         for r in recipies:
  103.             if len(r) == 11:
  104.                 csvStr = [
  105.                 f"{r[0][0]}, {r[0][1]}, {r[1][0]}, {r[1][1]}, {r[2][0]}, ",
  106.                 f"{r[2][1]}, {r[3][0]}, {r[3][1]}, {r[4][0]}, {r[4][1]}, ",
  107.                 f"{r[5][0]}, {r[5][1]}, {r[6][0]}, {r[6][1]}, {r[7][0]}, ",
  108.                 f"{r[7][1]}, {r[8][0]}, {r[8][1]}, {r[9][0]}, {r[9][1]}, ",
  109.                 f"{r[10][0]}, {r[10][1]}\r"]
  110.                 f.write("".join(csvStr))
  111.             if len(r) == 12:
  112.                 csvStr = [
  113.                 f"{r[0][0]}, {r[0][1]}, {r[1][0]}, {r[1][1]}, {r[2][0]}, ",
  114.                 f"{r[2][1]}, {r[3][0]}, {r[3][1]}, {r[4][0]}, {r[4][1]}, ",
  115.                 f"{r[5][0]}, {r[5][1]}, {r[6][0]}, {r[6][1]}, {r[7][0]}, ",
  116.                 f"{r[7][1]}, {r[8][0]}, {r[8][1]}, {r[9][0]}, {r[9][1]}, ",
  117.                 f"{r[10][0]}, {r[10][1]}, {r[11][0]}, {r[11][1]}\r"]
  118.                 f.write("".join(csvStr))
  119.  
  120. main()
Add Comment
Please, Sign In to add comment