This commit is contained in:
Johnson Chetty 2012-02-21 13:49:48 +01:00
commit 0bae5eaf10
4 changed files with 31 additions and 14 deletions

View File

@ -8,6 +8,8 @@ import sys
from django.contrib.gis.geos import Point
from imports.import_atlas import getFromToStopsForRoute, importUniqueRoutes
from imports import postload_cleanup as postclean
from decimal import Decimal
globalerr = []
def RouteType_save(entry):
@ -15,6 +17,14 @@ def RouteType_save(entry):
obj.save()
#print obj.__dict__
def getFromToStopsFromRouteDetails(code):
routeDetails = RouteDetail.objects.filter(route_code=code).order_by('serial')
if routeDetails.count() == 0:
return None
fromStop = routeDetails[0].stop
toStop = routeDetails[routeDetails.count() -1].stop
return (fromStop, toStop,)
def Route_save(entry):
"""
try:
@ -27,11 +37,11 @@ def Route_save(entry):
except IndexError:
t_stop = None
"""
from_to = getFromToStopsForRoute(entry[0])
from_to = getFromToStopsFromRouteDetails(entry[0])
if from_to is None:
globalerr.append({"data" :entry[0], error:["Route not found"]})
#obj = Route(code=entry[0], alias=entry[1], from_stop_txt=entry[2], to_stop_txt=entry[3], from_stop=from_to[0], to_stop=from_to[1], distance=float(entry[4]), stages=int(entry[5]))
#obj = Route(code=entry[0], alias=entry[1], from_stop_txt=entry[2], to_stop_txt=entry[3], from_stop=from_to[0], to_stop=from_to[1], distance=Decimal(entry[4]), stages=int(entry[5]))
obj = Route(
@ -41,7 +51,7 @@ def Route_save(entry):
from_stop_txt=str(entry[2]),
to_stop_txt=str(entry[3]),
to_stop=from_to[1],
distance=float(entry[4]),
distance=Decimal(entry[4]),
stages=int(entry[5]))
obj.save()
@ -98,7 +108,7 @@ def RouteDetail_save(entry):
serial=int(entry[1]),
stop= temp_stop,
stage=(lambda:entry[3].startswith('1'), lambda:None)[ entry[3] == '' ](),
km=(lambda:None,lambda:float(entry[4]))[ entry[4] != '' ]())
km=(lambda:None,lambda:Decimal(entry[4]))[ entry[4] != '' ]())
obj.save()
#print obj.__dict__
@ -109,7 +119,7 @@ def Road_save(entry):
def Fare_save(entry):
obj = Fare(
slab=float(entry[0]),
slab=Decimal(entry[0]),
ordinary=int(entry[1]),
limited=int(entry[2]),
express=int(entry[3]),

View File

@ -4,8 +4,9 @@ from django.contrib.auth.decorators import login_required
def route(request, slug):
srid = int(request.GET.get("srid", 4326))
route = get_object_or_404_json(Route, slug=slug)
stops = [r.stop.get_geojson() for r in RouteDetail.objects.filter(route=route)]
stops = [r.stop.get_geojson(srid=srid) for r in RouteDetail.objects.filter(route=route)]
return render_to_json_response({
'route': route.get_dict(),
'stops': {
@ -15,8 +16,9 @@ def route(request, slug):
})
def area(request, slug):
srid = int(request.GET.get("srid", 4326))
area = get_object_or_404_json(Area, slug=slug)
stops = [stop.get_geojson() for stop in Stop.objects.filter(area=area)]
stops = [stop.get_geojson(srid=srid) for stop in Stop.objects.filter(area=area)]
return render_to_json_response({
'area': area.get_dict(),
'stops': {
@ -44,12 +46,13 @@ def areas(request):
def stops(request):
qset = Stop.objects.all()
srid = int(request.GET.get("srid", 4326))
if request.GET.has_key('q'):
q = request.GET.get('q', '')
qset = qset.filter(display_name__icontains=q) #FIXME: This definitely needs to be a Q object with OR lookups for area name, road name, etc.
return render_to_json_response({
'type': 'FeatureCollection',
'features': [stop.get_geojson() for stop in qset]
'features': [stop.get_geojson(srid=srid) for stop in qset]
})
@ -63,4 +66,5 @@ def stop(request, slug):
return render_to_json_response(stop.from_geojson(request.POST))
else:
stop = get_object_or_404_json(Stop, slug=slug)
return render_to_json_response(stop.get_geojson()) #FIXME: please don't repeat this code, its retarded.
srid = int(request.GET.get("srid", 4326))
return render_to_json_response(stop.get_geojson(srid=srid)) #FIXME: please don't repeat this code, its retarded.

View File

@ -122,6 +122,7 @@ class Stop(models.Model):
}
def get_geojson(self, srid=4326):
print srid
if self.point is not None:
geom = json.loads(self.point.transform(srid, True).geojson)
else:

View File

@ -17,7 +17,7 @@ var API_BASE = "/1.0/",
var $list = $('#' + name + 'List');
var url = API_BASE + name + "/";
var $loadingLi = $('<div />').text("Loading...").appendTo($list);
$.getJSON(url, {}, function(items) {
$.getJSON(url, {'srid': 3857}, function(items) {
$loadingLi.remove();
$.each(items, function(i,v) {
var $li = $('<div />')
@ -52,7 +52,7 @@ var API_BASE = "/1.0/",
var url = API_BASE + name + "/" + $target.find(".listItemText").text();
$target.data("loading", true);
var $loading = $('<span />').addClass("loadingSpan").text("Loading...").appendTo($target);
$.getJSON(url, {}, function(obj) {
$.getJSON(url, {'srid': 3857}, function(obj) {
$loading.remove();
var stopsGeojson = obj.stops;
var stops = stopsGeojson.features;
@ -138,7 +138,7 @@ var API_BASE = "/1.0/",
}
function initMap() {
var center = new OpenLayers.LonLat(72.855211097628413, 19.010775291486027);
var center = new OpenLayers.LonLat(8110203.9998955, 2170000.4068373);
map = new OpenLayers.Map("mapCol", {
projection: new OpenLayers.Projection("EPSG:900913")
});
@ -148,8 +148,10 @@ var API_BASE = "/1.0/",
layers[0] = new OpenLayers.Layer.OSM();
geojson_format = new OpenLayers.Format.GeoJSON();
//yes, jsonLayer is global. Yes, I know it's wrong.
jsonLayer = layers[1] = new OpenLayers.Layer.Vector("Bus Stops", {
geometryType: 'Point', projection: new OpenLayers.Projection("EPSG:4326") });
jsonLayer = layers[1] = new OpenLayers.Layer.Vector({
geometryType: 'Point',
projection: new OpenLayers.Projection("EPSG:4326")
});
// map.addLayer(vector_layer);
map.addLayers(layers);
map.setCenter(center, 12);