merged
This commit is contained in:
commit
0bae5eaf10
|
@ -8,6 +8,8 @@ import sys
|
||||||
from django.contrib.gis.geos import Point
|
from django.contrib.gis.geos import Point
|
||||||
from imports.import_atlas import getFromToStopsForRoute, importUniqueRoutes
|
from imports.import_atlas import getFromToStopsForRoute, importUniqueRoutes
|
||||||
from imports import postload_cleanup as postclean
|
from imports import postload_cleanup as postclean
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
globalerr = []
|
globalerr = []
|
||||||
|
|
||||||
def RouteType_save(entry):
|
def RouteType_save(entry):
|
||||||
|
@ -15,6 +17,14 @@ def RouteType_save(entry):
|
||||||
obj.save()
|
obj.save()
|
||||||
#print obj.__dict__
|
#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):
|
def Route_save(entry):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
@ -27,11 +37,11 @@ def Route_save(entry):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
t_stop = None
|
t_stop = None
|
||||||
"""
|
"""
|
||||||
from_to = getFromToStopsForRoute(entry[0])
|
from_to = getFromToStopsFromRouteDetails(entry[0])
|
||||||
if from_to is None:
|
if from_to is None:
|
||||||
globalerr.append({"data" :entry[0], error:["Route not found"]})
|
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(
|
obj = Route(
|
||||||
|
@ -41,7 +51,7 @@ def Route_save(entry):
|
||||||
from_stop_txt=str(entry[2]),
|
from_stop_txt=str(entry[2]),
|
||||||
to_stop_txt=str(entry[3]),
|
to_stop_txt=str(entry[3]),
|
||||||
to_stop=from_to[1],
|
to_stop=from_to[1],
|
||||||
distance=float(entry[4]),
|
distance=Decimal(entry[4]),
|
||||||
stages=int(entry[5]))
|
stages=int(entry[5]))
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
|
@ -98,7 +108,7 @@ def RouteDetail_save(entry):
|
||||||
serial=int(entry[1]),
|
serial=int(entry[1]),
|
||||||
stop= temp_stop,
|
stop= temp_stop,
|
||||||
stage=(lambda:entry[3].startswith('1'), lambda:None)[ entry[3] == '' ](),
|
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()
|
obj.save()
|
||||||
#print obj.__dict__
|
#print obj.__dict__
|
||||||
|
|
||||||
|
@ -109,7 +119,7 @@ def Road_save(entry):
|
||||||
|
|
||||||
def Fare_save(entry):
|
def Fare_save(entry):
|
||||||
obj = Fare(
|
obj = Fare(
|
||||||
slab=float(entry[0]),
|
slab=Decimal(entry[0]),
|
||||||
ordinary=int(entry[1]),
|
ordinary=int(entry[1]),
|
||||||
limited=int(entry[2]),
|
limited=int(entry[2]),
|
||||||
express=int(entry[3]),
|
express=int(entry[3]),
|
||||||
|
|
|
@ -4,8 +4,9 @@ from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
|
|
||||||
def route(request, slug):
|
def route(request, slug):
|
||||||
|
srid = int(request.GET.get("srid", 4326))
|
||||||
route = get_object_or_404_json(Route, slug=slug)
|
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({
|
return render_to_json_response({
|
||||||
'route': route.get_dict(),
|
'route': route.get_dict(),
|
||||||
'stops': {
|
'stops': {
|
||||||
|
@ -15,8 +16,9 @@ def route(request, slug):
|
||||||
})
|
})
|
||||||
|
|
||||||
def area(request, slug):
|
def area(request, slug):
|
||||||
|
srid = int(request.GET.get("srid", 4326))
|
||||||
area = get_object_or_404_json(Area, slug=slug)
|
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({
|
return render_to_json_response({
|
||||||
'area': area.get_dict(),
|
'area': area.get_dict(),
|
||||||
'stops': {
|
'stops': {
|
||||||
|
@ -44,12 +46,13 @@ def areas(request):
|
||||||
|
|
||||||
def stops(request):
|
def stops(request):
|
||||||
qset = Stop.objects.all()
|
qset = Stop.objects.all()
|
||||||
|
srid = int(request.GET.get("srid", 4326))
|
||||||
if request.GET.has_key('q'):
|
if request.GET.has_key('q'):
|
||||||
q = request.GET.get('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.
|
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({
|
return render_to_json_response({
|
||||||
'type': 'FeatureCollection',
|
'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))
|
return render_to_json_response(stop.from_geojson(request.POST))
|
||||||
else:
|
else:
|
||||||
stop = get_object_or_404_json(Stop, slug=slug)
|
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.
|
||||||
|
|
|
@ -122,6 +122,7 @@ class Stop(models.Model):
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_geojson(self, srid=4326):
|
def get_geojson(self, srid=4326):
|
||||||
|
print srid
|
||||||
if self.point is not None:
|
if self.point is not None:
|
||||||
geom = json.loads(self.point.transform(srid, True).geojson)
|
geom = json.loads(self.point.transform(srid, True).geojson)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -17,7 +17,7 @@ var API_BASE = "/1.0/",
|
||||||
var $list = $('#' + name + 'List');
|
var $list = $('#' + name + 'List');
|
||||||
var url = API_BASE + name + "/";
|
var url = API_BASE + name + "/";
|
||||||
var $loadingLi = $('<div />').text("Loading...").appendTo($list);
|
var $loadingLi = $('<div />').text("Loading...").appendTo($list);
|
||||||
$.getJSON(url, {}, function(items) {
|
$.getJSON(url, {'srid': 3857}, function(items) {
|
||||||
$loadingLi.remove();
|
$loadingLi.remove();
|
||||||
$.each(items, function(i,v) {
|
$.each(items, function(i,v) {
|
||||||
var $li = $('<div />')
|
var $li = $('<div />')
|
||||||
|
@ -52,7 +52,7 @@ var API_BASE = "/1.0/",
|
||||||
var url = API_BASE + name + "/" + $target.find(".listItemText").text();
|
var url = API_BASE + name + "/" + $target.find(".listItemText").text();
|
||||||
$target.data("loading", true);
|
$target.data("loading", true);
|
||||||
var $loading = $('<span />').addClass("loadingSpan").text("Loading...").appendTo($target);
|
var $loading = $('<span />').addClass("loadingSpan").text("Loading...").appendTo($target);
|
||||||
$.getJSON(url, {}, function(obj) {
|
$.getJSON(url, {'srid': 3857}, function(obj) {
|
||||||
$loading.remove();
|
$loading.remove();
|
||||||
var stopsGeojson = obj.stops;
|
var stopsGeojson = obj.stops;
|
||||||
var stops = stopsGeojson.features;
|
var stops = stopsGeojson.features;
|
||||||
|
@ -138,7 +138,7 @@ var API_BASE = "/1.0/",
|
||||||
}
|
}
|
||||||
|
|
||||||
function initMap() {
|
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", {
|
map = new OpenLayers.Map("mapCol", {
|
||||||
projection: new OpenLayers.Projection("EPSG:900913")
|
projection: new OpenLayers.Projection("EPSG:900913")
|
||||||
});
|
});
|
||||||
|
@ -148,8 +148,10 @@ var API_BASE = "/1.0/",
|
||||||
layers[0] = new OpenLayers.Layer.OSM();
|
layers[0] = new OpenLayers.Layer.OSM();
|
||||||
geojson_format = new OpenLayers.Format.GeoJSON();
|
geojson_format = new OpenLayers.Format.GeoJSON();
|
||||||
//yes, jsonLayer is global. Yes, I know it's wrong.
|
//yes, jsonLayer is global. Yes, I know it's wrong.
|
||||||
jsonLayer = layers[1] = new OpenLayers.Layer.Vector("Bus Stops", {
|
jsonLayer = layers[1] = new OpenLayers.Layer.Vector({
|
||||||
geometryType: 'Point', projection: new OpenLayers.Projection("EPSG:4326") });
|
geometryType: 'Point',
|
||||||
|
projection: new OpenLayers.Projection("EPSG:4326")
|
||||||
|
});
|
||||||
// map.addLayer(vector_layer);
|
// map.addLayer(vector_layer);
|
||||||
map.addLayers(layers);
|
map.addLayers(layers);
|
||||||
map.setCenter(center, 12);
|
map.setCenter(center, 12);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user