157 lines
5.2 KiB
Python
157 lines
5.2 KiB
Python
# This is an auto-generated Django model module.
|
|
# You'll have to do the following manually to clean this up:
|
|
# * Rearrange models' order
|
|
# * Make sure each model has one field with primary_key=True
|
|
# Feel free to rename the models, but don't rename db_table values or field names.
|
|
#
|
|
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
|
|
# into your database.
|
|
|
|
from django.db import models
|
|
|
|
|
|
class Acexpressroutes(models.Model):
|
|
routecode = models.CharField(max_length=255)
|
|
stopserial = models.IntegerField()
|
|
stageno = models.IntegerField()
|
|
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
|
|
stage = models.CharField(max_length=255)
|
|
km = models.FloatField()
|
|
stopname = models.CharField(max_length=255)
|
|
class Meta:
|
|
db_table = u'acexpressroutes'
|
|
|
|
class Areamaster(models.Model):
|
|
areacode = models.IntegerField(unique=True)
|
|
areaname = models.CharField(max_length=255)
|
|
class Meta:
|
|
db_table = u'areamaster'
|
|
|
|
class Expressroutes(models.Model):
|
|
routecode = models.CharField(max_length=255)
|
|
stopserial = models.IntegerField()
|
|
stageno = models.IntegerField()
|
|
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
|
|
stage = models.CharField(max_length=255)
|
|
km = models.FloatField()
|
|
stopname = models.CharField(max_length=255)
|
|
class Meta:
|
|
db_table = u'expressroutes'
|
|
|
|
DAYS_MAP = {
|
|
"Monday": ['MF', 'FW', 'MS+HOL'],
|
|
"Tuesday": ['MF', 'FW', 'MS+HOL'],
|
|
"Wednesday": ['MF', 'FW', 'MS+HOL'],
|
|
"Thursday": ['MF', 'FW', 'MS+HOL'],
|
|
"Friday": ['MF', 'FW', 'MS+HOL'],
|
|
"Saturday": ['SAT','FW', 'MS+HOL'],
|
|
"Sunday": ['SH', 'FW'],
|
|
"Holiday": ['HOL', 'SH', 'MS+HOL'],
|
|
}
|
|
|
|
DAYS_OF_WEEK = {
|
|
1: 'Monday',
|
|
2: 'Tuesday',
|
|
3: 'Wednesday',
|
|
4: 'Thursday',
|
|
5: 'Friday',
|
|
6: 'Saturday',
|
|
7: 'Sunday'
|
|
}
|
|
|
|
class Atlas(models.Model):
|
|
routecode = models.CharField(max_length=255)
|
|
route = models.CharField(max_length=255)
|
|
busfrom = models.CharField(max_length=255)
|
|
firstfrom = models.CharField(max_length=255)
|
|
lastfrom = models.CharField(max_length=255)
|
|
busto = models.CharField(max_length=255)
|
|
firstto = models.CharField(max_length=255)
|
|
lastto = models.CharField(max_length=255)
|
|
routespan = models.CharField(max_length=255)
|
|
runtime7to11 = models.CharField(max_length=255)
|
|
runtime11to17 = models.CharField(max_length=255)
|
|
runtime17toend = models.CharField(max_length=255)
|
|
runtimenight = models.CharField(max_length=255)
|
|
headwaybefore7 = models.CharField(max_length=255)
|
|
headway7to11 = models.CharField(max_length=255)
|
|
headway11to17 = models.CharField(max_length=255)
|
|
headway17to20 = models.CharField(max_length=255)
|
|
headway20tolast = models.CharField(max_length=255)
|
|
reliefpoint = models.CharField(max_length=255)
|
|
traveltime = models.CharField(max_length=255)
|
|
scheduletype = models.CharField(max_length=255)
|
|
# id = models.IntegerField(unique=True)
|
|
class Meta:
|
|
db_table = u'atlas'
|
|
|
|
@staticmethod
|
|
def get_schedule(qset, schedules):
|
|
for s in schedules:
|
|
res = qset.filter(scheduletype__exact=s)
|
|
if res.count() > 0:
|
|
return res
|
|
return qset[0]
|
|
|
|
@classmethod
|
|
def get_atlas(kls, route, dateObj):
|
|
dayofweek = dateObj.isoweekday()
|
|
dayString = DAYS_OF_WEEK[dayofweek]
|
|
schedules = DAYS_MAP[dayString]
|
|
atlases = kls.objects.filter(route__iexact=route)
|
|
if atlases.count() < 1:
|
|
return False
|
|
a = kls.get_schedule(atlases, schedules)
|
|
if not a:
|
|
return False
|
|
return a.get_data(dateObj)
|
|
|
|
def get_data(self, dateObj):
|
|
d = {
|
|
'route': self.route,
|
|
'from': self.busfrom,
|
|
'to': self.busto,
|
|
# 'lastbusfrom': self.lastfrom,
|
|
# 'lastbusto': self.lastto,
|
|
|
|
}
|
|
return d
|
|
|
|
class Routetype(models.Model):
|
|
typenumber = models.IntegerField()
|
|
routetype = models.CharField(max_length=255)
|
|
class Meta:
|
|
db_table = u'routetype'
|
|
|
|
class Regularroutes(models.Model):
|
|
routecode = models.CharField(max_length=255)
|
|
stopserial = models.IntegerField()
|
|
stageno = models.IntegerField()
|
|
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
|
|
stage = models.CharField(max_length=255)
|
|
km = models.FloatField()
|
|
stopname = models.CharField(max_length=255)
|
|
class Meta:
|
|
db_table = u'regularroutes'
|
|
|
|
class Stopmaster(models.Model):
|
|
stopcode = models.IntegerField(unique=True)
|
|
stopname = models.CharField(max_length=255)
|
|
areacode = models.ForeignKey(Areamaster, db_column='areacode')
|
|
displayname = models.CharField(max_length=255)
|
|
smlength = models.IntegerField()
|
|
class Meta:
|
|
db_table = u'stopmaster'
|
|
|
|
class Asroutes(models.Model):
|
|
routecode = models.CharField(max_length=255)
|
|
stopserial = models.IntegerField()
|
|
stageno = models.IntegerField()
|
|
stopcode = models.ForeignKey(Stopmaster, db_column='stopcode')
|
|
stage = models.CharField(max_length=255)
|
|
km = models.FloatField()
|
|
stopname = models.CharField(max_length=255)
|
|
class Meta:
|
|
db_table = u'asroutes'
|
|
|