From 374a8f695fabf8429f931918493ccc3cf5d64869 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 22 Feb 2012 19:27:55 +0530 Subject: [PATCH] stats view --- chaloBEST/mumbai/views.py | 28 ++++++++++++++++++++++++++++ chaloBEST/templates/stats.html | 21 ++++++--------------- chaloBEST/urls.py | 2 +- chaloBEST/views.py | 13 +++++++------ 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/chaloBEST/mumbai/views.py b/chaloBEST/mumbai/views.py index 25d520b..20e979c 100644 --- a/chaloBEST/mumbai/views.py +++ b/chaloBEST/mumbai/views.py @@ -43,3 +43,31 @@ def editstops(request): return render_to_response("editstops.html", context) +def stats(request): + total_stops_left = Stop.objects.filter(point=None).count() + areas = [] + for a in Area.objects.all(): + stops = Stop.objects.filter(area=a) + d = { + 'area': a, + #'area_name': a.name, + 'total_stops': stops.count(), + 'remaining_stops': stops.filter(point=None).count() + } + areas.append(d) + routes = [] + for r in Route.objects.all(): + stops = Stop.objects.filter(routedetail__route=r) + d = { + 'route': r, + #'route_name': r.name, + 'total_stops': stops.count(), + 'remaining_stops': stops.filter(point=None).count() + } + routes.append(d) + return render_to_response("stats.html", { + 'total_stops_left': total_stops_left, + 'areas': areas, + 'routes': routes + }) + diff --git a/chaloBEST/templates/stats.html b/chaloBEST/templates/stats.html index 41eb067..29e276f 100644 --- a/chaloBEST/templates/stats.html +++ b/chaloBEST/templates/stats.html @@ -36,16 +36,7 @@ {% endblock %} @@ -55,13 +46,13 @@ ChaloBEST! The Stats.. -

We have {{ stops_left }} stops left!



+

We have {{ total_stops_left }} stops left!



-

Routes needing some love..


+

Routes needing some love..


    - {% for r in route_stat %} + {% for r in routes %}
  • - {{ r.route.alias }} needs {{ r.neededstops }} stop locations. + {{ r.route.alias }} needs {{ r.remaining_stops }} stop locations out of {{ r.total_stops }}.
  • {% endfor %}
@@ -69,9 +60,9 @@

Areas needing some love..


    - {% for a in area_stat %} + {% for a in areas %}
  • - {{ a.area.name }} needs {{ a.neededstops }} stop locations. + {{ a.area.name }} needs {{ a.remaining_stops }} stop locations out of {{ a.total_stops }}.
  • {% endfor %}
diff --git a/chaloBEST/urls.py b/chaloBEST/urls.py index aa1d5ef..f7dde24 100644 --- a/chaloBEST/urls.py +++ b/chaloBEST/urls.py @@ -12,7 +12,7 @@ urlpatterns = patterns('', # Example: # (r'^chaloBEST/', include('chaloBEST.foo.urls')), url(r'^$','chaloBEST.views.index', name='index'), - url(r'^stats/$','chaloBEST.views.stats', name='stats'), + url(r'^stats/$','mumbai.views.stats', name='stats'), url(r'^static/(?P.*)$','django.views.static.serve', {'document_root':'./static'}), (r'^routes/$', 'mumbai.views.routes'), (r'^route/(?P[a-zA-Z0-9\s\-]*?)/$', 'mumbai.views.route'), diff --git a/chaloBEST/views.py b/chaloBEST/views.py index db970db..86985c1 100644 --- a/chaloBEST/views.py +++ b/chaloBEST/views.py @@ -27,12 +27,13 @@ def stats(request): area_stat = [] for area in arealist: - area_stops = area.stop_set.all() - astops_left = len(area_stops) - for stp in area_stops: - if stp.point: - astops_left-=1 - + # area_stops = area.stop_set.all() + # astops_left = len(area_stops) + astops_left = Stop.objects.filter(area=area).filter(point=None).count() +# for stp in area_stops: +# if stp.point: +# astops_left-=1 +# area_stat.append({'area':area,'neededstops':astops_left})