From cb5dc8f5816da12203897a8c63f9f821dd321f41 Mon Sep 17 00:00:00 2001 From: Evangelos Oulis Date: Fri, 17 Jan 2020 13:11:00 +0200 Subject: [PATCH] Update v1.3 --- project.adoc | 4 +++- serverNode/serv.py | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/project.adoc b/project.adoc index 8ca0426..602cf21 100644 --- a/project.adoc +++ b/project.adoc @@ -162,7 +162,9 @@ image::Photos/itops-pizza_as_a_service.png[1000,800] == Διεπαφή Χρήστη (4~ο~ μέρος) -Η διεπαφή του χρήσρη π +Η διεπαφή του χρήστη αποτελείται από μία HTML σελίδα η οποία ενσωματώνει και δύο JavaScript Processes. +Σκοπός αυτής είναι η ανααπαράσταση της κατάστασης του Parking. Η σελίδα λοιπόν ενσωματώνει για κάθε θέση +parking == Autonomous Parking diff --git a/serverNode/serv.py b/serverNode/serv.py index 778f532..2668b93 100644 --- a/serverNode/serv.py +++ b/serverNode/serv.py @@ -33,13 +33,16 @@ myCursor = mydb.cursor() # Define a function that gets the parking status # for all parking codes. def getParkings(): - parks = dict() + parks = [] myCursor.execute("SELECT * FROM PARKING") myRes = myCursor.fetchall() for res in myRes: - parks[res[0]] = res[1] + if res[1] == 1: + parks.append({"no": res[0], "status": True}) + else: + parks.append({"no": res[0], "status": False}) return parks # ================================================================== @@ -65,18 +68,26 @@ class ParkingStatus(Resource): # SQL get all Parking places status. parks = getParkings() + currentParking = {} + for park in parks: + if park['no'] == data['no']: + currentParking = park + break; + thereIs = False toUpdate = False try: - if parks[int(data['no'])] != int(data['status']): + if currentParking['status'] != data['status']: toUpdate = True thereIs = True except IndexError: # handle Index Error thereIs = False + toUpdate = False except KeyError: # handle the KeyError thereIs = False + toUpdate = False if not thereIs: # Make a new insert entry for a new Parking Code. @@ -91,7 +102,7 @@ class ParkingStatus(Resource): mydb.commit() parks = getParkings() - return parks[data['no']], 201 + return currentParking, 201 # ==================================================================