mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-02-08 09:07:38 +00:00
Compare commits
No commits in common. "3d6074260aefd6a2c12d671091b69110ddb10e9d" and "22b2a0ec27b1ff5d95fb8885adc6823f50790ad0" have entirely different histories.
3d6074260a
...
22b2a0ec27
@ -1,12 +1,10 @@
|
|||||||
global expanded ; expanded = {}
|
def expand_recipe(recipe, recipes):
|
||||||
def expand_recipe(recipe, recipes, main = False):
|
|
||||||
global expanded
|
global expanded
|
||||||
|
|
||||||
ok = False
|
ok = False
|
||||||
part = 1 # Одна часть
|
part = 1 # Одна часть
|
||||||
while not ok:
|
while not ok:
|
||||||
ok = True
|
ok = True
|
||||||
min_vol = 0 # Объём мин. рецепта (вход)
|
|
||||||
# Перебираем элементы
|
# Перебираем элементы
|
||||||
for el in recipe:
|
for el in recipe:
|
||||||
# Если составное
|
# Если составное
|
||||||
@ -18,35 +16,24 @@ def expand_recipe(recipe, recipes, main = False):
|
|||||||
expanded = {}
|
expanded = {}
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
min_vol += expand_recipe(recipes[el].comps, recipes)
|
expand_recipe(recipes[el].comps, recipes)
|
||||||
else:
|
else:
|
||||||
if el in expanded:
|
if el in expanded:
|
||||||
expanded[el] += recipe[el]*part
|
expanded[el] += recipe[el]*part
|
||||||
else:
|
else:
|
||||||
expanded[el] = recipe[el]*part
|
expanded[el] = recipe[el]*part
|
||||||
|
|
||||||
min_vol += recipe[el]*part
|
|
||||||
|
|
||||||
if main:
|
|
||||||
return expanded, min_vol, part
|
|
||||||
else:
|
|
||||||
return min_vol
|
|
||||||
|
|
||||||
def calc(element, amount, recipes):
|
def calc(element, amount, recipes):
|
||||||
# Получаем характеристику элемента
|
# TODO: Пока только выводит расширенную версию рецепта
|
||||||
recipe, out = recipes[element].comps, recipes[element].out
|
recipe, out = recipes[element].comps, recipes[element].out
|
||||||
# Расчитываем минимальный рецепт
|
|
||||||
expanded, vol, part = expand_recipe(recipe, recipes, True)
|
|
||||||
|
|
||||||
# Домнажаем на сколько нужно
|
global expanded
|
||||||
need = amount//vol
|
expanded = {}
|
||||||
for i in expanded:
|
expand_recipe(recipe, recipes)
|
||||||
expanded[i] = expanded[i]*need
|
|
||||||
out = part*out*need
|
|
||||||
|
|
||||||
return expanded, out
|
return expanded
|
||||||
|
|
||||||
|
|
||||||
from parse import *
|
from parse import *
|
||||||
#print( load_recipes() )
|
#print( load_recipes() )
|
||||||
print( calc('Leporazine', 100, load_recipes()) )
|
print( calc('Dylovene', 100, load_recipes()) )
|
||||||
|
@ -29,30 +29,3 @@ def load_recipes(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space
|
|||||||
out = value
|
out = value
|
||||||
recipes[product] = reag__(category=category, comps=comps, out=out)
|
recipes[product] = reag__(category=category, comps=comps, out=out)
|
||||||
return recipes
|
return recipes
|
||||||
|
|
||||||
def localize(ftl = parse_ftl()):
|
|
||||||
recipes = load_recipes()
|
|
||||||
for k, v in list(recipes.items()):
|
|
||||||
for word in ftl:
|
|
||||||
if k.lower() == word:
|
|
||||||
new_key = ftl[word].capitalize()
|
|
||||||
recipes[new_key] = recipes.pop(k)
|
|
||||||
for k1, v1 in list(recipes[new_key].comps.items()):
|
|
||||||
for word1 in ftl:
|
|
||||||
if k1.lower() == word1:
|
|
||||||
new_key1 = ftl[word1]
|
|
||||||
recipes[new_key].comps[new_key1] = recipes[new_key].comps.pop(k1)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
for k1, v1 in list(recipes[k].comps.items()):
|
|
||||||
for word1 in ftl:
|
|
||||||
if k1.lower() == word1:
|
|
||||||
new_key1 = ftl[word1].capitalize()
|
|
||||||
recipes[k].comps[new_key1] = recipes[k].comps.pop(k1)
|
|
||||||
except:
|
|
||||||
for k1, v1 in list(recipes[new_key].comps.items()):
|
|
||||||
for word1 in ftl:
|
|
||||||
if k1.lower() == word1:
|
|
||||||
new_key1 = ftl[word1].capitalize()
|
|
||||||
recipes[new_key].comps[new_key1] = recipes[new_key].comps.pop(k1)
|
|
||||||
return recipes
|
|
Loading…
Reference in New Issue
Block a user