From 922689170041ffb67e349e50a0c9d36f37228364 Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Thu, 23 Feb 2012 12:53:37 +0100 Subject: [PATCH] stats revised. --- chaloBEST/gtfs/gtfs_export.py | 44 +++++++++++++++++++++++++--------- chaloBEST/gtfs/stop_times.txt | 32 ------------------------- chaloBEST/mumbai/views.py | 19 +++++++++++++-- chaloBEST/templates/stats.html | 20 +++++++++------- chaloBEST/views.py | 1 - 5 files changed, 61 insertions(+), 55 deletions(-) diff --git a/chaloBEST/gtfs/gtfs_export.py b/chaloBEST/gtfs/gtfs_export.py index c367be7..740bb61 100644 --- a/chaloBEST/gtfs/gtfs_export.py +++ b/chaloBEST/gtfs/gtfs_export.py @@ -200,9 +200,7 @@ def getserial(rdlist,stop): #check if rdlist is of a ring route.. if rdlist[0].route.code[3]== 'R' or '4' : # write ring specific code here. rings have multiple occuring stops, which one to choose?? - return None - - + return None for rd in rdlist: if(rd.stop==stop): @@ -215,15 +213,31 @@ def export_stop_times(routelist): #routelist = getRoutesHavingAllLocs() #1. get routeDetails - #2. + #2. get unique routes as unr and the routeDetails subset as rd_subset for that uniqueroute + #3. get unr.routeschedule as unr.rs ?? why is it multiple? + #4. get total distance as tdist from rd_subset + #5. get runtime from unr.rs + #6. if runtime1 is null, then runtime = abs(first_from - first_to) + #7. avgspeed = tdist/runtime... if runtime is not available then ?? + #8. + for r in routelist: - rds = RouteDetail.objects.filter(route=r).order_by('serial') + rdlist = RouteDetail.objects.filter(route=r).order_by('serial') sr_no=0 - for unr in UniqueRoute.objects.filter(route=r).order_by('id'): + unrs = UniqueRoute.objects.filter(route=r).order_by('id') + + for unr in unrs: from_stop = unr.from_stop - to_stop = unr.to_stop - rd_subset = rds[getserial(rdlist,from_stop):getserial(rdlist,to_stop)] - sr_no +=1 + to_stop = unr.to_stop + rd_subset = rdlist[getserial(rdlist,from_stop):getserial(rdlist,to_stop)] + dist=0 + for rd in rd_subset: + dist += rd.km + runtime = unr.runtime1 + if not runtime: + rs = unr.routeschedule_set.all()[0] + #if rs. + sr_no +=1 for rd in rd_subset: filedude.writerow([r.code+"_"+sr_no,"","",rd.stop.id,rd.serial]) @@ -236,7 +250,7 @@ stop_times.txt 2. Get rdlist = routedetails for that route.order_by('serial'). Get UniqueRoutes for the route. 3. --- scenario -- Not considering uniqueroutes-- 3.1 For rd in rdlist -3.1.1 filewrite (trip_id,,,stopid,stop.serial) +73.1.1 filewrite (trip_id,,,stopid,stop.serial) ----alternate scenario 3. For each UniqueRoute, get from_to stops list (rdsubset) from RouteDetail list @@ -267,5 +281,13 @@ def export_frequencies(): filedude.writerow(["289_1","16:00:00","22:00:00",420]) filedude.writerow(["289_1","07:00:00","11:00:00",540]) - +def fire_up(): + routelist = getRoutesHavingAllLocs() + export_routes(routelist) + #export_stops() + export_frequencies() + export_stop_times() + export_calendar() + export_trips() + export_agency() diff --git a/chaloBEST/gtfs/stop_times.txt b/chaloBEST/gtfs/stop_times.txt index 228820a..5c7ab2e 100644 --- a/chaloBEST/gtfs/stop_times.txt +++ b/chaloBEST/gtfs/stop_times.txt @@ -1,33 +1 @@ trip_id,arrival_time,departure_time,stop_id,stop_sequence -2820_1,,,1188,1 -2820_1,,,1189,2 -2820_1,,,1190,3 -2820_1,,,1191,4 -2820_1,,,1834,5 -2820_1,,,1192,6 -2820_1,,,1193,7 -2820_1,,,1214,8 -2820_1,,,1197,9 -2820_1,,,1199,10 -2820_1,,,1198,11 -2894_1,,,1188,1 -2894_1,,,1189,2 -2894_1,,,1190,3 -2894_1,,,1191,4 -2894_1,,,1834,5 -2894_1,,,1192,6 -2894_1,,,1193,7 -2894_1,,,1197,8 -2894_1,,,1822,9 -2894_1,,,1928,10 -2894_1,,,1929,11 -2894_1,,,1196,12 -2894_1,,,1195,13 -2894_1,,,1194,14 -2894_1,,,1193,15 -2894_1,,,1192,16 -2894_1,,,1834,17 -2894_1,,,1191,18 -2894_1,,,1190,19 -2894_1,,,1189,20 -2894_1,,,1188,21 diff --git a/chaloBEST/mumbai/views.py b/chaloBEST/mumbai/views.py index 20e979c..ffdb888 100644 --- a/chaloBEST/mumbai/views.py +++ b/chaloBEST/mumbai/views.py @@ -45,6 +45,7 @@ def editstops(request): def stats(request): total_stops_left = Stop.objects.filter(point=None).count() + total_stops = Stop.objects.count() areas = [] for a in Area.objects.all(): stops = Stop.objects.filter(area=a) @@ -52,7 +53,9 @@ def stats(request): 'area': a, #'area_name': a.name, 'total_stops': stops.count(), - 'remaining_stops': stops.filter(point=None).count() + 'remaining_stops': stops.filter(point=None).count(), + 'stops_done': stops.filter(point__isnull=False).count(), + } areas.append(d) routes = [] @@ -62,12 +65,24 @@ def stats(request): 'route': r, #'route_name': r.name, 'total_stops': stops.count(), - 'remaining_stops': stops.filter(point=None).count() + 'remaining_stops': stops.filter(point=None).count(), + 'stops_done': stops.filter(point__isnull=False).count(), } routes.append(d) + + areas_sorted = sorted(areas, key=lambda k: k['remaining_stops']) + + routes_sorted = sorted(routes, key=lambda k: k['remaining_stops']) + + routes = routes_sorted + areas = areas_sorted return render_to_response("stats.html", { + 'total_stop_count': total_stops, 'total_stops_left': total_stops_left, 'areas': areas, 'routes': routes }) + + + diff --git a/chaloBEST/templates/stats.html b/chaloBEST/templates/stats.html index 29e276f..39e994e 100644 --- a/chaloBEST/templates/stats.html +++ b/chaloBEST/templates/stats.html @@ -42,27 +42,29 @@ {% block body %}
-

- ChaloBEST! The Stats.. +

ChaloBEST! The Stats..

-

We have {{ total_stops_left }} stops left!



- -

Routes needing some love..


+

Total Stops : {{ total_stop_count }}
Stops left : {{ total_stops_left }}



+
+ +

Routes:


+
- -

Areas needing some love..


+

Areas:


    {% for a in areas %}
  • - {{ a.area.name }} needs {{ a.remaining_stops }} stop locations out of {{ a.total_stops }}. + {{ a.area.name }} - {{ a.stops_done }} / {{ a.total_stops }}. +
  • {% endfor %}
diff --git a/chaloBEST/views.py b/chaloBEST/views.py index 86985c1..d67f0ac 100644 --- a/chaloBEST/views.py +++ b/chaloBEST/views.py @@ -51,4 +51,3 @@ def stats(request): #return ret return render_to_response('stats.html', ret) -