mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-02-08 01:01:18 +00:00
Compare commits
5 Commits
170dc0517a
...
0ef9fc1de9
Author | SHA1 | Date | |
---|---|---|---|
|
0ef9fc1de9 | ||
|
5cce77aa10 | ||
|
0a98ef930b | ||
|
45ec9a1157 | ||
|
5deaa5823e |
@ -1,12 +1,14 @@
|
|||||||
global expanded ; expanded = {}
|
global expanded
|
||||||
def expand_recipe(recipe, recipes, main = False):
|
def expand_recipe(recipe, recipes, main = False):
|
||||||
global expanded
|
global expanded
|
||||||
|
if main:
|
||||||
|
expanded = {}
|
||||||
|
|
||||||
ok = False
|
ok = False
|
||||||
part = 1 # Одна часть
|
part = 1 # Одна часть
|
||||||
while not ok:
|
while not ok:
|
||||||
ok = True
|
ok = True
|
||||||
min_vol = 0 # Объём мин. рецепта (вход)
|
vol_in = 0 # Объём мин. рецепта (вход)
|
||||||
# Перебираем элементы
|
# Перебираем элементы
|
||||||
for el in recipe:
|
for el in recipe:
|
||||||
# Если составное
|
# Если составное
|
||||||
@ -18,35 +20,31 @@ def expand_recipe(recipe, recipes, main = False):
|
|||||||
expanded = {}
|
expanded = {}
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
min_vol += expand_recipe(recipes[el].comps, recipes)
|
vol_in += expand_recipe(recipes[el].comps, recipes)
|
||||||
else:
|
else:
|
||||||
if el in expanded:
|
if el in expanded:
|
||||||
expanded[el] += recipe[el]*part
|
expanded[el] += recipe[el]*part
|
||||||
else:
|
else:
|
||||||
expanded[el] = recipe[el]*part
|
expanded[el] = recipe[el]*part
|
||||||
|
|
||||||
min_vol += recipe[el]*part
|
vol_in += recipe[el]*part
|
||||||
|
|
||||||
if main:
|
if main:
|
||||||
return expanded, min_vol, part
|
return expanded, vol_in, part
|
||||||
else:
|
else:
|
||||||
return min_vol
|
return vol_in
|
||||||
|
|
||||||
def calc(element, amount, recipes):
|
def calc(element, amount, recipes):
|
||||||
# Получаем характеристику элемента
|
# Получаем характеристику элемента
|
||||||
recipe, out = recipes[element].comps, recipes[element].out
|
recipe, vol_out = recipes[element].comps, recipes[element].out
|
||||||
# Расчитываем минимальный рецепт
|
# Расчитываем минимальный рецепт
|
||||||
expanded, vol, part = expand_recipe(recipe, recipes, True)
|
expanded, vol_in, part = expand_recipe(recipe, recipes, True)
|
||||||
|
|
||||||
# Домнажаем на сколько нужно
|
need = amount//vol_in
|
||||||
need = amount//vol
|
|
||||||
for i in expanded:
|
for i in expanded:
|
||||||
expanded[i] = expanded[i]*need
|
expanded[i] = expanded[i]*need
|
||||||
out = part*out*need
|
vol_in *= need
|
||||||
|
vol_out *= part*need
|
||||||
|
|
||||||
return expanded, out
|
return expanded, vol_in, vol_out
|
||||||
|
|
||||||
|
|
||||||
from parse import *
|
|
||||||
#print( load_recipes() )
|
|
||||||
print( calc('Leporazine', 100, load_recipes()) )
|
|
||||||
|
@ -1,20 +1,43 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
from reag__ import reag__
|
||||||
|
|
||||||
if not os.path.exists('db.json'):
|
if not os.path.exists('db.json'):
|
||||||
db = {}
|
db = {}
|
||||||
js = json.dumps(db, indent=2)
|
js = json.dumps(db, indent=2)
|
||||||
with open("db.json", "w") as outfile:
|
with open('db.json', 'w') as outfile:
|
||||||
outfile.write(js)
|
outfile.write(js)
|
||||||
print('Created new db.json')
|
print('Created new db.json')
|
||||||
|
if not os.path.exists('raw_db.json'):
|
||||||
|
db = {}
|
||||||
|
js = json.dumps(db, indent=2)
|
||||||
|
with open('raw_db.json', 'w') as outfile:
|
||||||
|
outfile.write(js)
|
||||||
|
print('Created new raw_db.json')
|
||||||
|
|
||||||
|
|
||||||
def read_db(file = 'db.json'):
|
def read_db(file):
|
||||||
with open(file, "r", encoding="utf-8") as openfile:
|
with open(file, 'r', encoding='utf-8') as openfile:
|
||||||
db = json.load(openfile)
|
db = json.load(openfile)
|
||||||
return db
|
return db
|
||||||
|
|
||||||
def write_db(db, file = 'db.json'):
|
def write_db(db, file):
|
||||||
js = json.dumps(db, indent=2, ensure_ascii=False)
|
js = json.dumps(db, indent=2, ensure_ascii=False)
|
||||||
with open(file, "w", encoding="utf-8") as outfile:
|
with open(file, 'w', encoding='utf-8') as outfile:
|
||||||
outfile.write(js)
|
outfile.write(js)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def save(db, file):
|
||||||
|
raw = {}
|
||||||
|
for el in db:
|
||||||
|
class_data = db[el].get_all()
|
||||||
|
raw[el] = class_data
|
||||||
|
write_db(raw, file)
|
||||||
|
|
||||||
|
def load(file):
|
||||||
|
raw = read_db(file)
|
||||||
|
db = {}
|
||||||
|
for el in raw:
|
||||||
|
db[el] = reag__(raw[el][0], raw[el][1], raw[el][2])
|
||||||
|
return db
|
||||||
|
@ -2,11 +2,10 @@ from requests import get
|
|||||||
from yaml import load, SafeLoader
|
from yaml import load, SafeLoader
|
||||||
from reag__ import reag__
|
from reag__ import reag__
|
||||||
|
|
||||||
def parse_yml(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions/medicine.yml'):
|
#### Локализация ####
|
||||||
yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
|
|
||||||
return yml
|
|
||||||
|
|
||||||
def parse_ftl(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Locale/ru-RU/reagents/meta/medicine.ftl'):
|
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'
|
||||||
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():
|
||||||
@ -17,8 +16,22 @@ def parse_ftl(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-st
|
|||||||
locales[name] = locale
|
locales[name] = locale
|
||||||
return locales
|
return locales
|
||||||
|
|
||||||
def load_recipes(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions/medicine.yml', category = '-'):
|
def load_locales(locales_url):
|
||||||
yml = parse_yml(url)
|
locales = {}
|
||||||
|
for el in locales_url:
|
||||||
|
locales = locales | parse_ftl(el)
|
||||||
|
return locales
|
||||||
|
|
||||||
|
#### Рецепты ####
|
||||||
|
|
||||||
|
def parse_yml(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
|
||||||
|
url = f'{prefix}/{el}.yml'
|
||||||
|
yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
|
||||||
|
return yml
|
||||||
|
|
||||||
|
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 element in yml:
|
for element in yml:
|
||||||
product = element["id"]
|
product = element["id"]
|
||||||
@ -27,10 +40,12 @@ def load_recipes(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space
|
|||||||
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__(category=category, comps=comps, out=out)
|
recipes[product] = reag__(comps=comps, out=out, category=el)
|
||||||
return recipes
|
return recipes
|
||||||
|
|
||||||
|
|
||||||
|
#### Локализируем ####
|
||||||
|
|
||||||
def localize(recipes, locale):
|
def localize(recipes, locale):
|
||||||
loc_recipes = {}
|
loc_recipes = {}
|
||||||
# Итерируем элементы
|
# Итерируем элементы
|
||||||
@ -57,17 +72,3 @@ def localize(recipes, locale):
|
|||||||
loc_recipes[element] = recipes[element]
|
loc_recipes[element] = recipes[element]
|
||||||
|
|
||||||
return loc_recipes
|
return loc_recipes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
recipes = load_recipes()
|
|
||||||
locales = parse_ftl()
|
|
||||||
|
|
||||||
recipes = localize(recipes, locales)
|
|
||||||
|
|
||||||
from icecream import ic
|
|
||||||
ic.configureOutput(prefix='')
|
|
||||||
for i in recipes:
|
|
||||||
el = [i, recipes[i].comps]
|
|
||||||
ic(el)
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
class reag__:
|
class reag__:
|
||||||
def __init__(self, category: str = '-', comps = {}, out: int = 0):
|
def __init__(self, comps, out, category = '-'):
|
||||||
# medicine
|
|
||||||
self.category = category
|
|
||||||
# {'инапровалин': 1, 'углерод': 1}
|
# {'инапровалин': 1, 'углерод': 1}
|
||||||
self.comps = comps
|
self.comps = comps
|
||||||
# 2
|
# 2
|
||||||
self.out = out
|
self.out = out
|
||||||
|
# medicine
|
||||||
|
self.category = category
|
||||||
def get_all(self):
|
def get_all(self):
|
||||||
return [self.category, self.comps, self.out]
|
return [self.comps, self.out, self.category]
|
||||||
|
|
||||||
|
23
reworked/update_db.py
Normal file
23
reworked/update_db.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from parse import *
|
||||||
|
from calc import calc
|
||||||
|
from db import *
|
||||||
|
|
||||||
|
'''
|
||||||
|
# Загружаем локализацию
|
||||||
|
locales_url = ['medicine', 'chemicals']
|
||||||
|
locales = load_locales(locales_url)
|
||||||
|
|
||||||
|
# Загружаем сырые рецепты
|
||||||
|
recipes_url = ['medicine']
|
||||||
|
raw_recipes = load_recipes(recipes_url)
|
||||||
|
|
||||||
|
# Локализируем
|
||||||
|
recipes = localize(raw_recipes, locales)
|
||||||
|
# Сохранаяем данные
|
||||||
|
save(recipes, 'raw_db.json')
|
||||||
|
'''
|
||||||
|
|
||||||
|
rec = load('raw_db.json')
|
||||||
|
|
||||||
|
# Делаем предрасчёты
|
||||||
|
#calculated =
|
Loading…
Reference in New Issue
Block a user