Esempio n. 1
0
def addVehicle():
    if request.method == 'POST':
        from backend.models.Response import parkingResponse
        #removed logging from this function as it is the primary call and will be logged a lot of times
        response.content_type = 'application/json'
        from backend.controllers.VehicleController import VehicleController
        cstHand = VehicleController()
        try:

            postJson = json.load(request.body)
            obj = mngParking.getParkingDetaisByLotId(postJson["lotId"])
            logging.info("here i amj")
            logging.info(obj)
            if (postJson["vehicleType"] == "two"):
                if (obj["twoWheelerParkingCount"] -
                        obj["twoWheelerOccupied"]) > 0:
                    mngParking.updateParkingLot("two", postJson["lotId"])
            if (postJson["vehicleType"] == "lmv"):
                if (obj["lMVParkingCount"] - obj["lMVOccupied"]) > 0:
                    mngParking.updateParkingLot("lmv", postJson["lotId"])
            logging.info("The data posted is %s" % postJson)
            postResponse = cstHand.add_vehicle_at_lot(postJson)
            return postResponse
        except:
            logging.exception(
                "Some error occurred while trying to create parking")

        res = parkingResponse()
        failure = res.getFailureResponse()
        failure.status.message = 'Error during parking'
        return failure.to_JSON()
Esempio n. 2
0
    def add_parking_lot(self, jsonData):
        res = parkingResponse()
        try:
            status = addParkingLot(jsonData)
            if status:
                success = res.getSuccessResponse()
                success.status.message = 'data posted successfully'
                return success.to_JSON()
        except:
            logging.exception("Unable to post parking lot to DB")

        failure = res.getFailureResponse()
        failure.status.message = 'unable to post data'
        logging.info("parking lot post to DB of FFC failed")
        return failure.to_JSON()
Esempio n. 3
0
def TestMode():
    from backend.controllers.TestModeController import TestModeController
    response.content_type = 'application/json'
    logging.info("Test mode API called")
    res = parkingResponse()
    try:
        if request.query.get("command"):
            if any(word in request.query.get("command")
                   for word in ["start", "stop", "status", "pause"]):
                logging.info("test command is %s" %
                             request.query.get("command"))
                tbobj = TestModeController(request.query.get("command"))
                responsejson = tbobj.ProcessTestModeCommand()
                return responsejson
    except:
        logging.exception("Unable to process request failed")
    failure = res.getFailureResponse()
    failure.status.message = "Unable to process request, command not valid"
    return failure.to_JSON()
Esempio n. 4
0
def addParkingLot():
    if request.method == 'POST':
        from backend.models.Response import parkingResponse
        #removed logging from this function as it is the primary call and will be logged a lot of times
        response.content_type = 'application/json'
        from backend.controllers.ParkingController import ParkingController
        cstHand = ParkingController()
        try:
            postJson = json.load(request.body)
            logging.info("The data posted is %s" % postJson)
            postResponse = cstHand.add_parking_lot(postJson)
            return postResponse
        except:
            logging.exception(
                "Some error occurred while trying to create parking lot")

        res = parkingResponse()
        failure = res.getFailureResponse()
        failure.status.message = 'Error during creating parking lot'
        return failure.to_JSON()
Esempio n. 5
0
def removeVehicle():
    if request.method == 'GET':
        from backend.models.Response import parkingResponse
        logging.info("remove")
        #removed logging from this function as it is the primary call and will be logged a lot of times
        response.content_type = 'application/json'
        vehicleId = request.query.get("vehicleid")
        try:
            logging.info("v id is %s" % vehicleId)
            obj = mngParking.getVechileDetaisl(vehicleId)
            logging.info(obj)
            objLot = mngParking.getParkingDetaisByLotId(obj.lotId)

            logging.info(obj)
            if (obj.vehicleType == "two"):
                rate = objLot["twoWheelerParkingPrice"]
                mngParking.updateRemoveParkingLot("two", obj.lotId)
            if (obj.vehicleType == "lmv"):
                rate = objLot["lMVParkingPrice"]
                mngParking.updateRemoveParkingLot("lmv", obj.lotId)

            TimeStart = obj.insert_time
            now = datetime.datetime.now()
            logging.info(TimeStart)
            logging.info((now - TimeStart).total_seconds())
            delatTime = (now - TimeStart).total_seconds()
            logging.info(rate)
            return {
                "cost": (int)(delatTime / (60 * 60)) * rate,
                "vehicleid": vehicleId,
                "duration": (delatTime) / (60 * 60)
            }
        except:
            logging.exception(
                "Some error occurred while trying to create parking")

        res = parkingResponse()
        failure = res.getFailureResponse()
        failure.status.message = 'Error during removing'
        return failure.to_JSON()
Esempio n. 6
0
    def response_parking(self):
        res = parkingResponse()
        logging.info("response customer controller")
        try:
            data = getParking()
        except:
            logging.exception("Error Unable to get customers")
            failure = res.getFailureResponse()
            failure.status.message = 'get Parking fail'
            return failure.to_JSON()

        success = res.getSuccessResponse()
        if data:
            # for row in data:
            # 	time = datetime.fromtimestamp(row['eventTime'])
            # 	row['eventTime'] = str(time)

            logging.info("get Parking FFC %s" % data)
            success.response = data
        else:
            success.status.message = 'customer count empty'
            logging.info("get Parking FFC empty data: %s" % data)
        return success.to_JSON()