Add some more skeleton to the Parking system

Does contain some *basic* implementation
This commit is contained in:
DjBushido 2013-10-14 13:56:54 -04:00
parent 726ad4ca70
commit 269795202d

View File

@ -48,6 +48,23 @@ class ParkingLot(models.Model):
location = models.CharField(choices=LOT_CHOICES, unique=True, location = models.CharField(choices=LOT_CHOICES, unique=True,
primary_key=True) primary_key=True)
# parkingrating_set # parkingrating_set
@property
def current_ratings(self):
# Return a QuerySet containing only valid ParkingRatings
# (those ratings that aren't from a previous gameday)
return self.parkingrating_set.all()
def get_rating(self):
# Get the current rating of this parking lot
NUM_LOTS = 10
if self.current_ratings.count() < NUM_LOTS:
# Probably raise an exception here, not enough responses yet
pass
else:
total = sum([ ParkingRating.RATING_WEIGHTS[r.rating]
for r in self.parkingrating_set.all().order_by('created')[0:10] ])
return total / NUM_LOTS
class ParkingRating(models.Model): class ParkingRating(models.Model):
@ -61,7 +78,13 @@ class ParkingRating(models.Model):
(RATING_BUSY, 'Busy'), (RATING_BUSY, 'Busy'),
(RATING_FULL, 'Full'), (RATING_FULL, 'Full'),
) )
RATING_WEIGHTS = {
RATING_EMPTY: 0,
RATING_SCATTERED: 33,
RATING_BUSY: 66,
RATING_FULL: 100,
}
rating = models.CharField(max_length=10, choices=RATING_CHOICES) rating = models.CharField(max_length=10, choices=RATING_CHOICES)
created = models.DateTimeField(default=datetime.datetime.now) created = models.DateTimeField(default=datetime.datetime.now)
parking_lot = models.ForeignKey(ParkingLot) parking_lot = models.ForeignKey(ParkingLot)