switch de publico

parent 04502b9d
<div class="form-group"> <div class="form-group">
<br> <br>
<ul class="sidebar-menu" data-widget="tree"> <ul class="sidebar-menu" data-widget="tree">
{% if request.user.is_authenticated %}
<li>
<a class="treeview " href="{{ BASE_URL }}/reports">
<i class="fa fa-map"></i>
<span>Home</span>
<span class="pull-right-container">
<span class="label label-primary pull-right"></span>
</span>
</a>
</li>
{% endif %}
{% if folders %} {% if folders %}
<li class="treeview"> <li class="treeview">
<a href="#"> <a href="#">
......
...@@ -119,12 +119,11 @@ ...@@ -119,12 +119,11 @@
<!-- Main content --> <!-- Main content -->
<div class="container floating-panel" style="position:absolute; bottom: 40px; left: 12%; width: 500px; z-index: 1000"> <div class="container floating-panel" style="position:absolute; bottom: 40px; left: 12%; width: 500px; z-index: 1000">
<div class="range-control" id="rangecontrol"> <div class="range-control" id="rangecontrol">
<span id="tooltiptext">No Data</span> <span id="tooltiptext">{{ labels|first|slice:"6:8" }}/{{ labels|first|slice:"4:6" }}/{{ labels|first|slice:"0:4" }}</span>
<input class="cross-range" id="inputRange" type="range" min="0" max="{{ labels|length }}" step="1" value="0" data-thumbwidth="20" style="background: transparent;"> <input class="cross-range" id="inputRange" type="range" min="1" max="{{ labels|length }}" step="1" value="1" data-thumbwidth="20" style="background: transparent;">
<datalist class="range__list" id="number"> <datalist class="range__list" id="number">
<option>No Data</option>
{% for label in labels %} {% for label in labels %}
<option class="range__opt" value="{{ label }}">{{ label|slice:"6:8" }}/{{ label|slice:"4:6" }}/{{label|slice:"0:4" }}</option> <option class="range__opt" value="{{ label }}">{{ label|slice:"6:8" }}/{{ label|slice:"4:6" }}/{{label|slice:"0:4" }}</option>
{% endfor %} {% endfor %}
......
...@@ -3,6 +3,7 @@ from __future__ import unicode_literals ...@@ -3,6 +3,7 @@ from __future__ import unicode_literals
import json import json
import os import os
import string
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
# Create your views here. # Create your views here.
from collections import OrderedDict from collections import OrderedDict
...@@ -17,6 +18,18 @@ from django.views.decorators.csrf import csrf_exempt ...@@ -17,6 +18,18 @@ from django.views.decorators.csrf import csrf_exempt
from GeoInt_SIDT.settings import BASE_URL from GeoInt_SIDT.settings import BASE_URL
from catalog.models import Purchase from catalog.models import Purchase
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
from reportlab.lib import colors
from reportlab.platypus import Paragraph, Frame, Spacer, Image, Table, TableStyle, SimpleDocTemplate, PageBreak
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.graphics.shapes import Drawing, String
from reportlab.graphics.charts.textlabels import Label, LabelOffset
from reportlab.graphics.charts.legends import Legend
# ------------------------------------------------------------------------------- # -------------------------------------------------------------------------------
########### lee archivo de configuración ################ ########### lee archivo de configuración ################
...@@ -294,77 +307,205 @@ def tileinfo(request): ...@@ -294,77 +307,205 @@ def tileinfo(request):
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
# take the data and make ready for paragraph
def dataToParagraph(name, data):
p = '<strong>Subject name: </strong>' + name + '<br/>' + '<strong>Data: </strong> ('
for i in range(len(data)):
p += str(data[i])
if i != len(data) - 1:
p += ', '
else:
p += ')'
return p
# take the data and convert to list of strings ready for table
def dataToTable(name, data):
data = [str(x) for x in data]
data.insert(0, name)
return data
# create the table for our document
def myTable(path1,path2,basefile):
image1 = Image(path1, height=300, width=200, mask='auto')
path, dirs, files = next(os.walk(path2))
for file in files:
if file.startswith(basefile[:8]):
if file.endswith('.tif') and not file.endswith('0.tif'):
#image2 = Image(path2 + file, height=300, width=200, mask='auto')
image2 = image1
data = [['TCI', 'SCL'], [image1, image2]]
t = Table(data)
GRID_STYLE = TableStyle(
[
('ALIGN',(0,0),(-1,-1),'CENTER'),
('VALIGN',(0,0),(-1,-1),'TOP'),
],
)
t.setStyle(GRID_STYLE)
return t
# create a bar chart and specify positions, sizes, and colors
def myBarChart(data,maxi,fecha):
drawing = Drawing(600, 200)
bc = VerticalBarChart()
bc.x = 50
bc.y = 50
bc.height = 125
bc.width = 500
bc.data = data
bc.barWidth = .3 * inch
bc.groupSpacing = .2 * inch
bc.strokeColor = colors.black
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = maxi
bc.valueAxis.valueStep = 50
bc.categoryAxis.labels.boxAnchor = 'ne'
bc.categoryAxis.labels.dx = 8
bc.categoryAxis.labels.dy = -2
catNames = fecha[6:8]+"/"+fecha[4:6]+"/"+fecha[0:4]
catNames = catNames.split()
bc.categoryAxis.categoryNames = catNames
bc.bars[0].fillColor = colors.brown
bc.bars[1].fillColor = colors.lightgrey
bc.bars[2].fillColor = colors.gray
bc.bars[3].fillColor = colors.lightblue
bc.bars[4].fillColor = colors.darkgray
bc.bars[5].fillColor = colors.green
bc.bars[6].fillColor = colors.yellow
#bc.bars[7].fillColor = colors.black
bc.barSpacing = 1
bc.categoryAxis.labels.dx = 8
bc.categoryAxis.labels.dy = -2
bc.barLabelFormat = '%f km²'
bc.barLabels.nudge = 7
bc.valueAxis.labelTextFormat = '%d km²'
bc.valueAxis.valueMin = 0
drawing.add(bc)
return drawing
# add a legend for the bar chart
def myBarLegend(drawing, labels):
"Add sample swatches to a diagram."
d = drawing or Drawing(400, 200)
swatches = Legend()
swatches.alignment = 'right'
swatches.x = 80
swatches.y = 160
swatches.deltax = 60
swatches.dxTextSpace = 10
swatches.columnMaximum = 4
items = [
(colors.brown, labels[0]),
(colors.lightgrey, labels[1]),
(colors.gray, labels[2]),
(colors.lightblue, labels[3]),
(colors.darkgray, labels[4]),
(colors.green, labels[5]),
(colors.yellow, labels[6]+"km2"),
#(colors.black, labels[7]),
]
swatches.colorNamePairs = items
d.add(swatches, 'legend')
return d
def PDFGenerator(request, ruta, reporteDir, datasets): def PDFGenerator(request, ruta, reporteDir, datasets):
thumbs = ruta + 'out/' + reporteDir + '/TCI/thumbnails/' thumbs = ruta + 'out/' + reporteDir + '/TCI/thumbnails/'
SCL = ruta + 'out/' + reporteDir + '/SCL/' SCL = ruta + 'out/' + reporteDir + '/SCL/split/'
story = []
# define the style for our paragraph text
styles = getSampleStyleSheet()
styleN = styles['Normal']
################################################################################# # Header
# check https://developers.google.com/chart/image/docs/making_charts # im = Image(USERS_PATH + 'header.png',width=300, height=70)
# check https://developers.google.com/chart/image/docs/chart_params#gcharts_cht # im.hAlign = 'CENTER'
# cht = type # story.append(im)
# chd = data values #
# chl = labels # story.append(PageBreak())
#################################################################################
path, dirs, files = next(os.walk(thumbs)) path, dirs, files = next(os.walk(thumbs))
w, h = letter for index, file in enumerate(files):
values=[]
labels =[]
maxi = 0
for data in datasets:
if maxi > data['data'][index]:
maxi = maxi
else:
maxi = data['data'][index]
values.append([data['data'][index]])
labels.append(data['label'])
c = canvas.Canvas(ruta + reporteDir + ".pdf", pagesize=letter, ) path1 = thumbs+file
# Header
im = Image(USERS_PATH + 'header.png', width=300, height=70)
im.hAlign = 'CENTER'
story.append(im)
# Header # story.append(Spacer(1, .5 * inch))
c.drawImage(USERS_PATH + 'header.png', 170, h - 90, width=300, height=70)
c.showPage() # add the title
variable = "" #story.append(Paragraph("<strong>Results for Vizard Experiment</strong>", styleN))
# aqui estan los datos de todas las lineas # #story.append(Spacer(1, .25 * inch))
for data2 in datasets:
# solo de la linea verde #
print(data2['data'])
# print(data2['data'][1])
# variable = "0,0.0216,0,5.1408,29.8728,34.1892,57.0528,142.6788,506.6496,107.8344,0" # convert data to paragraph form and then add paragraphs
variable += str(data2['data'][0]) #story.append(Paragraph(dataToParagraph(subject1, results1), styleN))
variable += "," #story.append(Spacer(1, .25 * inch))
print(variable) #story.append(Paragraph(dataToParagraph(subject2, results2), styleN))
#story.append(Spacer(1, .5 * inch))
# body #
for file in files:
date = datetime.strptime(file[:8], '%Y%m%d').strftime('%d/%m/%Y')
c.drawString(280, h - 125, date) # table with images
story.append(myTable(path1,SCL,file))
story.append(Spacer(1, .5 * inch))
# add barchart and legend
drawing = myBarChart(values[:len(values)-1], maxi,file)
drawing = myBarLegend(drawing, labels[:len(labels)-1])
drawing.hAlign = 'CENTER'
story.append(drawing)
c.drawString(160, h - 165, 'TCI') story.append(PageBreak())
c.drawString(440, h - 165, 'SCL')
c.drawImage(USERS_PATH + 'header.png', 170, h - 90, width=300, height=70)
# Thumb image #
c.drawImage(thumbs + file, 70, h - 470, height=300, width=200, mask='auto')
# SCL image #
path2, dirs2, files2 = next(os.walk(SCL))
for file2 in files2:
if file2.startswith(file[:8]):
if not file2.endswith('.tif'):
c.drawImage(SCL + file2, 350, h - 470, height=300, width=200, mask='auto')
# Chart # # build our document with the list of flowables we put together
# los valores deben ir en chd para cada elemento # doc = SimpleDocTemplate(ruta + reporteDir + ".pdf", pagesize=letter, topMargin=0)
grafica = "https://chart.googleapis.com/chart?" \ doc.build(story)
"&chs=900x150" \
"&cht=bvs" \
"&chd=t:" + variable + "" \
"&chds=a" \
"&chco=ff8afa|659acc|99d4d9|696767|98775b|ababab|dddddd|d9f9ff|44ba5d|fff98b|383838" \
"&chxt=y" \
"&chm=N,000000,0,-1,11"
c.drawImage(grafica, 140, h - 650, width=900, height=150) print ("hecho")
c.drawImage(USERS_PATH + 'values.png', 70, h - 680, width=500, height=25)
c.showPage()
c.save()
pass pass
#----------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------
def ProcessChartData(path): def ProcessChartData(path):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment