From 864e7ed15bf2db8d5df5736b64f8d1ea81f17818 Mon Sep 17 00:00:00 2001 From: none Date: Fri, 1 Mar 2024 21:44:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B5=D1=86=D0=B5=D0=BF=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=20=D1=81=20=D0=BF=D0=BB=D0=B0=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B9,=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BE=D0=BD?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BC=D0=B5=D1=88=D0=B0=D0=BD=D1=8B=20=D0=B2=20?= =?UTF-8?q?1=20=D0=BA=D1=83=D1=87=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calc.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++------ site.py | 2 +- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/calc.py b/calc.py index 0976458..432e709 100644 --- a/calc.py +++ b/calc.py @@ -62,10 +62,18 @@ def sround(num, parts): num -= 1 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): global db, recipe if main: - recipe = {} + recipe = [] #{} comps = db[el][2:] # Получаем составные out = db[el][0] #Количество на выходе @@ -108,12 +116,57 @@ def calc(el, amount, main = False): for i in comps: if i[0] not in db: if i[0] == 'Плазма': - recipe[i[0]] = 1 + #recipe[i[0]] = 1 + + # Проверяем есть ли уже плазма + #exist = False + #for chk in recipe: + # if chk[0] == 'Плазма': + # exist = True + # break + #if not exist: + + if ll_find(recipe, 'Плазма') == None: + #recipe.append([i[0], 1]) + recipe = [[i[0], 1]] + recipe else: - if i[0] not in recipe: - recipe[i[0]] = part*i[1] - else: - recipe[i[0]] += part*i[1] + #if i[0] not in recipe: + # recipe[i[0]] = part*i[1] + #else: + # recipe[i[0]] += part*i[1] + recipe.append([i[0], part*i[1]]) + + # ЕСЛИ ЕСТЬ БАГИ ВЕРОЯТНО ЭТО ТУТ + # Если нету плазмы - соединяем вещества + if main: + if ll_find(recipe, 'Плазма') == None: + 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: print('PART: ', part) @@ -126,3 +179,4 @@ def calc(el, amount, main = False): #print( calc("Бикаридин", 100, True)) #print( calc("Диловен", 100, True)) #print( calc("Эфедрин", 100, True)) +print( calc("Криоксадон", 100, True) ) diff --git a/site.py b/site.py index a188a86..febd0a9 100644 --- a/site.py +++ b/site.py @@ -143,7 +143,7 @@ def update_output(reaction, amount): # Форматирование для HTML result = [] for i in comps: - result.append( html.Div(i + ': ' + str(comps[i]) + 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%'}) ) # Выходное вещество