Ejemplo n.º 1
0
def json_write_recipes():
    """Write all recipes from the global recipe_dict to file, overwriting previous data"""
    global recipe_dict
    f = open('./data/JSONRecipeShelf.json', 'w')
    json_string = RecipeSerializer.serialize_dict(recipe_dict)
    f.write(json_string)
    f.close()
Ejemplo n.º 2
0
    def json_write_recipes(self):
        """Write all recipes from self.recipe_dict to file, overwriting previous data"""
##        f = open(path.join(persistent_data_path, "JSONRecipeShelf.json"), 'w')
##        json_string = RecipeSerializer.serialize_dict(self.recipe_dict)
##        f.write(json_string)
##        f.close()
        with open(path.join(persistent_data_path, "JSONRecipes.json"), 'w') as f:
            json_string = RecipeSerializer.serialize_dict(self.recipe_dict)
            json.dump(json_string, f, indent=4)
Ejemplo n.º 3
0
def json_load_recipes():
    """Load recipes from a JSON file using our deserializer"""
    global recipe_dict
    global current_recipe
    f = open('./data/JSONRecipeShelf.json', 'r')
    json_str = f.read()
    f.close()
    recipe_dict = RecipeSerializer.deserialize_dict(json_str)
    # open first (default) recipe in list
    current_recipe = recipe_dict['0']
Ejemplo n.º 4
0
import tkinter.messagebox
from numbers import Number

from recipes import *
from polyplot import *
from dragmanager import *
from ingredient_data import *

from serializers.recipeserializer import RecipeSerializer

if False:  # Set to True whenever the Recipe class is changed
    default_recipe_dict = {}
    default_recipe_dict['0'] = Recipe.get_default_recipe()
    f = open('./data/JSONRecipeShelf.json', 'w')
    f.write(RecipeSerializer.serialize_dict(default_recipe_dict))
    f.close()

## SECTION 1
# Create stuff for restriction window

entry_type = StringVar()


def update_oxide_entry_type(recipe, entry_type):

    global current_recipe
    current_recipe.update_oxides(restr_dict, entry_type)

    for et in ['umf_', 'mass_perc_', 'mole_perc_']:
        if et == entry_type:
Ejemplo n.º 5
0
    def __init__(self):
        
        OxideData.set_default_oxides()
        with open(path.join(persistent_data_path, "JSONOxides.json"), 'r') as f:
            OxideData.oxide_dict = OxideSerializer.deserialize_dict(json.load(f))

        CoreData.__init__(self)

        if True:    # Use data saved by user if True
            self.other_attr_dict = {'0': 'LOI', '2': 'Clay', '1': 'Cost'}  # Replace by functions that sets data saved by user

            with open(path.join(persistent_data_path, "JSONIngredients.json"), 'r') as f:
                self.ingredient_dict = IngredientSerializer.deserialize_dict(json.load(f))
                
            for i, ing in self.ingredient_dict.items():
                self.ingredient_analyses[i] = ing.analysis

            # All of the data contained in JSONOther, except numerator_coefs, can be obtained from JSONRestriction.
            # Need to rethink how data is packaged.
            with open(path.join(persistent_data_path, "JSONOther.json"), 'r') as f:
                self.other_dict = OtherSerializer.deserialize_dict(json.load(f))

            with open(path.join(persistent_data_path, "JSONRecipes.json"), 'r') as f:
                self.recipe_dict = RecipeSerializer.deserialize_dict(json.load(f))

            with open(path.join(persistent_data_path, "JSONOrder.json"), 'r') as f:
                self.order = json.load(f)

            #Create Restriction dictionary
            with open(path.join(persistent_data_path, "JSONRestrictions.json"), 'r') as f:
                self.restr_dict = RestrictionSerializer.deserialize_dict(json.load(f))
            # It seems a bit silly to record the default lower and upper bounds in both self.restr_dict
            # and in self.default_lower_bounds and self.default_lower_bounds, but that's how things
            # stand at the moment
            for key in self.restr_keys():
                self.default_lower_bounds[key] = self.restr_dict[key].default_low
                self.default_upper_bounds[key] = self.restr_dict[key].default_upp
                
        else:   # Reset data
            self.set_default_data()
             
            self.set_default_default_bounds()
            with open(path.join(persistent_data_path, "JSONRecipes.json"), 'r') as f:
                self.recipe_dict = RecipeSerializer.deserialize_dict(json.load(f))
            self.order = {"ingredients": ["0", "1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"],
                          "oxides":["SiO2","Al2O3","B2O3","MgO","CaO","SrO","BaO","ZnO","Li2O","Na2O","K2O","P2O5","Fe2O3","TiO2","MnO2","ZrO2"],
                          "other": ["0","1","2","3","4","5","6"],
                          "other attributes": ["0", "1", "2"] }
                
            self.restr_dict = {}

            # Create oxide restrictions:
            for ox in self.order['oxides']:
                key = 'umf_'+ox
                self.restr_dict[key] = Restriction(key, ox, 'mole_'+ox, {'fluxes_total': 1}, \
                                                   self.default_lower_bounds[key], self.default_upper_bounds[key], dec_pt=3)
                key = 'mass_perc_'+ox
                self.restr_dict[key] = Restriction(key, ox, 'mass_'+ox, {'ox_mass_total': 0.01}, \
                                                   self.default_lower_bounds[key], self.default_upper_bounds[key], dec_pt=2)
                key = 'mole_perc_'+ox
                self.restr_dict[key] = Restriction(key, ox, 'mole_'+ox, {'ox_mole_total': 0.01}, \
                                                   self.default_lower_bounds[key], self.default_upper_bounds[key], dec_pt=2)

            # Create ingredient restrictions:
            for i, ing in self.ingredient_dict.items():
                key = 'ingredient_'+i
                self.restr_dict[key] = Restriction(key, ing.name, key, {'ingredient_total': 0.01}, \
                                       self.default_lower_bounds[key], self.default_upper_bounds[key])

            # Create other restrictions:
            for i, ot in self.other_dict.items():
                key = 'other_'+i
                self.restr_dict[key] = Restriction(key, ot.name, key, ot.normalization, ot.def_low, ot.def_upp, dec_pt=ot.dec_pt)

            self.json_write_restrictions()
            self.json_write_ingredients()
            self.json_write_other()
            self.json_write_order()

        self.current_recipe = None
        self.recipe_index = None
        self.set_current_recipe('0')