示例#1
0
    def __init__(self):

        # TODO : have this read in from a configuration file
        # initialize Monitron Modules (Mwa Ha Ha)

        # self.tempGetter = TempGetter()     // DS1202B or whatever disabled in favor of combo AM2302

        self.dataStorer = DataStorer()
        self.heatController = HeatController(
            'NormallyON')  # Tell the controller which plug
        self.temperatureAndHumidityGetter = TemperatureAndHumidityGetter(
            '2302', '14')  # we're using an AM2302 on pin 6
        self.fanController = Controller(26)  # our fan is a 5V PC fan on pin 26
        self.rgb_led_1 = RGBLEDController(
            16, 16, 21)  # we're not using the green pins on these.
        self.rgb_led_2 = RGBLEDController(07, 07,
                                          01)  # not using green pins yet maybe
        # the peripherals controlled by the outlet box

        # when the class initializes, set the pins connected to the output box relays
        # accepts key string of corresponding dictionary for outlet number to pin mapping
        # "bcm_pin_dict",  "board_gpio_pin_dict":
        self.outletBoxController = OutletBoxController(0, self.pin_map_key)
        self.outletBoxController.set_pins()
        self.lampController = OutletBoxController(
            8, self.pin_map_key)  # the lamp is plugged in to outlet 8
        self.humidifierController = OutletBoxController(
            7, self.pin_map_key)  # the mister is plugged into outlet 7
        self.cameraController = CameraController()  # clicka clicka

        self.initialize_peripherals()
        # temperature_min, temperature_max, humidity_min, humidity_max, time_interval
        self.monitor(70, 80, 70, 80, 3)  # go.
示例#2
0
    def __init__(self, graph, edge_data):
        self.__controller = Controller(graph, edge_data)

        self.__menu_options = {
            0: "0. Exit",
            1: "1. Get the number of vertices",
            2:
            "2. Is there an edge from vertex x to vertex y? If yes, print the edge id",
            3: "3. In degree & out degree of a vertex",
            4:
            "4. Iterate through the set of outbound edges of a vertex and print each id",
            5:
            "5. Iterate through the set of inbound edges of a vertex and print each id",
            6: "6. Get the endpoints of an edge specified by an edge id",
            7: "7. Retrieve the information attached to a specific edge",
            8: "8. Modify the information attached to a specific edge"
        }
示例#3
0
def logout():
    
    client_id, private_id = g.client_id, g.private_id
    result = Controller.logout(client_id, private_id)

    return jsonify({
            "client_id": client_id,
            "ok": result
        })
示例#4
0
def verify():

    client_id, private_id = g.client_id, g.private_id
    result = Controller.verify(client_id, private_id)

    return jsonify({
        "client_id": client_id,
        "timestamp": time(),
        "ok": result
    })
示例#5
0
def register():

    client = Controller.register()

    return jsonify({
        "client_id": client.peer.id_hex,
        "private_id": client.peer.key_hex,
        "timestamp": time(),
        "ok": True
    })
示例#6
0
def get_client_status(client_id):

    client = Controller.get_client(client_id)
    if not client:
        return abort(404)

    return jsonify({
        "client_id": client_id,
        "status": client.status.value,
        "last_online": client.last_pulse,
        "timestamp": time(),
        "ok": True
    })
示例#7
0
def get_client_udp_address(client_id):

    client = Controller.get_client(client_id)
    if not client:
        return abort(404)

    host, port = client.get_address()
    if not host or not port:
        return abort(404)

    return jsonify({
        "client_id": client_id,
        "host": host,
        "port": port,
        "timestamp": time(),
        "ok": True
    })
示例#8
0
    def inner_func(*args, **kwargs):
        auth = request.headers.get('Authorization')
        if not auth:
            return abort(400)

        try:
            method, token = auth.split(' ', 1)
        except:
            return abort(400)

        if method != 'Bearer' or not token:
            return abort(400)

        client_id = Controller.get_private_to_id(token)
        if not client_id:
            return abort(400)

        g.client_id = client_id
        g.private_id = token

        return func(*args, **kwargs)
示例#9
0
def main():
    word = RandomWord(choice(JsonWords().get_words()))

    while "-" in word.random_word or " " in word.random_word:  # avoids words like "water-based" or entries with spaces
        word = RandomWord(choice(JsonWords().get_words()))

    board = Board(player, word)
    view = View()
    controller = Controller(board, view)

    controller.hint()

    while True:
        controller.take_guess()
        controller.handle_guess()
        controller.result()
        controller.check_winner()

        if controller.winner is not None:
            if play_again():
                main()

            else:
                controller.close()
                quit()
示例#10
0
 def __init__(self):
     self.collectionName = "properties"
     self.service = PropertyService()
     Controller.__init__(self)
示例#11
0
from flask import Flask
from Controllers.Controller import Controller
from Controllers.UDPHeartbeat import UDPHeartbeat
import Routes

app = Flask(__name__)
app.register_blueprint(Routes.mod)

if __name__ == '__main__':

    Controller.start_scheduler()
    udp_heartbeat = UDPHeartbeat(host="0.0.0.0", port=5027)
    udp_heartbeat.start_running()
    app.run(host="0.0.0.0", port=5025, debug=True, use_reloader=False)
示例#12
0
class UserInterface:
    def __init__(self, graph, edge_data):
        self.__controller = Controller(graph, edge_data)

        self.__menu_options = {
            0: "0. Exit",
            1: "1. Get the number of vertices",
            2:
            "2. Is there an edge from vertex x to vertex y? If yes, print the edge id",
            3: "3. In degree & out degree of a vertex",
            4:
            "4. Iterate through the set of outbound edges of a vertex and print each id",
            5:
            "5. Iterate through the set of inbound edges of a vertex and print each id",
            6: "6. Get the endpoints of an edge specified by an edge id",
            7: "7. Retrieve the information attached to a specific edge",
            8: "8. Modify the information attached to a specific edge"
        }

    def print_menu(self):
        for val in self.__menu_options.values():
            print(val)

    def run(self):
        while True:
            self.print_menu()

            option = Utilities.read_integer(">> ")

            if option == 0:
                exit()
            elif option == 1:
                print("The number of vertices of the graph is {}.".format(
                    self.__controller.return_number_of_vertices()))
            elif option == 2:
                x = Utilities.read_integer("First vertex: ")
                y = Utilities.read_integer("Second vertex: ")
                result = self.__controller.return_edge_id_from_vertex_x_to_y(
                    x, y)

                if result == -1:
                    print(
                        "Edge starting from vertex {} to {} could not be found!"
                        .format(x, y))
                else:
                    print("Edge starting from vertex {} to {} has the id {}.".
                          format(x, y, result))
            elif option == 3:
                vertex = Utilities.read_integer("Vertex: ")
                result = self.__controller.vertex_degree(vertex)

                if result == -1:
                    print("Vertex could not be found!")
                else:
                    print("Degree in: {}; degree out: {}.".format(
                        result[0], result[1]))
            elif option == 4:
                vertex = Utilities.read_integer("Vertex: ")
                result = self.__controller.outbound_edges(vertex)
                print("The outbound edges of vertex {} are: {}.".format(
                    vertex, result))
            elif option == 5:
                vertex = Utilities.read_integer("Vertex: ")
                result = self.__controller.inbound_edges(vertex)
                print("The inbound edges of vertex {} are: {}.".format(
                    vertex, result))
            elif option == 6:
                edge_id = Utilities.read_integer("Edge id: ")
                result = self.__controller.endpoints_of_edge_id(edge_id)

                if result == -1:
                    print(
                        "The endpoint with the specified edge id could not be found!"
                    )
                else:
                    print("The endpoint with the edge id {} is {}.".format(
                        edge_id, result))
            elif option == 7:
                x = Utilities.read_integer("First vertex: ")
                y = Utilities.read_integer("Second vertex: ")
                result = self.__controller.get_edge_value(x, y)

                if result == -1:
                    print(
                        "The edge starting from vertex {} to {} does not exist!"
                        .format(x, y))
                else:
                    print(
                        "The value of the edge starting from vertex {} to {} is {}."
                        .format(x, y, result))
            elif option == 8:
                x = Utilities.read_integer("First vertex: ")
                y = Utilities.read_integer("Second vertex: ")
                new_value = Utilities.read_integer("New value: ")
                result = self.__controller.mod_edge_value(x, y, new_value)

                if result == False:
                    print(
                        "The edge starting from vertex {} to {} does not exist!"
                        .format(x, y))
                else:
                    print(
                        "The value of the edge starting from vertex {} to {} has been modified!"
                        .format(x, y))
            else:
                print("Unknown option entered!")
示例#13
0
class Monitron:

    pin_map_key = "bcm_pin_dict"
    currentTemperature = 0.0
    currentHumidity = 0.0

    # tempGetter = object
    temperatureAndHumidityGetter = object

    dataStorer = object

    # heatController = object

    humidityController = object
    fanController = object

    rgb_led_1 = object
    rgb_led_2 = object
    rgb_led_3 = object
    rgb_led_4 = object

    outletBoxController = object
    lampController = object

    cameraController = object

    def __init__(self):

        # TODO : have this read in from a configuration file
        # initialize Monitron Modules (Mwa Ha Ha)

        # self.tempGetter = TempGetter()     // DS1202B or whatever disabled in favor of combo AM2302

        self.dataStorer = DataStorer()
        self.heatController = HeatController(
            'NormallyON')  # Tell the controller which plug
        self.temperatureAndHumidityGetter = TemperatureAndHumidityGetter(
            '2302', '14')  # we're using an AM2302 on pin 6
        self.fanController = Controller(26)  # our fan is a 5V PC fan on pin 26
        self.rgb_led_1 = RGBLEDController(
            16, 16, 21)  # we're not using the green pins on these.
        self.rgb_led_2 = RGBLEDController(07, 07,
                                          01)  # not using green pins yet maybe
        # the peripherals controlled by the outlet box

        # when the class initializes, set the pins connected to the output box relays
        # accepts key string of corresponding dictionary for outlet number to pin mapping
        # "bcm_pin_dict",  "board_gpio_pin_dict":
        self.outletBoxController = OutletBoxController(0, self.pin_map_key)
        self.outletBoxController.set_pins()
        self.lampController = OutletBoxController(
            8, self.pin_map_key)  # the lamp is plugged in to outlet 8
        self.humidifierController = OutletBoxController(
            7, self.pin_map_key)  # the mister is plugged into outlet 7
        self.cameraController = CameraController()  # clicka clicka

        self.initialize_peripherals()
        # temperature_min, temperature_max, humidity_min, humidity_max, time_interval
        self.monitor(70, 80, 70, 80, 3)  # go.

    def print_status(self):

        # print "%s %s" % (hello, world)
        # print("{} {}".format(hello, world))
        print("|EpochTime: {}\t| Temp : {}\t| Humidity: {}\t".format(
            TimeGetter.get_epoch_time(), self.currentTemperature,
            self.currentHumidity))
        print("-----------------------------------------")

    def initialize_peripherals(self):
        self.turn_lights_on()
        self.test_fan()
        self.cameraController.take_picture()
        #self.lampController.turn_outlet_on()

    def turn_lights_on(self):
        self.rgb_led_1.magenta_on()
        print("RGB LED 1 magenta_on")
        self.rgb_led_2.magenta_on()
        print("RGB LED 2 magenta_on")

    def turn_lights_off(self):
        self.rgb_led_1.magenta_off()
        print("RGB LED 1 magenta_off")
        self.rgb_led_2.magenta_off()
        print("RGB LED 2 magenta_off")

    def monitor(self, temperature_min, temperature_max, humidity_min,
                humidity_max, time_interval):

        #while True:

        # get the current temperature and current humidity from the sensor
        self.currentTemperature, self.currentHumidity = self.temperatureAndHumidityGetter.get_temperature_and_humidity(
            'F')

        # store the current temperature and humidity data
        self.dataStorer.store_data(self.currentTemperature,
                                   self.currentHumidity)
        print("-----------------------------------------")
        print(TimeGetter.get_epoch_time())

        # TODO : maybe add the fish tank heater in a little pool of water . . .
        # just in case the lamp alone isn't enough to heat the terrarium
        # or the light is too much for the plants over time.
        # i.e. the light has to be on too long to heat the chamber and is cooking the plants.

        # check the temperature conditions, and toggle the heat lamp as necessary

        # if the current temp is lower then the lowest temp minimum we want,
        if float(self.currentTemperature) < float(temperature_min):

            print("Temperature: Low")
            print("{} > {} < {}".format(temperature_min,
                                        self.currentTemperature,
                                        temperature_max))
            self.lampController.turn_outlet_on()

        # else if the current temp is greater than the max temp we want,
        elif float(self.currentTemperature) > float(temperature_max):

            print("Temperature: High")
            print("{} < {} > {}".format(temperature_min,
                                        self.currentTemperature,
                                        temperature_max))
            self.lampController.turn_outlet_off(
            )  # turn heat off, if it isn't already off

        else:

            print("Temperature: Sweet Spot")
            print("{} < {} < {}".format(temperature_min,
                                        self.currentTemperature,
                                        temperature_max))

        # check the humidity conditions and toggle the humidifier as necessary

        # if the current humidity is lower then the lowest humidity minimum we want,
        if float(self.currentHumidity) < float(humidity_min):

            print("Humidity: Low")
            print("{} > {} < {}".format(humidity_min, self.currentHumidity,
                                        humidity_max))
            self.humidifierController.turn_outlet_on()
            self.fanController.turn_off()

        # else if the current humidity is greater than the max humidity we want,
        elif float(self.currentHumidity) > float(humidity_max):

            print("Humidity: High")
            print("{} < {} > {}".format(humidity_min, self.currentHumidity,
                                        humidity_max))
            self.humidifierController.turn_outlet_off(
            )  # turn humidifier off, if it isnt' already off
            self.fanController.turn_on()

        else:

            print("Humidity: Sweet Spot")
            print("{} < {} < {}".format(humidity_min, self.currentHumidity,
                                        humidity_max))
            self.fanController.turn_off()

        # give it a rest. don't spam the sensor too much
        time.sleep(time_interval)

    def monitor_temperature_and_humidity(self, temp_format):
        current_temp, current_humidity = self.temperatureAndHumidityGetter.get_temperature_and_humidity(
            temp_format)
        print("{0}*{1} {2}".format(current_temp, temp_format,
                                   current_humidity))

    def test_rgb_led(self):
        self.rgb_led_1.magenta_on()
        print("RGB LED 1 magenta_on")
        self.rgb_led_2.magenta_on()
        print("RGB LED 2 magenta_on")
        time.sleep(1)
        self.rgb_led_1.magenta_off()
        print("RGB LED 1 magenta_off")
        self.rgb_led_2.magenta_off()
        print("RGB LED 2 magenta_off")

    def test_fan(self):

        self.fanController.turn_on()
        print("fan on")
        time.sleep(1)
        self.fanController.turn_off()
        print("fan off")

    def test_lamp(self):
        self.lampController.turn_outlet_on()
        time.sleep(1)
        self.lampController.turn_outlet_off()

    def test_data_storer(self):
        temp_format = 'F'
        current_temp, current_humidity = self.temperatureAndHumidityGetter.get_temperature_and_humidity(
            temp_format)
        self.dataStorer.store_data(current_temp, current_humidity)