mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2026-06-22 04:21:02 +00:00
Compare commits
3 Commits
0ef9fc1de9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bda4452390 | |||
| 53d540c841 | |||
| 320a7204e3 |
@@ -1,3 +1,6 @@
|
|||||||
|
from precalc__ import precalc__
|
||||||
|
from db import load
|
||||||
|
|
||||||
global expanded
|
global expanded
|
||||||
def expand_recipe(recipe, recipes, main = False):
|
def expand_recipe(recipe, recipes, main = False):
|
||||||
global expanded
|
global expanded
|
||||||
@@ -48,3 +51,17 @@ 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
|
||||||
|
|
||||||
|
|
||||||
|
def precalc(element, amount):
|
||||||
|
try:
|
||||||
|
# Загружаем рецепты с нужным количеством
|
||||||
|
recipes = load(f'{amount}_calc.json', 'precalc')
|
||||||
|
except:
|
||||||
|
return 'Нету такого файла или вещества'
|
||||||
|
return recipes[element]
|
||||||
|
|||||||
+9
-4
@@ -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 = {}
|
||||||
|
if type == 'raw':
|
||||||
for el in raw:
|
for el in raw:
|
||||||
db[el] = reag__(raw[el][0], raw[el][1], raw[el][2])
|
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
|
||||||
|
|||||||
+18
-9
@@ -1,11 +1,14 @@
|
|||||||
from requests import get
|
from requests import get
|
||||||
from yaml import load, SafeLoader
|
from yaml import load, SafeLoader
|
||||||
from reag__ import reag__
|
from reag__ import reag__
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
#### Локализация ####
|
#### Локализация ####
|
||||||
|
|
||||||
def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Locale/ru-RU/reagents/meta'):
|
def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Locale/ru-RU/reagents/meta'):
|
||||||
url = f'{prefix}/{el}.ftl'
|
if '.ftl' not in el:
|
||||||
|
el += '.ftl'
|
||||||
|
url = f'{prefix}/{el}'
|
||||||
raw = get(url).content.decode('utf-8')
|
raw = get(url).content.decode('utf-8')
|
||||||
locales = {}
|
locales = {}
|
||||||
for i in raw.splitlines():
|
for i in raw.splitlines():
|
||||||
@@ -18,27 +21,33 @@ def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/s
|
|||||||
|
|
||||||
def load_locales(locales_url):
|
def load_locales(locales_url):
|
||||||
locales = {}
|
locales = {}
|
||||||
for el in locales_url:
|
for el in tqdm(locales_url):
|
||||||
locales = locales | parse_ftl(el)
|
locales = locales | parse_ftl(el)
|
||||||
return locales
|
return locales
|
||||||
|
|
||||||
#### Рецепты ####
|
#### Рецепты ####
|
||||||
|
|
||||||
|
SafeLoader.add_multi_constructor('', lambda loader, tag_suffix, node: None)
|
||||||
|
|
||||||
def parse_yml(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
def parse_yml(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
||||||
url = f'{prefix}/{el}.yml'
|
if '.yml' not in el:
|
||||||
|
el += '.yml'
|
||||||
|
url = f'{prefix}/{el}'
|
||||||
yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
|
yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
|
||||||
return yml
|
return yml
|
||||||
|
|
||||||
def load_recipes(recipes_url, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
def load_recipes(recipes_url, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
||||||
for el in recipes_url:
|
|
||||||
yml = parse_yml(el, prefix)
|
|
||||||
recipes = {}
|
recipes = {}
|
||||||
|
for el in tqdm(recipes_url):
|
||||||
|
yml = parse_yml(el, prefix)
|
||||||
for element in yml:
|
for element in yml:
|
||||||
product = element["id"]
|
if 'products' not in element or 'reactants' not in element:
|
||||||
|
continue
|
||||||
|
product = element['id']
|
||||||
comps = {}
|
comps = {}
|
||||||
for elem in element["reactants"]:
|
for elem in element['reactants']:
|
||||||
comps[elem] = element["reactants"][elem]["amount"]
|
comps[elem] = element['reactants'][elem]['amount']
|
||||||
for id, value in element["products"].items():
|
for id, value in element['products'].items():
|
||||||
out = value
|
out = value
|
||||||
recipes[product] = reag__(comps=comps, out=out, category=el)
|
recipes[product] = reag__(comps=comps, out=out, category=el)
|
||||||
return recipes
|
return recipes
|
||||||
|
|||||||
@@ -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]
|
||||||
+33
-9
@@ -1,23 +1,47 @@
|
|||||||
from parse import *
|
from parse import *
|
||||||
from calc import calc
|
from calc import *
|
||||||
from db import *
|
from db import *
|
||||||
|
|
||||||
'''
|
print('''1. Обновить всё.
|
||||||
|
2. Пересчитать рецепты.
|
||||||
|
''')
|
||||||
|
inp = input(">> ")
|
||||||
|
print('\n')
|
||||||
|
|
||||||
|
vols = [30, 50, 100]
|
||||||
|
if inp == '1':
|
||||||
|
print('Парсим и обрабатываем данные...')
|
||||||
# Загружаем локализацию
|
# Загружаем локализацию
|
||||||
locales_url = ['medicine', 'chemicals']
|
locales_url = ['biological', 'botany', 'chemicals', 'cleaning', 'elements', 'fun',
|
||||||
|
'gases', 'medicine', 'narcotics', 'physical-desc', 'pyrotechnic', 'toxins',
|
||||||
|
'consumable/drink/alcohol', 'consumable/drink/drinks', 'consumable/drink/juice', 'consumable/drink/soda',
|
||||||
|
'consumable/food/condiments', 'consumable/food/food', 'consumable/food/ingredients']
|
||||||
locales = load_locales(locales_url)
|
locales = load_locales(locales_url)
|
||||||
|
|
||||||
# Загружаем сырые рецепты
|
# Загружаем сырые рецепты
|
||||||
recipes_url = ['medicine']
|
recipes_url = ['biological', 'botany', 'chemicals', 'cleaning', 'drinks', 'food',
|
||||||
|
'fun', 'gas', 'medicine', 'pyrotechnic']
|
||||||
raw_recipes = load_recipes(recipes_url)
|
raw_recipes = load_recipes(recipes_url)
|
||||||
|
|
||||||
# Локализируем
|
# Локализируем
|
||||||
recipes = localize(raw_recipes, locales)
|
recipes = localize(raw_recipes, locales)
|
||||||
# Сохранаяем данные
|
|
||||||
save(recipes, 'raw_db.json')
|
save(recipes, 'raw_db.json')
|
||||||
'''
|
print('Сохранены минимальные рецепты в raw_db.json')
|
||||||
|
print('Выполняем предрасчёты...')
|
||||||
|
|
||||||
rec = load('raw_db.json')
|
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("ГОТОВО.")
|
||||||
#calculated =
|
|
||||||
|
|||||||
Reference in New Issue
Block a user