<commit_before>#Import/Modify/Store info for all ingredients

IngredientLibrary = []

FAMILIES = ['Alcohol','Mixer']

BASES = []


class Ingredient:
    name = None
    base = None
    family = None
    startVol = None
    endVol = None
    active = None
    position = None
    def __init__(self, name, base, family, startVol, endVol, active, position):
        self.name = name
        self.base = base
        self.family = family
        self.startVol = startVol
        self.endVol = endVol
        self.active = active
        self.position = position

    #String representation for storage
    def __str__(self):
        return self.name+','+self.base+','+self.family+','+str(self.startVol)+','+str(self.endVol)+','+str(self.active)+','+str(self.position)

    def isActive(self):
        return self.active

    def getName(self):
        return self.name

    def setName(self,new_name):
        self.name = new_name
    
    def getBase(self):
        return self.base

    def setBase(self,new_base):
        self.base = new_base

    def getFamily(self):
        return self.family

    def setFamily(self,new_family):
        self.family = new_family

    def getStartVol(self):
        return self.startVol

    def setStartVol(self,new_startVol):
        self.startVol = new_startVol

    def getEndVol(self):
        return self.endVol

    def setEndVol(self, new_endVol):
        self.endVol = new_endVol

    def setActive(self, new_active):
        self.active = new_active
    
    def getPosition(self):
        return self.position

    def setPosition(self, new_position):
        self.position = new_position

        
#Create an ingredient
def createIngredient(name,base,family,startVol, endVol, active, position):
    test = str(active)
    if(test == 'True'):
        active = True
    else:
        active = False
    ingredient = Ingredient(name, base, family, int(startVol), int(endVol), bool(active), int(position))
    addIngredient(ingredient)

#Add ingredient to IngredientLibrary
def addIngredient(new_ingredient):
    IngredientLibrary.append(new_ingredient)

#Commit IngredientLibrary to storage
def storeIngredientLibrary():
    file = open("IngredientRepo.txt","w")
    for ingredient in IngredientLibrary:
        file.write(str(ingredient)+'\n')
    file.close()

#Restore IngredientLibrary from storage
def restoreIngredientLibrary():
    file = open("IngredientRepo.txt","r")
    for line in file:
        elements = line.split(',')
        createIngredient(elements[0],elements[1],elements[2],elements[3],elements[4],elements[5],elements[6])

#Build bases library from file
def restoreBases():
    #TODO: Remove this after ingestion
    BASES.clear()
    file = open("BasesRepo.txt","r")
    for line in file:
        BASES.append(line.strip('\n'))
    
#Delete ingredient from IngredientLibrary
def deleteIngredient(name):
    marked = None
    for element in IngredientLibrary:<commit_msg>Refactored Ingredient saving to json format<commit_after>import json

#Import/Modify/Store info for all ingredients

IngredientLibrary = []

FAMILIES = ['Alcohol','Mixer']

BASES = []


class Ingredient:
    name = None
    base = None
    family = None
    startVol = None
    endVol = None
    active = None
    position = None
    def __init__(self, name, base, family, startVol, endVol, active, position):
        self.name = name
        self.base = base
        self.family = family
        self.startVol = startVol
        self.endVol = endVol
        self.active = active
        self.position = position

    #String representation for storage
    def __str__(self):
        return self.name+','+self.base+','+self.family+','+str(self.startVol)+','+str(self.endVol)+','+str(self.active)+','+str(self.position)

    def isActive(self):
        return self.active

    def getName(self):
        return self.name

    def setName(self,new_name):
        self.name = new_name
    
    def getBase(self):
        return self.base

    def setBase(self,new_base):
        self.base = new_base

    def getFamily(self):
        return self.family

    def setFamily(self,new_family):
        self.family = new_family

    def getStartVol(self):
        return self.startVol

    def setStartVol(self,new_startVol):
        self.startVol = new_startVol

    def getEndVol(self):
        return self.endVol

    def setEndVol(self, new_endVol):
        self.endVol = new_endVol

    def setActive(self, new_active):
        self.active = new_active
    
    def getPosition(self):
        return self.position

    def setPosition(self, new_position):
        self.position = new_position

        
#Create an ingredient
def createIngredient(name,base,family,startVol, endVol, active, position):
    test = str(active)
    if(test == 'True'):
        active = True
    else:
        active = False
    ingredient = Ingredient(name, base, family, int(startVol), int(endVol), bool(active), int(position))
    addIngredient(ingredient)

#Add ingredient to IngredientLibrary
def addIngredient(new_ingredient):
    IngredientLibrary.append(new_ingredient)

#Save IngredientLibrary to storage
def storeIngredientLibrary():
    file = open("IngredientRepo.txt","w")
    for ingredient in IngredientLibrary:
        file.write(json.dumps(ingredient.__dict__)+'\n')
    file.close()

#Restore IngredientLibrary from storage
def restoreIngredientLibrary():
    file = open("IngredientRepo.txt","r")
    for line in file:
        ingredient = json.loads(line[:len(line)-1])
        createIngredient(ingredient['name'],ingredient['base'],ingredient['family'],ingredient['startVol'],ingredient['endVol'],ingredient['active'],ingredient['position'])

#Build bases library from file
def restoreBases():
    #TODO: Remove this after ingestion
    BASES.clear()
    file = open("BasesRepo.txt","r")
    for line in file:
        BASES.append(line.strip('\n'))
    
#Delete ingredient from IngredientLibrary
def deleteIngredient(name):
    marked = None
    for element in IngredientLibrary:
{'fraction_non_alphanumeric': 0.11063051073032773, 'fraction_numerical': 0.0013308933621693562, 'mean_word_length': 3.1348005502063274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3354039', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1857, 'n_words': 424}