mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-02-08 01:01:18 +00:00
up
This commit is contained in:
parent
c7987e6fd1
commit
88571e318a
288
calc.py
288
calc.py
@ -1,6 +1,10 @@
|
|||||||
from db import *
|
from db import *
|
||||||
from math import floor
|
from math import floor
|
||||||
|
|
||||||
|
# DEBUG
|
||||||
|
from icecream import ic
|
||||||
|
ic.disable()
|
||||||
|
|
||||||
db = read_db()
|
db = read_db()
|
||||||
|
|
||||||
# Составные
|
# Составные
|
||||||
@ -8,162 +12,173 @@ recipe = {}
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
def sround(num, parts):
|
def sround(num, parts):
|
||||||
acc = [1,2,3,4,5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
|
acc = [1,2,3,4,5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
|
||||||
amount = num*parts
|
amount = num*parts
|
||||||
|
|
||||||
# Ловим частые повторения
|
# Ловим частые повторения
|
||||||
tries = 0
|
tries = 0
|
||||||
|
|
||||||
# Пока не вывели хорошее число
|
# Пока не вывели хорошее число
|
||||||
good = False
|
good = False
|
||||||
while not good:
|
while not good:
|
||||||
num = floor(num)
|
num = floor(num)
|
||||||
print(good, ' ', num)
|
ic(good, ' ', num)
|
||||||
st = 1 ; good = True
|
st = 1 ; good = True
|
||||||
# Перебираем различное количество частей
|
# Перебираем различное количество частей
|
||||||
while st < parts:
|
while st < parts:
|
||||||
# Если в допустимых значениях
|
# Если в допустимых значениях
|
||||||
if num*st in acc:
|
if num*st in acc:
|
||||||
st += 1
|
st += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
good = False
|
good = False
|
||||||
# Перебираем допустимые значения
|
# Перебираем допустимые значения
|
||||||
for i in acc:
|
for i in acc:
|
||||||
if abs(i - num*st) <= 2:
|
if abs(i - num*st) <= 2:
|
||||||
num = i
|
num = i
|
||||||
break
|
break
|
||||||
st += 1
|
st += 1
|
||||||
|
|
||||||
# Ловим частые повторения
|
# Ловим частые повторения
|
||||||
tries += 1
|
tries += 1
|
||||||
if tries > 500:
|
if tries > 500:
|
||||||
return sround1(num, parts)
|
return sround1(num, parts)
|
||||||
|
|
||||||
if num*parts > amount:
|
if num*parts > amount:
|
||||||
return sround1(num, parts)
|
return sround1(num, parts)
|
||||||
|
|
||||||
return num
|
return num
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def sround(num, parts):
|
def sround(num, parts):
|
||||||
acc = [1,2,3,4,5]
|
acc = [1,2,3,4,5]
|
||||||
num = floor(num)
|
num = floor(num)
|
||||||
|
|
||||||
if num == 0:
|
if num == 0:
|
||||||
return 1
|
return 1
|
||||||
if num in acc:
|
if num in acc:
|
||||||
return num
|
return num
|
||||||
elif num%5 == 0:
|
elif num%5 == 0:
|
||||||
return num
|
return num
|
||||||
|
|
||||||
while num%5 != 0:
|
while num%5 != 0:
|
||||||
num -= 1
|
num -= 1
|
||||||
return num
|
return num
|
||||||
|
|
||||||
# Поиск элемента в списке рецепта
|
# Поиск элемента в списке рецепта
|
||||||
def ll_find(ll, pat):
|
def ll_find(ll, pat):
|
||||||
find = False
|
find = False
|
||||||
for i in range(len(ll)):
|
for i in range(len(ll)):
|
||||||
if ll[i][0] == pat:
|
if ll[i][0] == pat:
|
||||||
return i
|
return i
|
||||||
return None
|
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][3:] # Получаем составные
|
||||||
heat = db[el][2]
|
heat = db[el][2]
|
||||||
out = db[el][0] #Количество на выходе
|
out = db[el][0] #Количество на выходе
|
||||||
|
|
||||||
# Считаем количество частей
|
# Считаем количество частей
|
||||||
parts = 0
|
parts = 0
|
||||||
for i in comps:
|
for i in comps:
|
||||||
parts += i[1]
|
parts += i[1]
|
||||||
|
|
||||||
# Делаем поправку на выход
|
# Делаем поправку на выход
|
||||||
while out < parts:
|
while out < parts:
|
||||||
# Предварительная часть
|
# Предварительная часть
|
||||||
part = sround(amount/parts, parts)
|
part = sround(amount/parts, parts)
|
||||||
# Если итоговый объём <= входного объёма
|
# Если итоговый объём <= входного объёма
|
||||||
if (parts+1)*part <= amount:
|
if (parts+1)*part <= amount:
|
||||||
parts += 1
|
parts += 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Считаем 1 часть
|
# Считаем 1 часть
|
||||||
part = sround(amount/parts, parts)
|
part = sround(amount/parts, parts)
|
||||||
|
|
||||||
# Перебираем составные и делаем рекурсию
|
# Динамический объём
|
||||||
for i in comps:
|
# Нужен когда у вещества вход 20 а выход 10
|
||||||
if i[0] in db:
|
#part_vol =
|
||||||
lpart = calc(i[0], part*i[1])
|
|
||||||
# Если наша часть больше чем составная
|
|
||||||
if lpart < part:
|
|
||||||
part = lpart
|
|
||||||
# lpart - количество составного в итоге
|
|
||||||
# 50/3, часть = 16, ИТОГ: 16*3=48 <
|
|
||||||
|
|
||||||
if heat and not main:
|
|
||||||
recipe = [['heat']] + recipe
|
|
||||||
if heat and main:
|
|
||||||
recipe.append(['heat'])
|
|
||||||
|
|
||||||
# Перебираем элементарные вещества
|
|
||||||
for i in comps:
|
|
||||||
if i[0] not in db:
|
|
||||||
if i[0] == 'Плазма':
|
|
||||||
if ll_find(recipe, 'Плазма') == None:
|
|
||||||
recipe = [[i[0], 1]] + recipe
|
|
||||||
else:
|
|
||||||
if heat:
|
|
||||||
recipe = [[i[0], part*i[1]]] + recipe
|
|
||||||
else:
|
|
||||||
recipe.append([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
|
# Перебираем составные и делаем рекурсию
|
||||||
|
for i in comps:
|
||||||
|
ic(i)
|
||||||
|
if i[0] in db:
|
||||||
|
lpart = calc(i[0], part*i[1])
|
||||||
|
# Если наша часть больше чем составная
|
||||||
|
if lpart < part:
|
||||||
|
part = lpart
|
||||||
|
# lpart - количество составного в итоге
|
||||||
|
# 50/3, часть = 16, ИТОГ: 16*3=48 <
|
||||||
|
|
||||||
|
|
||||||
if main:
|
if heat and not main:
|
||||||
print('PART: ', part)
|
recipe = [['heat']] + recipe
|
||||||
return [recipe, out*part]
|
if heat and main:
|
||||||
else:
|
recipe.append(['heat'])
|
||||||
print(recipe)
|
|
||||||
print(el)
|
# Перебираем элементарные вещества
|
||||||
print('PART: ', part)
|
for i in comps:
|
||||||
return part*parts
|
if i[0] not in db:
|
||||||
|
if i[0] == 'Плазма':
|
||||||
|
if ll_find(recipe, 'Плазма') == None:
|
||||||
|
recipe = [[i[0], 1]] + recipe
|
||||||
|
else:
|
||||||
|
if heat:
|
||||||
|
recipe = [[i[0], part*i[1]]] + recipe
|
||||||
|
else:
|
||||||
|
recipe.append([i[0], part*i[1]])
|
||||||
|
|
||||||
|
# Если нету плазмы и нагрева - соединяем вещества
|
||||||
|
if main:
|
||||||
|
if ll_find(recipe, 'Плазма') == None and ll_find(recipe, 'heat') == None:
|
||||||
|
ic('START: ', recipe)
|
||||||
|
new_recipe = []
|
||||||
|
|
||||||
|
while recipe != []:
|
||||||
|
ic("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]):
|
||||||
|
# Если это отметка для нагрева
|
||||||
|
if el[0] == 'heat':
|
||||||
|
break
|
||||||
|
same_id = ll_find(recipe, el[0])
|
||||||
|
ic('OLD: ', new_recipe[id][1])
|
||||||
|
new_recipe[id][1] += recipe[same_id][1]
|
||||||
|
ic('NEW: ', new_recipe[id][1] + recipe[same_id][1])
|
||||||
|
# Удаляем этот элемент
|
||||||
|
del recipe[same_id]
|
||||||
|
|
||||||
|
ic("NEW:", new_recipe)
|
||||||
|
|
||||||
|
|
||||||
|
recipe = new_recipe
|
||||||
|
|
||||||
|
|
||||||
|
if main:
|
||||||
|
ic(part)
|
||||||
|
return [recipe, out*part]
|
||||||
|
else:
|
||||||
|
ic(recipe)
|
||||||
|
ic(el)
|
||||||
|
ic('PART: ', part)
|
||||||
|
# >>>>>>>>>>>>>>> Возможен баг <<<<<<<<<<<<
|
||||||
|
#return part*parts
|
||||||
|
# Возвращаем объём=часть*выход
|
||||||
|
return part*out
|
||||||
|
|
||||||
#print( calc("Лексорин", 100, True))
|
#print( calc("Лексорин", 100, True))
|
||||||
#print( calc("Бикаридин", 100, True))
|
#print( calc("Бикаридин", 100, True))
|
||||||
@ -172,3 +187,16 @@ 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("Ацетон", 50, True) )
|
||||||
|
|
||||||
|
#print( calc("Фенол", 50, True) )
|
||||||
|
#print(calc("Бензол", 50, True))
|
||||||
|
#OK print( calc("Гидроксид", 50, True) )
|
||||||
|
|
||||||
|
#print( calc("", 100, True) )
|
||||||
|
#print( calc("", 100, True) )
|
||||||
|
#print( calc("", 100, True) )
|
||||||
|
3
site.py
3
site.py
@ -7,7 +7,6 @@ els = list(db.keys())
|
|||||||
from dash import Dash, dcc, html, Input, Output,callback
|
from dash import Dash, dcc, html, Input, Output,callback
|
||||||
app = Dash(__name__, title="SS14 Tools", update_title=None)
|
app = Dash(__name__, title="SS14 Tools", update_title=None)
|
||||||
|
|
||||||
|
|
||||||
#### ФОРМАТ СТРАНИЦЫ ####
|
#### ФОРМАТ СТРАНИЦЫ ####
|
||||||
|
|
||||||
app.index_string = '''
|
app.index_string = '''
|
||||||
@ -164,4 +163,4 @@ def update_output(reaction, amount):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# app.run(debug=True)
|
# app.run(debug=True)
|
||||||
app.run(debug=False)
|
app.run(debug=False, port = 9000)
|
||||||
|
12
update_db.py
12
update_db.py
@ -71,7 +71,7 @@ class Reagent:
|
|||||||
self.__category = init_data.get("category")
|
self.__category = init_data.get("category")
|
||||||
# raw значения которые обработаны
|
# raw значения которые обработаны
|
||||||
|
|
||||||
self.heat: bool = init_data.get("heat")
|
self.__heat: bool = init_data.get("heat")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -95,6 +95,9 @@ class Reagent:
|
|||||||
print(self.__category)
|
print(self.__category)
|
||||||
result.append(self.__category)
|
result.append(self.__category)
|
||||||
|
|
||||||
|
# Добавляем нужен ли нагрев
|
||||||
|
result.append(self.__heat)
|
||||||
|
|
||||||
if not self.__recipe:
|
if not self.__recipe:
|
||||||
return None
|
return None
|
||||||
for item in self.__recipe:
|
for item in self.__recipe:
|
||||||
@ -171,7 +174,12 @@ def load_recipes(url,name):
|
|||||||
# print(item["id"])
|
# print(item["id"])
|
||||||
if item["id"] not in content:
|
if item["id"] not in content:
|
||||||
continue
|
continue
|
||||||
content[item["id"]]["heat"] = "minTemp" in item
|
if "minTemp" in item:
|
||||||
|
content[item["id"]]["heat"] = True
|
||||||
|
else:
|
||||||
|
content[item["id"]]["heat"] = False
|
||||||
|
# if "minTemp" in item:
|
||||||
|
# print(item["minTemp"])
|
||||||
content[item["id"]]["reactants"] = {
|
content[item["id"]]["reactants"] = {
|
||||||
element: {"amount": item["reactants"][element]["amount"], "reagent": element in content} for element in
|
element: {"amount": item["reactants"][element]["amount"], "reagent": element in content} for element in
|
||||||
item["reactants"]}
|
item["reactants"]}
|
||||||
|
Loading…
Reference in New Issue
Block a user