From 78741aca7b38cf01e04e1519ac09756f7989acaf Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Sun, 22 Jan 2012 08:18:50 +0530 Subject: [PATCH] Changes made to home page and started work on data_mapper, models file tweaked a bit to allow nulls in marathi fields --- chaloBEST/imports/data_mapper.py | 200 ++++++++++++++++++------------- chaloBEST/mumbai/models.py | 6 +- chaloBEST/templates/index.html | 34 ++++-- 3 files changed, 138 insertions(+), 102 deletions(-) diff --git a/chaloBEST/imports/data_mapper.py b/chaloBEST/imports/data_mapper.py index c94aa43..e3715da 100644 --- a/chaloBEST/imports/data_mapper.py +++ b/chaloBEST/imports/data_mapper.py @@ -6,68 +6,75 @@ import json import datetime import sys -CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/db_csv_files/AreaMaster.csv", "r")) -CsvFile.next() -for entry in CsvFile: - obj = Area(int(entry[0]), entry[1]) - obj.save() - print obj.a_code, obj.areanm +def AreaLoader(): + CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/db_csv_files/AreaMaster.csv", "r")) + CsvFile.next() + for entry in CsvFile: + obj = Area(int(entry[0]), entry[1]) + obj.save() + print obj.a_code, obj.areanm -print "----- " + print "----- " + return -CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/chaloBEST/db_csv_files/FareMaster.csv", "r")) -test = CsvFile.next() -print test -for entry in CsvFile: - obj = Fare(slab=float(entry[0]), ordinary=int(entry[1]), limited=int(entry[2]), express=int(entry[3]), ac=int(entry[4]), ac_express=int(entry[5])) - obj.save() - print obj.__dict__ +def FareLoader(): + CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/chaloBEST/db_csv_files/FareMaster.csv", "r")) + test = CsvFile.next() + print test + for entry in CsvFile: + obj = Fare(slab=float(entry[0]), ordinary=int(entry[1]), limited=int(entry[2]), express=int(entry[3]), ac=int(entry[4]), ac_express=int(entry[5])) + obj.save() + print obj.__dict__ + return +def RoadLoader(): + CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/db_csv_files/RoadMaster.csv", "r")) + test = CsvFile.next() + print test + for entry in CsvFile: + obj = Road(roadcd=int(entry[0]), roadnm=str(entry[1])) + obj.save() + print obj.__dict__ + return -CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/db_csv_files/RoadMaster.csv", "r")) -test = CsvFile.next() -print test -for entry in CsvFile: - obj = Road(roadcd=int(entry[0]), roadnm=str(entry[1])) - obj.save() - print obj.__dict__ +def RouteLoader(): + CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/db_csv_files/RouteMaster.csv", "r"), delimiter='\t') + test = CsvFile.next() + print test + for entry in CsvFile: + obj = Route(route=entry[0], routealias=entry[1], from_stop=entry[2], to_stop=entry[3], distance=float(entry[4]), stages=int(entry[5])) + print obj.__dict__ + return +def RouteDetailsLoader(): + CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/db_csv_files/RouteDetails.csv", "r"), delimiter='\t') + test = CsvFile.next() + print test + for entry in CsvFile: + try: + print obj.__dict__ + obj = RouteDetails(rno=entry[0], stopsr=int(entry[1]), stopdcd=Stop.objects.get(stopcd=int(entry[2])), stage=entry[3].startswith('1'), km=float(entry[4])) + + except: + f.write(obj.__dict__) + return +#RNO,STOPSR,STOPCD,STAGE,KM -CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/db_csv_files/RouteMaster.csv", "r"), delimiter='\t') -test = CsvFile.next() -print test -for entry in CsvFile: - obj = Route(route=entry[0], routealias=entry[1], from_stop=entry[2], to_stop=entry[3], distance=float(entry[4]), stages=int(entry[5])) - print obj.__dict__ +def AreaLoader(): + CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/chaloBEST/db_csv_files/RouteDetails.csv", "r"), delimiter='\t') + f= open('RouteDetailsErrors', 'w') + test = CsvFile.next() + print test + for entry in CsvFile: + try: + obj = RouteDetails(rno=entry[0], stopsr=int(entry[1]), stopcd=Stop.objects.get(stopcd=int(entry[2])), stage=(lambda:entry[3].startswith('1'), lambda:None)[ entry[3] == '' ](), km=(lambda:None,lambda:float(entry[4]))[ entry[4] != '' ]() ) + obj.save() + obj.__dict__ + except : + f.write(str(sys.exc_info()[0]) + str(entry) + '\n') + print "Error:", sys.exc_info()[0] - -CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/db_csv_files/RouteDetails.csv", "r"), delimiter='\t') -test = CsvFile.next() -print test -for entry in CsvFile: - try: - print obj.__dict__ - obj = RouteDetails(rno=entry[0], stopsr=int(entry[1]), stopdcd=Stop.objects.get(stopcd=int(entry[2])), stage=entry[3].startswith('1'), km=float(entry[4])) - - except: - f.write(obj.__dict__) - -RNO,STOPSR,STOPCD,STAGE,KM - -CsvFile = csv.reader(open("/home/johnson/Desktop/chaloBEST/chaloBEST/db_csv_files/RouteDetails.csv", "r"), delimiter='\t') -f= open('RouteDetailsErrors', 'w') -test = CsvFile.next() -print test -for entry in CsvFile: - try: - obj = RouteDetails(rno=entry[0], stopsr=int(entry[1]), stopcd=Stop.objects.get(stopcd=int(entry[2])), stage=(lambda:entry[3].startswith('1'), lambda:None)[ entry[3] == '' ](), km=(lambda:None,lambda:float(entry[4]))[ entry[4] != '' ]() ) - obj.save() - obj.__dict__ - except : - f.write(str(sys.exc_info()[0]) + str(entry) + '\n') - print "Error:", sys.exc_info()[0] - -f.close() + f.close() date_format = entry[0].rsplit('.') theday = int(date_format[0]) @@ -78,41 +85,62 @@ import datetime def holiday_loader(): -CsvFile = csv.reader(open(join(PROJECT_ROOT, "../db_csv_files/Holidays.csv"), "r"), delimiter="\t") -f= open('HolidaysErrors', 'w') -test = CsvFile.next() -print test -for entry in CsvFile: - try: - date_format = entry[0].rsplit('.') - theday = int(date_format[0]) - themonth = int(date_format[1]) - theyear = int('20'+ date_format[2]) - obj = Holiday(h_date=datetime.date(day=theday, month=themonth, year=theyear), h_name=str(entry[1])) - obj.save() - obj.__dict__ - except : - f.write(str(sys.exc_info()[0]) + str(entry) + '\n') - print "Error:", sys.exc_info()[0] + CsvFile = csv.reader(open(join(PROJECT_ROOT, "../db_csv_files/Holidays.csv"), "r"), delimiter="\t") + f= open('HolidaysErrors', 'w') + test = CsvFile.next() + print test + for entry in CsvFile: + try: + date_format = entry[0].rsplit('.') + theday = int(date_format[0]) + themonth = int(date_format[1]) + theyear = int('20'+ date_format[2]) + obj = Holiday(h_date=datetime.date(day=theday, month=themonth, year=theyear), h_name=str(entry[1])) + obj.save() + obj.__dict__ + except : + f.write(str(sys.exc_info()[0]) + str(entry) + '\n') + print "Error:", sys.exc_info()[0] + + f.close() + return + +def RouteLoader(): + CsvFile = csv.reader(open(join(PROJECT_ROOT, "../db_csv_files/Route.csv"), "r"), delimiter="\t") + f= open(join(PROJECT_ROOT, "../db_csv_files/RouteErrors.csv"), 'w') + header = CsvFile.next() + print header + for entry in CsvFile: + try: + obj = Route(route=entry[0], routealias=entry[1], from_stop=entry[2], to_stop=entry[3], distance=float(entry[4]), stages=int(entry[5])) + obj.save() + obj.__dict__ + except : + f.write(str(sys.exc_info()[0]) + str(entry) + '\n') + print "Error:", sys.exc_info()[0] + str(entry) + + f.close() + return + + obj = Route(route=entry[0], routealias=entry[1], from_stop=entry[2], to_stop=entry[3], distance=float(entry[4]), stages=int(entry[5])) -f.close() def Depot_loader(): -CsvFile = csv.reader(open(join(PROJECT_ROOT, "../db_csv_files/Depot.csv"), "r"), delimiter="\t") -f= open(join(PROJECT_ROOT, "../db_csv_files/DepotErrors.csv"), 'w') -header = CsvFile.next() -print header -for entry in CsvFile: - try: - obj = Depot(depot_code=str(entry[0]),depot_name=str(entry[1]), stop = Stop.objects.get(stopcd=int(entry[2]))) - obj.save() - obj.__dict__ - except : - f.write(str(sys.exc_info()[0]) + str(entry) + '\n') - print "Error:", sys.exc_info()[0] + str(entry) - -f.close() + CsvFile = csv.reader(open(join(PROJECT_ROOT, "../db_csv_files/Depot.csv"), "r"), delimiter="\t") + f= open(join(PROJECT_ROOT, "../db_csv_files/DepotErrors.csv"), 'w') + header = CsvFile.next() + print header + for entry in CsvFile: + try: + obj = Depot(depot_code=str(entry[0]),depot_name=str(entry[1]), stop = Stop.objects.get(stopcd=int(entry[2]))) + obj.save() + obj.__dict__ + except : + f.write(str(sys.exc_info()[0]) + str(entry) + '\n') + print "Error:", sys.exc_info()[0] + str(entry) + f.close() + return diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index eb0a3d3..3063b4b 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -42,14 +42,14 @@ SCHED = { class Area(models.Model): a_code = models.IntegerField(primary_key=True) areanm = models.TextField(blank=True, max_length=255) - areanm_mr= models.TextField(blank=True, max_length=512) + areanm_mr= models.TextField(null=True, blank=True, max_length=512) #null=True, def __unicode__(self): return self.areanm class Road(models.Model): roadcd = models.IntegerField(primary_key=True) roadnm = models.TextField(blank=True, max_length=255) - #roadnm_mr= models.TextField(blank=True, max_length=512) + roadnm_mr= models.TextField(null=True, blank=True, max_length=512) def __unicode__(self): return self.roadnm @@ -74,7 +74,7 @@ class Stop(models.Model): roadcd = models.ForeignKey(Road) a_code = models.ForeignKey(Area) depot = models.TextField(max_length=255) # should actually be a foreign key to a depotMaster, - stopnm_mr= models.TextField(blank=True, max_length=512) + stopnm_mr= models.TextField(null=True, blank=True, max_length=512)#null=True, def __unicode__(self): return self.stopnm diff --git a/chaloBEST/templates/index.html b/chaloBEST/templates/index.html index e371fbc..61785b4 100644 --- a/chaloBEST/templates/index.html +++ b/chaloBEST/templates/index.html @@ -6,25 +6,33 @@ ChaloBEST - - -
+ +
-
-

Free and simple tools to find bus routes in Mumbai, coming soon to your phone.

-

Try out our mobile website, SMS service, and Android application.

-

-

Want to get involved or learn more? Check out our project wiki or join our mailing list. -
-

ChaloBEST is a collaboration of Mumbai Environmental Social Network (MESN), SPARC Systems, CAMP, and
Homi Bhabha Centre for Science Education, TIFR, with support from BEST (Brihanmumbai Electric Supply & Transport Undertaking).

-
-
- +
+

Free and simple tools to find your way through Mumbai, coming soon to SMS, web and smartphone.

+ +

Want to get involved or learn more? Check out our project wiki or join our mailing list. +
+

+

+ ChaloBEST is a collaboration of CAMP, MacGregor TechKnowlogy, SPARC Systems, UserINNOV, and the
Homi Bhabha Centre for Science Education, Tata Institute of Fundamental Research (TIFR). +

+

+ We are funded by the Indian Institute of Human Settlements as the first-prize winners in the
Sankranti Transform Urban India competition at the India Urban Conference 2011. +

+ +

We are also supported by the Traffic Planning Department of the BEST (Brihanmumbai Electric Supply & Transport Undertaking). +

+ +
+
+