Exemplo n.º 1
0
class CoolingControll(object):

    def __init__(self, process):
        self.process = process
        self.serial_comunication = SerialCalls()

    def handle_states(self):
        state = self.process.state
        if state == STATES.get('turn_on_chiller'):
            logger.info("[Cooling] Function defined: turn_on_chiller")
            self.turn_on_chiller()
        elif state == STATES.get('check_temperature'):
            logger.info("[Cooling] Function defined: check_temperature")
            self.check_temperature()

    def turn_on_chiller(self):
        self.serial_comunication.turn_on_chiller()
        logger.info('[Cooling] Turning on water on chiller')
        self.process.state = STATES.get('check_temperature')
        self.process.save()
        logger.info("[Cooling] State changed! New state: check_temperature")

    def check_temperature(self):
        temperature = ThermalSensor.get_current_temperature()
        logger.info("[Cooling] Temperature: %.2f" % temperature)
        if temperature < 2:
            logger.info("[Cooling] Temperature is lower than 20 degrees")
            self.serial_comunication.turn_off_chiller()
            logger.info("[Cooling] Turning off water on chiller")
            self.process.state = fermentation.STATES.get('chill_must')
            self.process.save()
            logger.info("[Cooling] Cooling stage completed! "
                        "New state: chill_must")
Exemplo n.º 2
0
class FilteringControll(object):

    def __init__(self, process):
        self.process = process
        self.serial_comunication = SerialCalls()

    def handle_states(self):
        state = self.process.state
        if state == STATES.get('open_pot_valve'):
            logger.info("[Filtering] Function defined: open_pot_valve")
            self.open_pot_valve()
        elif state == STATES.get('insert_water'):
            logger.info("[Filtering] Function defined: insert_water")
            self.insert_water()
        elif state == STATES.get('check_level'):
            logger.info("[Filtering] Function defined: check_level")
            self.check_level()
        elif state == STATES.get('stop_water'):
            logger.info("[Filtering] Function defined: stop_water")
            self.stop_water()

    def open_pot_valve(self):
        now = timezone.now()
        minutes = timedelta(minutes=1)
        if now > self.process.filtering_init + minutes:
            self.process.filtering_init = now
            logger.info("[Filtering] 20 minutes after filtering init")
            self.serial_comunication.activate_alarm()
            self.process.state = STATES.get('insert_water')
            self.process.save()
            logger.info("[Filtering] State changed! New state: insert_water")

    def insert_water(self):
        self.serial_comunication.insert_water()
        logger.info("[Filtering] Turn on the water")
        self.process.state = STATES.get('check_level')
        self.process.save()
        logger.info("[Filtering] State changed! New state: check_level")

    def check_level(self):
        logger.info("[Filtering] Checking level of pot2. . .")
        now = timezone.now()
        minutes = timedelta(minutes=10)

        if now > self.process.filtering_init + minutes:
            logger.info("[Filtering] Pot water level reached")
            self.process.state = STATES.get('stop_water')
            self.process.save()
            logger.info("[Filtering] State changed! New state: stop_water")
        else:
            logger.info("[Filtering] Pot water level not reached")

    def stop_water(self):
        self.serial_comunication.stop_water()
        logger.info("[Filtering] Closing valve")
        self.process.state = boiling.STATES.get('warm_must')
        self.process.save()
        self.serial_comunication.turn_on_resistor()
        logger.info("[Filtering] State changed! New state: warm_must "
                    "(from boiling process)")
Exemplo n.º 3
0
 def __init__(self, process):
     self.heat_order = process.recipe.get_heat_order()
     process.actual_heat = Heat.objects.get(pk=self.heat_order.get('1'))
     process.save()
     self.process = process
     self.next_heat = '2'
     self.serial_comunication = SerialCalls()
Exemplo n.º 4
0
class PreBreweryControll(object):

    def __init__(self, process):
        self.process = process
        self.valve = Valve.objects.get(pk=1)
        self.serial_comunication = SerialCalls()

    def handle_states(self):
        state = self.process.state
        if state == STATES.get('insert_water'):
            logger.info("[PreBrewery] Function defined: insert_water")
            self.insert_water()
        elif state == STATES.get('waiting_water'):
            logger.info("[PreBrewery] Function defined: waiting_water")
            self.waiting_water()
        elif state == STATES.get('stop_water'):
            logger.info("[PreBrewery] Function defined: stop_water")
            self.stop_water()

    def insert_water(self):
        self.valve = Valve.objects.get(pk=1)
        self.serial_comunication.insert_water()
        self.valve.is_opened = 1
        self.process.state = STATES.get('waiting_water')
        self.process.save()
        logger.info("[PreBrewery] State changed! New state: waiting_water")

    def waiting_water(self):
        now = timezone.now()
        waiting_time = timedelta(minutes=self.process.recipe.insert_water_time)
        if now > self.process.initial_datetime + waiting_time:
            logger.info("[PreBrewery] Pot water level reached")
            self.process.state = STATES.get('stop_water')
            self.process.save()
            logger.info("[PreBrewery] State changed! New state: stop_water")
        else:
            logger.info("[PreBrewery] Pot water level not reached")
            self.process.state = STATES.get('waiting_water')
            self.process.save()

    def stop_water(self):
        self.serial_comunication.stop_water()
        self.valve.is_opened = 0
        self.process.state = brewery.STATES.get('initial_boiling')
        self.process.save()
        logger.info("[PreBrewery] State changed! New state: "
                    "initial_boiling (from brewery process)")
Exemplo n.º 5
0
class FermentationControll(object):

    def __init__(self, process):
        self.process = process
        self.freezer_temperature = self.process.recipe.fermentation_temperature
        self.serial_comunication = SerialCalls()
        self.serial_comunication.activate_alarm()

    def handle_states(self):
        state = self.process.state
        if state == STATES.get('chill_must'):
            logger.info("[Fermentation] Function defined: chill_must")
            self.chill_must()
        elif state == STATES.get('maintain_temperature'):
            logger.info("[Fermentation] Function defined: "
                        "maintain_temperature")
            self.maintain_temperature()

    def chill_must(self):
        self.serial_comunication.turn_on_freezer(self.freezer_temperature)
        logger.info('[Fermentation] Cooling must on the freezer')
        temperature = ThermalSensor.get_current_temperature()
        if temperature > self.freezer_temperature:
            logger.info("[Fermentation] Fermentation temperature not reached")
            self.process.state = STATES.get('chill_must')
            # Decrease temperature
            pass
        else:
            logger.info("[Fermentation] Temperature reached!")
            self.process.state = STATES.get('maintain_temperature')
            logger.info("[Fermentation] State changed! "
                        "New state: maintain_temperature")
        self.process.save()

    def maintain_temperature(self):
        temperature = ThermalSensor.get_current_temperature()
        if self.freezer_temperature - 2 <= temperature \
                <= self.freezer_temperature + 2:
            logger.info("[Fermentation] Temperature on range")
            self.process.state = STATES.get('process_end')
            logger.info("[Fermentation] State changed! "
                        "New state: process_end")
        else:
            logger.info("[Fermentation] Temperature not on range")
            self.process.state = STATES.get('chill_must')
            pass
        self.process.save()
Exemplo n.º 6
0
 def __init__(self, process):
     self.process = process
     self.serial_comunication = SerialCalls()
Exemplo n.º 7
0
 def __init__(self, process):
     self.process = process
     self.valve = Valve.objects.get(pk=1)
     self.serial_comunication = SerialCalls()
Exemplo n.º 8
0
 def __init__(self, process):
     self.hop_order = process.recipe.get_hop_order()
     process.actual_hop = Hop.objects.get(pk=self.hop_order.get("1"))
     process.save()
     self.process = process
     self.serial_comunication = SerialCalls()
Exemplo n.º 9
0
class BoilingControll(object):
    def __init__(self, process):
        self.hop_order = process.recipe.get_hop_order()
        process.actual_hop = Hop.objects.get(pk=self.hop_order.get("1"))
        process.save()
        self.process = process
        self.serial_comunication = SerialCalls()

    def handle_states(self):
        state = self.process.state
        if state == STATES.get("warm_must"):
            logger.info("[Boiling] Function defined: warm_must")
            self.warm_must()
        elif state == STATES.get("add_hops"):
            logger.info("[Boiling] Function defined: add_hops")
            self.add_hops()
        elif state == STATES.get("continue_boiling"):
            logger.info("[Boiling] Function defined: continue_boiling")
            self.continue_boiling()

    def warm_must(self):
        temperature = ThermalSensor.get_current_temperature()
        logger.info("[Boiling] Temperature: %.2f" % temperature)
        if temperature < self.process.recipe.boiling_temperature:
            logger.info("[Boiling] Temperature less than actual " "heat temperature")
            self.serial_comunication.turn_on_resistor()
        else:
            logger.info("[Boiling] Temperature reached!")
            self.process.state = STATES.get("add_hops")
            self.process.boiling_stop_time = timezone.now() + timedelta(minutes=self.process.recipe.boiling_duration)
            logger.info("[Boining] State changed! New state: add_hops")
        self.process.save()

    def add_hops(self):
        if self.process.change_hop():
            self.serial_comunication.add_hop(self.process.next_hop)
            logger.info("[Boiling] Hop has been added to the pot!")
            if self.check_next():
                hops = Hop.objects.get(pk=self.get_next_hop())
                self.process.next_hop += 1
                self.process.actual_hop = hops
                self.process.state = STATES.get("add_hops")
                logger.info("[Boiling] State changed! New state: add_hops")
            else:
                self.process.state = STATES.get("continue_boiling")
                logger.info("[Boiling] State changed! " "New state: continue_boiling")

        self.process.save()

    def continue_boiling(self):
        if self.check_boiling_time_reached():
            logger.info("[Boiling] Boiling stage completed!" "New state: turn_on_chiller")
            self.process.state = cooling.STATES.get("turn_on_chiller")
            self.serial_comunication.turn_off_resistor(2)
        self.process.save()

    def check_next(self):
        if self.process.next_hop <= len(self.hop_order):
            return True
        else:
            return False

    def get_next_hop(self):
        next_hop = self.process.next_hop
        return self.hop_order.get(str(next_hop))

    def check_boiling_time_reached(self):
        now = timezone.now()

        if now >= self.process.boiling_stop_time:
            return True
        else:
            return False
Exemplo n.º 10
0
 def __init__(self, process):
     self.process = process
     self.freezer_temperature = self.process.recipe.fermentation_temperature
     self.serial_comunication = SerialCalls()
     self.serial_comunication.activate_alarm()
Exemplo n.º 11
0
class BreweryControll(object):

    def __init__(self, process):
        self.heat_order = process.recipe.get_heat_order()
        process.actual_heat = Heat.objects.get(pk=self.heat_order.get('1'))
        process.save()
        self.process = process
        self.next_heat = '2'
        self.serial_comunication = SerialCalls()

    def handle_states(self):
        state = self.process.state
        if state == STATES.get('initial_boiling'):
            logger.info("[Brewery] Function defined: initial_boiling")
            self.initial_boiling()
        elif state == STATES.get('heating'):
            self.serial_comunication.turn_on_engine()
            self.heating()
        elif state == STATES.get('heat_controll'):
            logger.info("[Brewery] Function defined: heat_controll")
            self.heat_controll()

    def initial_boiling(self):
        boiling_temperature = self.process.recipe.initial_boiling_temperature
        self.serial_comunication.turn_on_resistor(boiling_temperature)
        temperature = ThermalSensor.get_current_temperature()
        logger.info("[Brewery] Temperature: %.2f" % temperature)

        if temperature < boiling_temperature:
            logger.info("[Brewery] Actual temperature is lower "
                        "than %.2f" % boiling_temperature)
            self.serial_comunication.turn_on_resistor(boiling_temperature)
            pass
        else:
            logger.info("[Brewery] Actual temperature is greater "
                        "than %.2f" % boiling_temperature)
            self.serial_comunication.turn_off_resistor(1)
            self.process.state = STATES.get('insert_malt')
            self.serial_comunication.activate_alarm()
            logger.info("[Brewery] State changed! New state: insert_malt")
        self.process.save()

    def heating(self):
        self.serial_comunication.turn_on_resistor(
            self.process.recipe.boiling_temperature)
        logger.info("[Brewery] Function defined: heating")
        temperature = ThermalSensor.get_current_temperature()

        logger.info("[Brewery] Temperature: %.2f" % temperature)
        if temperature < self.process.actual_heat.temperature:
            logger.info("[Brewery] Temperature less than actual "
                        "heat temperature")
            self.serial_comunication.turn_on_resistor(
                self.process.actual_heat.temperature)
        else:
            logger.info("[Brewery] Temperature greater than "
                        "actual_heat temperature")
            self.process.actual_heat_time = timezone.now()
            self.process.state = STATES.get('heat_controll')
            logger.info("[Brewery] State changed! New state: heat_controll")
        self.process.save()

    def heat_controll(self):
        if self.process.change_heat():
            logger.info('[Brewery] Previous heating is done. Change heat!')
            if self.check_next():
                heat = Heat.objects.get(pk=self.get_next_heat())
                self.process.next_heat += 1
                self.process.actual_heat = heat
                self.process.state = STATES.get('heating')
                logger.info("[Brewery] State changed! New state: heating")
            else:
                self.process.state = STATES.get('iodine_test')
                self.serial_comunication.activate_alarm()
                logger.info("[Brewery] State changed! New state: iodine_test")
        else:
            # Maintain temperature
            pass
        self.process.save()

    def check_next(self):
        if self.process.next_heat <= len(self.heat_order):
            return True
        else:
            return False

    def get_next_heat(self):
        next_heat = self.process.next_heat
        return self.heat_order.get(str(next_heat))