示例#1
0
class AssignmentClass(object):
    s = Slot.search()

    def min_free_slot(self):
        res = self.s.filter('term', status=STATUS_FREE).aggs.metric(
            'assign_slot', 'min', field=SLOT_NO).execute()
        if res:
            return int(res.aggregations.assign_slot.value)
        else:
            return False

    def max_occupied_slot_plus_one(self):
        try:
            res = self.s.filter('term', status=STATUS_OCCUPIED).aggs.metric(
                'assign_slot', 'max', field=SLOT_NO).execute()
        except AttributeError:
            return 1
        else:
            if res.aggregations.assign_slot.value >= MAX_NO_OF_SLOTS:
                return False
            else:
                return int(res.aggregations.assign_slot.value + 1)

    def assign_slot(self):
        assigned_slot = self.min_free_slot()
        return assigned_slot or self.max_occupied_slot_plus_one()
 def regsearch(self, reg_no):
     try:
         s= Slot.search()
         slot = s.filter("term", registration_no = reg_no).execute()[0]
         print slot, slot.registration_no, slot.slot_no
     except NotFoundError:
         return False
     else:
         return dict(registration_no=slot.registration_no, slot_no=slot.slot_no, colour= slot.colour)
 def coloursearch(self, colour):
     try:
         s= Slot.search()
         slot = s.filter("term", colour = colour).execute()
     except NotFoundError:
         return False
     else:
         slots = []
         for car in slot:
             slots.append(dict(registration_no=car.registration_no, slot_no=car.slot_no))
         return slots
示例#4
0
 def regsearch(self, reg_no):
     try:
         s = Slot.search()
         slot = s.filter("term", registration_no=reg_no).execute()[0]
     except NotFoundError:
         return False
     else:
         return {
             'registration_no': slot.registration_no,
             'slot_no': slot.slot_no,
             'colour': slot.colour
         }
示例#5
0
 def coloursearch(self, colour):
     try:
         s = Slot.search()
         slot = s.filter("term", colour=colour).execute()
     except NotFoundError:
         return False
     else:
         slots = []
         for car in slot:
             slots.append({
                 'registration_no': car.registration_no,
                 'slot_no': car.slot_no,
             })
         return slots
示例#6
0
class AvailabilityClass(object):
    s = Slot.search().sort(SLOT_NO)

    def search_free(self):
        return self.s.filter('term', status=STATUS_FREE).execute()

    def search_occupied(self):
        return self.s.filter('term', status=STATUS_OCCUPIED).execute()

    def is_max_slot_no_reached(self):
        max_slot_no = assignmentclass.max_occupied_slot_plus_one()
        return max_slot_no or False

    def is_available(self):
        """
        to check if parking space is available
        :return: bool
        """
        is_free = self.search_free()
        return is_free or self.is_max_slot_no_reached()

    def allfree(self):
        """
        finds all the free slots
        :return: list
        """
        slots = self.search_free()
        available_slots = []
        for slot in slots:
            available_slots.append({'Slot_no': slot.slot_no})

        max_slot_no = self.is_max_slot_no_reached()
        if max_slot_no:
            for i in range(max_slot_no + 1, MAX_NO_OF_SLOTS + 1):
                available_slots.append({'Slot_no': i})
        return available_slots or 'All Occupied'
示例#7
0
def is_duplicate(reg_no):
    return bool(Slot.search().filter('term', registration_no=reg_no).execute())
def is_duplicate(reg_no):
        s = Slot.search()
        if s.filter("term", registration_no=reg_no).execute():
            return True
        else:
            return False