Browse Source

Update v1.3

master
Evangelos Oulis 5 years ago
parent
commit
cb5dc8f581
  1. 4
      project.adoc
  2. 19
      serverNode/serv.py

4
project.adoc

@ -162,7 +162,9 @@ image::Photos/itops-pizza_as_a_service.png[1000,800]
== Διεπαφή Χρήστη (4~ο~ μέρος) == Διεπαφή Χρήστη (4~ο~ μέρος)
Η διεπαφή του χρήσρη π Η διεπαφή του χρήστη αποτελείται από μία HTML σελίδα η οποία ενσωματώνει και δύο JavaScript Processes.
Σκοπός αυτής είναι η ανααπαράσταση της κατάστασης του Parking. Η σελίδα λοιπόν ενσωματώνει για κάθε θέση
parking
== Autonomous Parking == Autonomous Parking

19
serverNode/serv.py

@ -33,13 +33,16 @@ myCursor = mydb.cursor()
# Define a function that gets the parking status # Define a function that gets the parking status
# for all parking codes. # for all parking codes.
def getParkings(): def getParkings():
parks = dict() parks = []
myCursor.execute("SELECT * FROM PARKING") myCursor.execute("SELECT * FROM PARKING")
myRes = myCursor.fetchall() myRes = myCursor.fetchall()
for res in myRes: 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 return parks
# ================================================================== # ==================================================================
@ -65,18 +68,26 @@ class ParkingStatus(Resource):
# SQL get all Parking places status. # SQL get all Parking places status.
parks = getParkings() parks = getParkings()
currentParking = {}
for park in parks:
if park['no'] == data['no']:
currentParking = park
break;
thereIs = False thereIs = False
toUpdate = False toUpdate = False
try: try:
if parks[int(data['no'])] != int(data['status']): if currentParking['status'] != data['status']:
toUpdate = True toUpdate = True
thereIs = True thereIs = True
except IndexError: except IndexError:
# handle Index Error # handle Index Error
thereIs = False thereIs = False
toUpdate = False
except KeyError: except KeyError:
# handle the KeyError # handle the KeyError
thereIs = False thereIs = False
toUpdate = False
if not thereIs: if not thereIs:
# Make a new insert entry for a new Parking Code. # Make a new insert entry for a new Parking Code.
@ -91,7 +102,7 @@ class ParkingStatus(Resource):
mydb.commit() mydb.commit()
parks = getParkings() parks = getParkings()
return parks[data['no']], 201 return currentParking, 201
# ================================================================== # ==================================================================

Loading…
Cancel
Save