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. "c7987e6fd14f326985d14e11c43b1f998b361c6b" and "16a4a5b2fae570f137479fd89c2f0156fa46b49e" have entirely different histories.
c7987e6fd1
...
16a4a5b2fa
76
calc.py
76
calc.py
@ -62,21 +62,12 @@ def sround(num, parts):
|
|||||||
num -= 1
|
num -= 1
|
||||||
return num
|
return num
|
||||||
|
|
||||||
# Поиск элемента в списке рецепта
|
|
||||||
def ll_find(ll, pat):
|
|
||||||
find = False
|
|
||||||
for i in range(len(ll)):
|
|
||||||
if ll[i][0] == pat:
|
|
||||||
return i
|
|
||||||
return None
|
|
||||||
|
|
||||||
def calc(el, amount, main = False):
|
def calc(el, amount, main = False):
|
||||||
global db, recipe
|
global db, recipe
|
||||||
if main:
|
if main:
|
||||||
recipe = []
|
recipe = {}
|
||||||
|
|
||||||
comps = db[el][3:] # Получаем составные
|
comps = db[el][2:] # Получаем составные
|
||||||
heat = db[el][2]
|
|
||||||
out = db[el][0] #Количество на выходе
|
out = db[el][0] #Количество на выходе
|
||||||
|
|
||||||
# Считаем количество частей
|
# Считаем количество частей
|
||||||
@ -88,12 +79,15 @@ def calc(el, amount, main = False):
|
|||||||
while out < parts:
|
while out < parts:
|
||||||
# Предварительная часть
|
# Предварительная часть
|
||||||
part = sround(amount/parts, parts)
|
part = sround(amount/parts, parts)
|
||||||
|
#print(el, ': ',out,' < ', parts)
|
||||||
# Если итоговый объём <= входного объёма
|
# Если итоговый объём <= входного объёма
|
||||||
if (parts+1)*part <= amount:
|
if (parts+1)*part <= amount:
|
||||||
parts += 1
|
parts += 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# parts = out
|
||||||
|
|
||||||
# Считаем 1 часть
|
# Считаем 1 часть
|
||||||
part = sround(amount/parts, parts)
|
part = sround(amount/parts, parts)
|
||||||
|
|
||||||
@ -101,67 +95,30 @@ def calc(el, amount, main = False):
|
|||||||
for i in comps:
|
for i in comps:
|
||||||
if i[0] in db:
|
if i[0] in db:
|
||||||
lpart = calc(i[0], part*i[1])
|
lpart = calc(i[0], part*i[1])
|
||||||
# Если наша часть больше чем составная
|
|
||||||
if lpart < part:
|
|
||||||
part = lpart
|
|
||||||
# lpart - количество составного в итоге
|
# lpart - количество составного в итоге
|
||||||
# 50/3, часть = 16, ИТОГ: 16*3=48 <
|
# 50/3, часть = 16, ИТОГ: 16*3=48 <
|
||||||
|
try:
|
||||||
if heat and not main:
|
if lpart < part:
|
||||||
recipe = [['heat']] + recipe
|
print("LPART: ",lpart)
|
||||||
if heat and main:
|
part = lpart
|
||||||
recipe.append(['heat'])
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Перебираем элементарные вещества
|
# Перебираем элементарные вещества
|
||||||
for i in comps:
|
for i in comps:
|
||||||
if i[0] not in db:
|
if i[0] not in db:
|
||||||
if i[0] == 'Плазма':
|
if i[0] == 'Плазма':
|
||||||
if ll_find(recipe, 'Плазма') == None:
|
recipe[i[0]] = 1
|
||||||
recipe = [[i[0], 1]] + recipe
|
|
||||||
else:
|
else:
|
||||||
if heat:
|
if i[0] not in recipe:
|
||||||
recipe = [[i[0], part*i[1]]] + recipe
|
recipe[i[0]] = part*i[1]
|
||||||
else:
|
else:
|
||||||
recipe.append([i[0], part*i[1]])
|
recipe[i[0]] += part*i[1]
|
||||||
|
|
||||||
# ЕСЛИ ЕСТЬ БАГИ ВЕРОЯТНО ЭТО ТУТ
|
|
||||||
# Если нету плазмы - соединяем вещества
|
|
||||||
if main:
|
|
||||||
if ll_find(recipe, 'Плазма') == None and not heat:
|
|
||||||
print('START: ', recipe)
|
|
||||||
new_recipe = []
|
|
||||||
#for i in recipe:
|
|
||||||
while recipe != []:
|
|
||||||
print("ORIG:", recipe)
|
|
||||||
el = recipe[0]
|
|
||||||
new_recipe.append(el)
|
|
||||||
del recipe[0]
|
|
||||||
|
|
||||||
# Текущий id
|
|
||||||
id = ll_find(new_recipe, el[0])
|
|
||||||
|
|
||||||
# Если есть ещё такой элемент
|
|
||||||
while ll_find(recipe, el[0]):
|
|
||||||
same_id = ll_find(recipe, el[0])
|
|
||||||
print('OLD: ', new_recipe[id][1])
|
|
||||||
new_recipe[id][1] += recipe[same_id][1]
|
|
||||||
print('NEW: ', new_recipe[id][1] + recipe[same_id][1])
|
|
||||||
# Удаляем этот элемент
|
|
||||||
#recipe.pop( same_id )
|
|
||||||
del recipe[same_id]
|
|
||||||
|
|
||||||
print("NEW:", new_recipe)
|
|
||||||
|
|
||||||
|
|
||||||
recipe = new_recipe
|
|
||||||
|
|
||||||
|
|
||||||
if main:
|
if main:
|
||||||
print('PART: ', part)
|
print('PART: ', part)
|
||||||
return [recipe, out*part]
|
return [recipe, out*part]
|
||||||
else:
|
else:
|
||||||
print(recipe)
|
|
||||||
print(el)
|
|
||||||
print('PART: ', part)
|
print('PART: ', part)
|
||||||
return part*parts
|
return part*parts
|
||||||
|
|
||||||
@ -169,6 +126,3 @@ def calc(el, amount, main = False):
|
|||||||
#print( calc("Бикаридин", 100, True))
|
#print( calc("Бикаридин", 100, True))
|
||||||
#print( calc("Диловен", 100, True))
|
#print( calc("Диловен", 100, True))
|
||||||
#print( calc("Эфедрин", 100, True))
|
#print( calc("Эфедрин", 100, True))
|
||||||
#print( calc("Криоксадон", 100, True) )
|
|
||||||
#print( calc("Гидроксид", 100, True) )
|
|
||||||
#print( calc("Пунктураз", 100, True) )
|
|
||||||
|
6
site.py
6
site.py
@ -143,11 +143,7 @@ def update_output(reaction, amount):
|
|||||||
# Форматирование для HTML
|
# Форматирование для HTML
|
||||||
result = []
|
result = []
|
||||||
for i in comps:
|
for i in comps:
|
||||||
if i[0] == 'heat':
|
result.append( html.Div(i + ': ' + str(comps[i])
|
||||||
result.append( html.Div('Нагреть!'
|
|
||||||
, style={'background-color': 'rgb(115, 62, 157)', 'color': '#ffffff', 'margin-top': 10, 'border-radius': 10, 'padding': 15, 'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) )
|
|
||||||
else:
|
|
||||||
result.append( html.Div(i[0] + ': ' + str(i[1])
|
|
||||||
, style={'background-color': 'rgb(213, 193, 86)', 'color': '#ffffff', 'margin-top': 10, 'border-radius': 10, 'padding': 15, 'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) )
|
, style={'background-color': 'rgb(213, 193, 86)', 'color': '#ffffff', 'margin-top': 10, 'border-radius': 10, 'padding': 15, 'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) )
|
||||||
|
|
||||||
# Выходное вещество
|
# Выходное вещество
|
||||||
|
Loading…
Reference in New Issue
Block a user