mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-02-08 01:01:18 +00:00
Обновление update_db и мелкие изменения
This commit is contained in:
parent
0ef9fc1de9
commit
320a7204e3
@ -1,3 +1,5 @@
|
|||||||
|
from precalc__ import precalc__
|
||||||
|
|
||||||
global expanded
|
global expanded
|
||||||
def expand_recipe(recipe, recipes, main = False):
|
def expand_recipe(recipe, recipes, main = False):
|
||||||
global expanded
|
global expanded
|
||||||
@ -48,3 +50,9 @@ def calc(element, amount, recipes):
|
|||||||
|
|
||||||
return expanded, vol_in, vol_out
|
return expanded, vol_in, vol_out
|
||||||
|
|
||||||
|
|
||||||
|
def calc_all(recipes, amount):
|
||||||
|
precalc = {}
|
||||||
|
for el in recipes:
|
||||||
|
precalc[el] = precalc__(calc(el, amount, recipes))
|
||||||
|
return precalc
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from reag__ import reag__
|
from reag__ import reag__
|
||||||
|
from precalc__ import precalc__
|
||||||
|
|
||||||
if not os.path.exists('db.json'):
|
if not os.path.exists('precalc.json'):
|
||||||
db = {}
|
db = {}
|
||||||
js = json.dumps(db, indent=2)
|
js = json.dumps(db, indent=2)
|
||||||
with open('db.json', 'w') as outfile:
|
with open('precalc.json', 'w') as outfile:
|
||||||
outfile.write(js)
|
outfile.write(js)
|
||||||
print('Created new db.json')
|
print('Created new precalc.json')
|
||||||
if not os.path.exists('raw_db.json'):
|
if not os.path.exists('raw_db.json'):
|
||||||
db = {}
|
db = {}
|
||||||
js = json.dumps(db, indent=2)
|
js = json.dumps(db, indent=2)
|
||||||
@ -35,9 +36,13 @@ def save(db, file):
|
|||||||
raw[el] = class_data
|
raw[el] = class_data
|
||||||
write_db(raw, file)
|
write_db(raw, file)
|
||||||
|
|
||||||
def load(file):
|
def load(file, type = 'raw'):
|
||||||
raw = read_db(file)
|
raw = read_db(file)
|
||||||
db = {}
|
db = {}
|
||||||
for el in raw:
|
if type == 'raw':
|
||||||
db[el] = reag__(raw[el][0], raw[el][1], raw[el][2])
|
for el in raw:
|
||||||
|
db[el] = reag__(raw[el][0], raw[el][1], raw[el][2])
|
||||||
|
elif type == 'precalc':
|
||||||
|
for el in raw:
|
||||||
|
db[el] = precalc__(raw[el])
|
||||||
return db
|
return db
|
||||||
|
7
reworked/precalc__.py
Normal file
7
reworked/precalc__.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class precalc__:
|
||||||
|
def __init__(self, els):
|
||||||
|
self.recipe = els[0]
|
||||||
|
self.vol_in = els[1]
|
||||||
|
self.vol_out = els[2]
|
||||||
|
def get_all(self):
|
||||||
|
return [self.recipe, self.vol_in, self.vol_out]
|
@ -1,23 +1,43 @@
|
|||||||
from parse import *
|
from parse import *
|
||||||
from calc import calc
|
from calc import *
|
||||||
from db import *
|
from db import *
|
||||||
|
|
||||||
'''
|
print('''1. Обновить всё.
|
||||||
# Загружаем локализацию
|
2. Пересчитать рецепты.
|
||||||
locales_url = ['medicine', 'chemicals']
|
''')
|
||||||
locales = load_locales(locales_url)
|
inp = input(">> ")
|
||||||
|
print('\n')
|
||||||
|
|
||||||
# Загружаем сырые рецепты
|
vols = [30, 50, 100]
|
||||||
recipes_url = ['medicine']
|
if inp == '1':
|
||||||
raw_recipes = load_recipes(recipes_url)
|
print('Парсим и обрабатываем данные...')
|
||||||
|
# Загружаем локализацию
|
||||||
|
locales_url = ['medicine', 'chemicals']
|
||||||
|
locales = load_locales(locales_url)
|
||||||
|
|
||||||
# Локализируем
|
# Загружаем сырые рецепты
|
||||||
recipes = localize(raw_recipes, locales)
|
recipes_url = ['medicine']
|
||||||
# Сохранаяем данные
|
raw_recipes = load_recipes(recipes_url)
|
||||||
save(recipes, 'raw_db.json')
|
|
||||||
'''
|
|
||||||
|
|
||||||
rec = load('raw_db.json')
|
# Локализируем
|
||||||
|
recipes = localize(raw_recipes, locales)
|
||||||
|
|
||||||
# Делаем предрасчёты
|
save(recipes, 'raw_db.json')
|
||||||
#calculated =
|
print('Сохранены минимальные рецепты в raw_db.json')
|
||||||
|
print('Выполняем предрасчёты...')
|
||||||
|
|
||||||
|
for i in vols:
|
||||||
|
precalc = calc_all(recipes, i)
|
||||||
|
save(precalc, f'{i}_calc.json')
|
||||||
|
print(f'Данные сохранены в {i}_calc.json')
|
||||||
|
elif inp == '2':
|
||||||
|
print('Выполняем расчёты...')
|
||||||
|
recipes = load('raw_db.json')
|
||||||
|
for i in vols:
|
||||||
|
precalc = calc_all(recipes, i)
|
||||||
|
save(precalc, f'{i}_calc.json')
|
||||||
|
print(f'Данные сохранены в {i}_calc.json')
|
||||||
|
else:
|
||||||
|
exit()
|
||||||
|
|
||||||
|
print("ГОТОВО.")
|
||||||
|
Loading…
Reference in New Issue
Block a user