def door_trigger(token,trigger):
	user = auth.user(request.get_header('X-Forwarded-User'))
	garage = Garage(initial=dao.door_status(), door_switch_callback=door_switch_callback)
	update_db = garage.current not in (Garage.opened, Garage.closed )
	if garage.can(trigger):
		getattr(garage, trigger)()
		if update_db: dao.update_status("user:"+user,garage.current)
	return auth_ok(door_status_to_json( dao.door_status() ))
Beispiel #2
0
def door_trigger(token, trigger):
    user = auth.user(request.get_header('X-Forwarded-User'))
    garage = Garage(initial=dao.door_status(),
                    door_switch_callback=door_switch_callback)
    update_db = garage.current not in (Garage.opened, Garage.closed)
    if garage.can(trigger):
        getattr(garage, trigger)()
        if update_db: dao.update_status("user:" + user, garage.current)
    return auth_ok(door_status_to_json(dao.door_status()))
Beispiel #3
0
	def test_cannot_trigger(self):
		self.assertEqual(Garage.closed, self.fsm.current)
	
		self.assertTrue(self.fsm.cannot(Garage.stop))
		
		self.assertTrue(self.fsm.cannot(Garage.close))

		self.fsm = Garage(initial=Garage.opened,door_switch_callback=self.door_switch_count_increment)
		self.assertEqual(Garage.opened, self.fsm.current)
		
		self.assertTrue(self.fsm.cannot(Garage.stop))
		
		self.assertTrue(self.fsm.cannot(Garage.open))
		
		self.assertEqual(0, self.door_switch_count)
Beispiel #4
0
def addGarage():
    log('Called addGarage')
    garageName = flask.request.form['garageName']
    numSpots = flask.request.form['numSpots']
    numHandicapSpots = flask.request.form['numHandicapSpots']
    address = flask.request.form['address']
    phone = flask.request.form['phone']
    ownerDL = flask.request.form['ownerDL']
    log('About to create JSON')
    json_result = {}
    log('About to try')
    latitude = flask.request.form['latitude']
    log(latitude)
    longitude = flask.request.form['longitude']
    log(longitude)

    try:
        log('In try')
        garageData.createGarage(Garage(garageName, numSpots, numHandicapSpots, address, phone, ownerDL, latitude, longitude)) #First argument is gID, will use as key somehow, passing phone for now
        log('finished create garage')
        json_result['ok'] = True
        log('after json result')
    except Exception as exc:
        log('EXCEPTION')
        log(str(exc))
        json_result['error'] = str(exc)
    return flask.Response(json.dumps(json_result), mimetype='application/json')
Beispiel #5
0
def initGarageState(screen, db):
    try:
        garage_obj = db["Garage"]
    except KeyError:
        screen.addstr("This is first time application is getting used \n")
        screen.addstr("Please enter the initial number of levels\n")
        while True:
            try:
                initial_levels = int(screen.getstr())
                break
            except ValueError:
                screen.addstr(
                    "Please enter valid value for Initial number of levels\n")
        screen.addstr("Please enter Initial number of slots\n")
        while True:
            try:
                initial_slots = int(screen.getstr())
                break
            except ValueError:
                screen.addstr(
                    "Please enter valid value for Initial number of slots\n")

        garage_obj = Garage(init_levels=initial_levels,
                            init_slots=initial_slots)
        db["Garage"] = garage_obj
    return garage_obj
Beispiel #6
0
	def test_full_cycle_from_open(self):
		

		self.fsm = Garage(initial=Garage.opened,door_switch_callback=self.door_switch_count_increment)

		self.assertEqual(Garage.opened, self.fsm.current)
		
		self.fsm.close()
		self.assertEqual(Garage.closing, self.fsm.current)
		
		self.fsm.stop()
		self.assertEqual(Garage.stopped_on_closing, self.fsm.current)
		
		self.fsm.open()
		self.assertEqual(Garage.opening, self.fsm.current)
		
		self.assertEqual(3, self.door_switch_count)
def main():
    print("Tworzymy Janusza, obiekt klasy Person z pustą listą samochodów...")
    janusz = Person("Janusz", "Dziki", "Gdziesiowo 1A")
    time.sleep(1)
    print("Tworzymy 3 samochody Janusza oraz garaż w którym będą samochody...")
    audi = Car("Audi", "A4", 5, 1.6, "GDZ IES1", 6.5)
    volvo = Car("Volvo", "XC60", 5, 2.0, "GDZ IES2", 7.3)
    seat = Car("Seat", "Vario", 5, 1.4, "GDZ IES3", 7.0)
    janusz_garage = Garage("Gdziesiowo 1B", 3, [audi, volvo, seat])
    time.sleep(1)
    print("przypisujemy auta do Janusza...\n")
    janusz.cars = [audi.registration, volvo.registration, seat.registration]
    janusz.garage = janusz_garage
    time.sleep(1)
    print(janusz)
    time.sleep(1)
    print("Sprawdzamy ile utworzyliśmy obiektów...")
    time.sleep(1)
    print("Ilość obiektów klasy Car:", Car.quantity)
    print("Ilość aut należących do Janusza:",
          janusz.number_of_cars,
          end="\n\n")
    time.sleep(1)
    print("Janusz testuje swoje autko...")
    time.sleep(1)
    print(janusz.cars[2])
    time.sleep(1)
    print(janusz.garage[2])
    time.sleep(1)
    print("\nIlość potrzebnego paliwa na trase 765 km:",
          str(janusz.garage[2].calculate_combustion(765)) + " l")
    time.sleep(1)
    print("Koszt tego paliwa (cena paliwa: 4.92 zł/l): {:.2f} zł\n\n".format(
        janusz.garage[2].calculate_fuel_price(700, 4.92)))
    time.sleep(1)
    print("Halina wrzuca na autostradzie bieg R jak RAKIETA i niszczy auto...")
    janusz.delete_car("GDZ-IES1")
    time.sleep(1)
    print("\n", janusz)
    time.sleep(1)
    print(janusz.garage)
    time.sleep(1)
    print("Ilość obiektów klasy Car:", Car.quantity, end="\n\n")
    time.sleep(1)
    print("Jakieś cwane nicponie kradną Januszowi pozostałe auta...")
    janusz.delete_car("GDZ-IES2")
    janusz.delete_car("GDZ-IES3")
    time.sleep(1)
    print(janusz)
    time.sleep(1)
    print(janusz.garage)
    time.sleep(1)
    print("Ilość obiektów klasy Car:", Car.quantity, end="\n\n")
    print("Ilość aut Janusza:", janusz.number_of_cars)
Beispiel #8
0
def _garage_from_entity(garage_entity):
    log("Creating garage from entity...")
    name = garage_entity['Name']
    numSpots = garage_entity['numSpots']
    numHandicapSpots = garage_entity['numHandicapSpots']
    address = garage_entity['Address']
    phone = garage_entity['Phone']
    ownerDL = garage_entity['Owner DL']
    latitude = garage_entity['latitude']
    longitude = garage_entity['longitude']
    garageVal = Garage(name, numSpots, numHandicapSpots, address, phone,
                       ownerDL, longitude, latitude)
    log("Returning garage from entity...")
    return garageVal
Beispiel #9
0
 def __init__(self,
              name="Nieznane",
              surname="Nieznane",
              address="Nieznany",
              garage=Garage(),
              cars=None):
     self.name = name
     self.surname = surname
     self.address = address
     self.garage = garage
     if cars is None:
         cars = []
     self.cars = cars
     self.number_of_cars = len(cars)
Beispiel #10
0
def on_message(client, userdata, msg):
    if msg.topic == "garage/activate":
        print("Message Recieved")
        print(msg.topic + " " + str(msg.payload))
        output_pin = int(os.environ["GARAGE_OUTPUT_PIN"])
        try:
            g = Garage(output_pin)
            g.activate()
            print("Garage activated")
        except:
            print("Unexpected error:", sys.exc_info()[0])
        finally:
            g.cleanup()
    else:
        print(f"Unhandled message topic: {msg.topic}, message: {msg.payload}")
Beispiel #11
0
	def test_initil(self):
		self.assertEqual(Garage.closed, self.fsm.current)
		self.fsm = Garage(initial=Garage.opened)
		self.assertEqual(Garage.opened, self.fsm.current)
Beispiel #12
0
			screen.addstr("Please enter the initial number of levels\n")
			while True:
				try:
					initial_levels = int(screen.getstr())
					break
				except ValueError:
					screen.addstr("Please enter valid value for Initial number of levels\n")
			screen.addstr("Please enter Initial number of slots\n")
			while True:
				try:
					initial_slots = int(screen.getstr())
					break
				except ValueError:
					screen.addstr("Please enter valid value for Initial number of slots\n")

			garage_obj = Garage(init_levels=initial_levels, init_slots=initial_slots)
			db["Garage"] = garage_obj
			clearScreen(screen)

		if input_char == '2':
			screen.addstr("Please enter Initial number of slots for new Level\n")
			while True:
				try:
					initial_slots = int(screen.getstr())
					break
				except ValueError:
					screen.addstr("Please enter valid value for Initial number of slots\n")
				
			screen.addstr(garage_obj.addLevel(init_slots=initial_slots))
			db["Garage"] = garage_obj
			clearScreen(screen)
Beispiel #13
0
class TestGarageDoorStateMachine(unittest.TestCase):

	def door_switch_count_increment(self, e):
		self.door_switch_count+=1
		return self.door_switch_successful

	def setUp(self):
		self.door_switch_count = 0
		self.door_switch_successful = True
		self.fsm = Garage(door_switch_callback=self.door_switch_count_increment)

	def test_initial_state(self):
		self.assertEqual(Garage.closed, self.fsm.current)

	def test_open(self):
		self.fsm.open()
		self.assertEqual(Garage.opening, self.fsm.current)		
		self.assertEqual(1, self.door_switch_count)
		
	def test_cannot_trigger(self):
		self.assertEqual(Garage.closed, self.fsm.current)
	
		self.assertTrue(self.fsm.cannot(Garage.stop))
		
		self.assertTrue(self.fsm.cannot(Garage.close))

		self.fsm = Garage(initial=Garage.opened,door_switch_callback=self.door_switch_count_increment)
		self.assertEqual(Garage.opened, self.fsm.current)
		
		self.assertTrue(self.fsm.cannot(Garage.stop))
		
		self.assertTrue(self.fsm.cannot(Garage.open))
		
		self.assertEqual(0, self.door_switch_count)
		

	def test_full_cycle_from_closed(self):
		
		self.fsm.open()
		self.assertEqual(Garage.opening, self.fsm.current)
		
		self.fsm.stop()
		self.assertEqual(Garage.stopped_on_opening, self.fsm.current)
		
		self.fsm.close()
		self.assertEqual(Garage.closing, self.fsm.current)
		
		self.assertEqual(3, self.door_switch_count)

	def test_full_cycle_from_open(self):
		

		self.fsm = Garage(initial=Garage.opened,door_switch_callback=self.door_switch_count_increment)

		self.assertEqual(Garage.opened, self.fsm.current)
		
		self.fsm.close()
		self.assertEqual(Garage.closing, self.fsm.current)
		
		self.fsm.stop()
		self.assertEqual(Garage.stopped_on_closing, self.fsm.current)
		
		self.fsm.open()
		self.assertEqual(Garage.opening, self.fsm.current)
		
		self.assertEqual(3, self.door_switch_count)
			
	def test_door_switch_fails(self):
		self.door_switch_successful = False
		self.fsm.open()
		self.assertEqual(Garage.closed, self.fsm.current)
	
	def test_initil(self):
		self.assertEqual(Garage.closed, self.fsm.current)
		self.fsm = Garage(initial=Garage.opened)
		self.assertEqual(Garage.opened, self.fsm.current)
# Bismillah al-Rahmaan al-Raheem
# Ali Shah | Dec. 05, 2020

"""CS1.1 Assignment 3: OOP Design Challenge."""

from garage import Garage

# Instantiate Garage
garage = Garage()

# Initiate menu loop
menu = None

print("----------------------------------------")
print("Welcome to Jerry's Auto Garage!")

while menu != "0":
    print("----------------------------------------")
    menu = input(
        "[0] Exit\n\n"
        "[1] Meet Team\n"
        "[2] Change Uniform\n"
        "[3] Add Mechanic\n\n"
        "[4] Add Car\n"
        "[5] Check Cars\n"
        "[6] Fix Car\n\n"
        "[7] Test Drive\n"
        "[8] Do a burnout!!!\n\n"
        "Your choice: "
    )
    print("\n----------------------------------------")
Beispiel #15
0
"""Exemple d'utilisation des classes Garage et Voiture."""

from garage import Garage
from voiture import Voiture

# Création des voitures.
v1 = Voiture('BMW', 'Noir')
v2 = Voiture('Subaru', 'Bleu')
v3 = Voiture('Dacia', 'Rouge')

# On place les voitures dans un garage ainsi qu'un nombre.
g = Garage(v1, v2, v3)

# On affiche le garage.
g.afficher()
Beispiel #16
0
    def amount_storage_items(self) -> int:
        return self.__storage_interface.amount_storage_items()

    def print_storage_item_list(self):
        items: List[str] = [
            it.name for it in self.__storage_interface.get_items()
        ]
        print(items)

    def __repr__(self):
        return f"{self.__name} запрятал {self.amount_storage_items()} вещей!"


if __name__ == '__main__':
    car: Car = Car("h134if123", 20)
    cupboard: Cupboard = Cupboard(40)
    garage: Garage = Garage("очень далеко д.21", 10)

    car.push_item(Book("dsfsdf", 200, 0.5))
    car.push_item(Box(1, 2, 3))

    person: Person = Person("Петр", car)
    person.save_item(Bottle("Жижа", 29, 0.7))
    person.save_item(Bottle("Жижа 2.1", 29, 1.7))
    print(person.pop_item())

    person.change_interface(garage)
    print(person.amount_storage_items())
    person.save_item(Bottle("Жижа", 29, 0.7))
    person.save_item(Bottle("Жижа 2.1", 29, 1.7))
Beispiel #17
0
 def get_garage2(self):
     from garage import Garage
     return Garage(6, "San Escobar")
Beispiel #18
0
 event = 0
 pygame.mixer.pre_init(44100, -16, 2, 2048)
 pygame.mixer.init()
 clock = pygame.time.Clock()
 size = width, height = 800, 800
 screen = pygame.display.set_mode(size, pygame.NOFRAME)
 background = pygame.Surface(screen.get_size())
 player_sprites = pygame.sprite.Group()
 nitro_sprites = pygame.sprite.Group()
 coin_sprites = pygame.sprite.Group()
 npc_sprites = pygame.sprite.Group()
 road = Road(screen, path + f'{choose_roads()}.png')
 main_player = Player(player_sprites)
 main_menu = Menu(screen, background, road, main_player, str(sys.argv[1]))
 settings = Settings(screen, main_menu, main_menu.login)
 garage = Garage(screen, main_menu, main_menu.login)
 road_select = Road_select(screen, main_menu, main_menu.login)
 change_road = False
 shop = Shop(screen, main_menu.login, garage)
 screen.blit(background, (0, 0))
 game = Game(main_player, coin_sprites, nitro_sprites, npc_sprites,
             player_sprites, road, screen, str(sys.argv[1]))
 main_menu.set_game_class(game)
 moving_event = 0
 while running:
     for event in pygame.event.get():
         if event.type == pygame.QUIT:
             running = False
         if event.type == pygame.KEYDOWN:
             if event.key == pygame.K_ESCAPE and main_menu.game_over:
                 main_menu.is_started = False
Beispiel #19
0
from garage import Garage
from car import Car

if __name__ == '__main__':
    car = Car()
    garage = Garage()

    while True:
        place = int(
            input('Куда идём?'
                  '\n 1 - Гоночная дорога'
                  '\n 2 - Гараж'
                  '\n 3 - На хуй'
                  '\n 4 - Выйти из гонок\n> '))
        if place == 1:
            print('Дороги нет, катитесь на хуй ')
            continue
        if place == 2:
            garage.action(car)
            continue
        if place == 3:
            print('Ну и пиздуй отсюда')
            continue
        if place == 4:
            break
Beispiel #20
0
 def get_garage1(self):
     from garage import Garage
     return Garage(2, "New York")
Beispiel #21
0
from flask import Flask
from flask import render_template
from flask import jsonify
from garage import Garage

from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
import os

app = Flask(__name__)

garage = Garage()

temperature_feature_flag = os.environ.get(
    'TEMPERATURE_FEATURE_FLAG') is not None


@app.route('/', methods=['GET', 'POST'])
def index():
    return render_template('index.html')


@app.route('/pressGarageDoorButton', methods=['POST'])
def openGarage():
    garage.PressGarageDoorButton()
    return ""


@app.route('/featureFlags', methods=['GET'])
def getFeatureFlags():
Beispiel #22
0
                    break
                except ValueError:
                    screen.addstr(
                        "Please enter valid value for Initial number of levels\n"
                    )
            screen.addstr("Please enter Initial number of slots\n")
            while True:
                try:
                    initial_slots = int(screen.getstr())
                    break
                except ValueError:
                    screen.addstr(
                        "Please enter valid value for Initial number of slots\n"
                    )

            garage_obj = Garage(init_levels=initial_levels,
                                init_slots=initial_slots)
            db["Garage"] = garage_obj
            clearScreen(screen)

        if input_char == '2':
            screen.addstr(
                "Please enter Initial number of slots for new Level\n")
            while True:
                try:
                    initial_slots = int(screen.getstr())
                    break
                except ValueError:
                    screen.addstr(
                        "Please enter valid value for Initial number of slots\n"
                    )
Beispiel #23
0
	def setUp(self):
		self.door_switch_count = 0
		self.door_switch_successful = True
		self.fsm = Garage(door_switch_callback=self.door_switch_count_increment)
Beispiel #24
0
print(
    '1. create_parking_lot (slot number):  to create parking lot based on slot number'
)
print('2. park KA-001-1234 : to park car into parking lot')
print('3. leave KA-001-1234 : to remove car from lot')
print('4. status: to see parking status ')
print('5. help: to see all command list')
print('6. exit: to quit')
play = True
while play:
    inputValue = input('Please write command line: ')
    splitData = inputValue.split(' ')
    splitData[0] = splitData[0].lower()
    try:
        if splitData[0] == 'create_parking_lot':
            parking_lot = Garage(int(splitData[1]))
        elif splitData[0] == 'park':
            parking_lot.park(splitData[1])
        elif splitData[0] == 'leave':
            parking_lot.leave(splitData[1])
        elif splitData[0] == 'status':
            parking_lot.status()
        elif splitData[0] == 'exit':
            play = False
        elif splitData[0] == 'help':
            print('List of Command: ')
            print(
                '1. create_parking_lot (slot number):  to create parking lot based on slot number'
            )
            print('2. park KA-001-1234 : to park car into parking lot')
            print('3. leave KA-001-1234 : to remove car from lot')
Beispiel #25
0
from thirdBathroom import ThirdBathroom
from hiddenRoom import HiddenRoom
from darkHallway import DarkHallway
from musicRoom import MusicRoom
from library import Library
from servantQuarters import ServantQuarters
from livingRoom import LivingRoom
from hallway import Hallway

# ------------------------------------------------------------+
# First Floor Map -- Pedro's rooms
Entrance = Entrance(0, 0)
TeaRoom = TeaRoom(0, 1)
GuestBathroom = GuestBathroom(1, 0)
Kitchen = Kitchen(1, 1)
Garage = Garage(1, 2)
row1 = [Entrance, TeaRoom]
row2 = [GuestBathroom, Kitchen, Garage]
floor1_map = [row1, row2]
# ------------------------------------------------------------+
# ------------------------------------------------------------+
# Second Floor Map -- Jason's rooms
# row1 = [LivingRoom(0, 0), DarkHallway(0, 1)]
# row2 = [ServantQuarters(1, 0), MusicRoom(1, 1), Library(1, 2)]
LivingRoom = LivingRoom(0, 0)
DarkHallway = DarkHallway(0, 1)
ServantQuarters = ServantQuarters(1, 0)
MusicRoom = MusicRoom(1, 1)
Library = Library(1, 2)
row1 = [LivingRoom, DarkHallway]
row2 = [ServantQuarters, MusicRoom, Library]
Beispiel #26
0
 def load_garage(self):
     from garage import Garage
     return Garage.load_cars_from_csv("Elk", "cars.csv")