g214/graphics/views.py

107 lines
3.8 KiB
Python
Raw Normal View History

2018-08-20 08:21:25 +00:00
# coding=utf-8
from django.http import HttpResponse
from django.shortcuts import render, render_to_response
from django.core.serializers import serialize
from base.models import *
from graphics.models import FloorPlan, SectionalPlan
from django.db.models import Avg
from django.forms.models import model_to_dict
import json
def simple_chart(request):
f = FloorPlan(title=u"地热交换路基平面图")
f.link()
f.road_lines()
f.line_box()
f.drilling()
f_script, f_div = f.components()
s = SectionalPlan(title=u"地热交换路基剖面图")
s.road_lines()
s.drilling()
s.line_box()
s_script, s_div = s.components()
return render(request, 'graphics/simple_chart.html',
{"f_script": f_script, "f_div": f_div, "s_script": s_script, "s_div": s_div})
def map(request):
lands = Land.objects.filter(code__lte=14)
g214_lands = Land.objects.all().order_by('code').exclude(name='醉马滩').exclude(name='长石头')
g214_land = list()
for l in g214_lands:
if l.section_set.all():
if l.section_set.all()[0].owner == 'road':
g214_land.append(l)
return render(request, "graphics/map.html", {"lands": lands, "g214_land": g214_land})
def observation(request):
return render(request, "graphics/observation.html")
def drilling_geojson(request):
id = request.GET.get('id')
s = Section.objects.filter(land__id=id).exclude(the_geom=None)
j = serialize('custom_geojson', s,
geometry_field='the_geom',
fields=('id', 'code', 'name', 'type', 'owner'))
return HttpResponse(content=j, content_type='application/vnd.geo+json')
def road_geojson(request):
id = request.GET.get('id')
q = Section.objects.exclude(the_geom=None).filter(owner='road')
if id:
q = q.filter(land__id=id)
j = serialize('custom_geojson', q,
geometry_field='the_geom',
fields=('id','code', 'name', 'land', 'owner', 'type', 'thermometer', 'reinforcement',
'shift', 'strain', 'humidity', 'rtu', 'box'))
return HttpResponse(content=j, content_type='application/vnd.geo+json')
def land_detail_geojson(request):
id = request.GET.get('id')
l = Land.objects.filter(id=id).exclude(the_geom=None)
j = serialize('custom_geojson', l,
geometry_field='the_geom',
fields=('id', 'code', 'name', 'type', 'depth', 'section'))
return HttpResponse(content=j, content_type='application/vnd.geo+json')
def section_detail_geojson(request):
id = request.GET.get('id')
s = Section.objects.filter(id=id).exclude(the_geom=None)
j = serialize('custom_geojson', s,
geometry_field='the_geom',
fields=('id', 'code', 'name', 'land', 'owner', 'type', 'thermometer', 'reinforcement',
'shift', 'strain', 'humidity', 'rtu', 'box'))
return HttpResponse(content=j, content_type='application/vnd.geo+json')
def text(request):
return render(request, "graphics/text.html")
def text2(request):
section = Section.objects.all().exclude(the_geom=None)
section_dict = {}
i = 1
for s in section:
probe_data_avg = ProbeData.objects.filter(probe__drilling__section__id=s.id).aggregate(Avg('value'))
s_dict = model_to_dict(s)
dict = {i: [s_dict['name'], s_dict['the_geom'][:2], probe_data_avg['value__avg']]}
i += 1
section_dict.update(dict)
return HttpResponse(json.dumps(section_dict), content_type="application/json")
def linshi(request):
id = request.GET.get('id')
l = Land.objects.filter(id=id)
j = serialize('custom_geojson', l,
geometry_field='the_geom',
fields=('id','name'))
return HttpResponse(content=j, content_type='application/vnd.geo+json')