Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
bfc1fe9b
Commit
bfc1fe9b
authored
Mar 27, 2019
by
Ulises Morales Ramírez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
switch de publico
parent
04502b9d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
195 additions
and
66 deletions
+195
-66
aside.html
reports/templates/aside.html
+0
-11
sclData.html
reports/templates/sclData.html
+2
-3
views.py
reports/views.py
+193
-52
No files found.
reports/templates/aside.html
View file @
bfc1fe9b
<div
class=
"form-group"
>
<br>
<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 %}
<li
class=
"treeview"
>
<a
href=
"#"
>
...
...
reports/templates/sclData.html
View file @
bfc1fe9b
...
...
@@ -119,12 +119,11 @@
<!-- Main content -->
<div
class=
"container floating-panel"
style=
"position:absolute; bottom: 40px; left: 12%; width: 500px; z-index: 1000"
>
<div
class=
"range-control"
id=
"rangecontrol"
>
<span
id=
"tooltiptext"
>
No Data
</span>
<input
class=
"cross-range"
id=
"inputRange"
type=
"range"
min=
"
0"
max=
"{{ labels|length }}"
step=
"1"
value=
"0
"
data-thumbwidth=
"20"
style=
"background: transparent;"
>
<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=
"
1"
max=
"{{ labels|length }}"
step=
"1"
value=
"1
"
data-thumbwidth=
"20"
style=
"background: transparent;"
>
<datalist
class=
"range__list"
id=
"number"
>
<option>
No Data
</option>
{% for label in labels %}
<option
class=
"range__opt"
value=
"{{ label }}"
>
{{ label|slice:"6:8" }}/{{ label|slice:"4:6" }}/{{label|slice:"0:4" }}
</option>
{% endfor %}
...
...
reports/views.py
View file @
bfc1fe9b
...
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
import
json
import
os
import
string
import
xml.etree.ElementTree
as
ET
# Create your views here.
from
collections
import
OrderedDict
...
...
@@ -17,6 +18,18 @@ from django.views.decorators.csrf import csrf_exempt
from
GeoInt_SIDT.settings
import
BASE_URL
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 ################
...
...
@@ -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
):
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'
]
#################################################################################
# check https://developers.google.com/chart/image/docs/making_charts #
# check https://developers.google.com/chart/image/docs/chart_params#gcharts_cht #
# cht = type #
# chd = data values #
# chl = labels #
#################################################################################
# Header
im
=
Image
(
USERS_PATH
+
'header.png'
,
width
=
300
,
height
=
70
)
im
.
hAlign
=
'CENTER'
story
.
append
(
im
)
story
.
append
(
PageBreak
())
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 #
c
.
drawImage
(
USERS_PATH
+
'header.png'
,
170
,
h
-
90
,
width
=
300
,
height
=
70
)
story
.
append
(
Spacer
(
1
,
.5
*
inch
))
c
.
showPage
()
variable
=
""
# aqui estan los datos de todas las lineas #
for
data2
in
datasets
:
# solo de la linea verde #
print
(
data2
[
'data'
])
# print(data2['data'][1])
# add the title
#story.append(Paragraph("<strong>Results for Vizard Experiment</strong>", styleN))
#story.append(Spacer(1, .25 * inch))
# variable = "0,0.0216,0,5.1408,29.8728,34.1892,57.0528,142.6788,506.6496,107.8344,0"
variable
+=
str
(
data2
[
'data'
][
0
])
variable
+=
","
print
(
variable
)
# convert data to paragraph form and then add paragraphs
#story.append(Paragraph(dataToParagraph(subject1, results1), styleN))
#story.append(Spacer(1, .25 * inch))
#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'
)
c
.
drawString
(
440
,
h
-
165
,
'SCL'
)
c
.
drawImage
(
USERS_PATH
+
'header.png'
,
170
,
h
-
90
,
width
=
300
,
height
=
70
)
story
.
append
(
PageBreak
())
# 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 #
# los valores deben ir en chd para cada elemento #
grafica
=
"https://chart.googleapis.com/chart?"
\
"&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"
# build our document with the list of flowables we put together
doc
=
SimpleDocTemplate
(
ruta
+
reporteDir
+
".pdf"
,
pagesize
=
letter
,
topMargin
=
0
)
doc
.
build
(
story
)
c
.
drawImage
(
grafica
,
140
,
h
-
650
,
width
=
900
,
height
=
150
)
c
.
drawImage
(
USERS_PATH
+
'values.png'
,
70
,
h
-
680
,
width
=
500
,
height
=
25
)
print
(
"hecho"
)
c
.
showPage
()
c
.
save
()
pass
#-----------------------------------------------------------------------------------------------------------------
def
ProcessChartData
(
path
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment