Commit bb35fe54 authored by Emmanuel René Huchim Puc's avatar Emmanuel René Huchim Puc

Merge branch 'dev' of gitlab.geoint.mx:mario.chirinos/GeoInt_SIDT into dev

parents e5be4d17 242d42f3
.cross-range {
-webkit-appearance: none;
width: 100%;
margin: 4.05px 0;
}
.cross-range:focus {
outline: none;
}
.cross-range::-webkit-slider-runnable-track {
width: 100%;
height: 7.9px;
cursor: pointer;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
background: #dc7828;
border-radius: 25px;
border: 1px solid #dc7828;
}
.cross-range::-webkit-slider-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 16px;
width: 16px;
border-radius: 50px;
background: #ffffff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -5.05px;
}
.cross-range:focus::-webkit-slider-runnable-track {
background: #e0863e;
}
.cross-range::-moz-range-track {
width: 100%;
height: 7.9px;
cursor: pointer;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
background: #dc7828;
border-radius: 25px;
border: 1px solid #dc7828;
}
.cross-range::-moz-range-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 16px;
width: 16px;
border-radius: 50px;
background: #ffffff;
cursor: pointer;
}
.cross-range::-ms-track {
width: 100%;
height: 7.9px;
cursor: pointer;
background: transparent;
border-color: transparent;
color: transparent;
}
.cross-range::-ms-fill-lower {
background: #ca6c21;
border: 1px solid #dc7828;
border-radius: 50px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}
.cross-range::-ms-fill-upper {
background: #dc7828;
border: 1px solid #dc7828;
border-radius: 50px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}
.cross-range::-ms-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 16px;
width: 16px;
border-radius: 50px;
background: #ffffff;
cursor: pointer;
height: 7.9px;
}
.cross-range:focus::-ms-fill-lower {
background: #dc7828;
}
.cross-range:focus::-ms-fill-upper {
background: #e0863e;
}
#opacitySlide {
background: transparent;
padding-left: 10px;
padding-right: 10px;
}
......@@ -237,11 +237,15 @@ function drawApiResponse(element) {
if (data.uuid === element.id.replace("-li", '')) {
console.log("footprint:\n", data.product.footprint);
if (!prevfeature.has(data.uuid)){
element.style.textDecoration = 'underline';
//element.style.textDecoration = 'underline';
let divh4 = element.children[0].children[1].children[0];
divh4.innerHTML = divh4.textContent + ' <i class="fa fa-eye" style="color:green"> </i>';
prevfeature.set(data.uuid, osmap.addfootprint(data.product.footprint, prevfeature));
}else{
if (prevfeature.length != 0){
element.style.textDecoration = 'none';
//element.style.textDecoration = 'none';
let divh4 = element.children[0].children[1].children[0]
divh4.innerHTML = divh4.textContent + ' <i class="fa fa-eye-slash" style="color: #dd4b39"> </i>';
osmap.deletefootprint(prevfeature.get(data.uuid));
prevfeature.delete(data.uuid);
}
......@@ -452,14 +456,13 @@ $(document).ready(function () {
success : function (res) {
data.img = res.img;
var temp = document.querySelector('#product_list_template');
// filling template
temp.content.querySelector('.single-product-input').id = data.uuid + "-div";
temp.content.querySelector('input').value = data.uuid;
temp.content.querySelector('li').id = data.uuid + "-li";
temp.content.querySelector('h4').id = data.uuid + "-h4";
temp.content.querySelector('h4').textContent = data.product.producttype + "_" + data.product.tileid;
temp.content.querySelector('p').textContent = data.product.beginposition;
temp.content.querySelector('p').textContent = data.product.producttype + "_" + data.product.tileid;
temp.content.querySelector('h4').innerHTML = parserDate(data.product.beginposition) + ' <i class="fa fa-eye-slash" style="color: #dd4b39"> </i>';
temp.content.querySelector('img').src = "data:image/jpeg;base64, " + data.img;
temp.content.querySelectorAll('span')[1].textContent = data.product.identifier;
temp.content.querySelectorAll('span')[2].textContent = data.product.size;
......@@ -496,6 +499,12 @@ $(document).ready(function () {
});
});
function parserDate(parsedate){
let fullDate = parsedate.split('T');
let date = fullDate[0].split('-');
date = date[1] + "/" + date[2] + "/" + date[0];
return date + " " + fullDate[1].split('.')[0];
}
// adds product to cart
$('#product-to-cart-form').submit(function (event) {
......
......@@ -5,6 +5,7 @@
<link rel="stylesheet" href="{% static 'catalog/css/map.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'catalog/css/body.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'catalog/css/modal1.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'catalog/css/crossrange.css' %}" type="text/css">
<!-- <link rel="stylesheet" href="https://openlayers.org/en/v4.6.4/css/ol.css" type="text/css">-->
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css">
<link rel="stylesheet" href="{% static 'catalog/css/waitingModal.css' %}" type="text/css">
......@@ -190,7 +191,8 @@
</a>
<ul class="treeview-menu sidebar-form">
<li>
<input class="form-control" type="number" value="100" name="cloudPercentage">
<input class="form-text" id="clouds" value="5" oninput="setCloudPercentageSlider(this.value)" name="cloudPercentage" disabled>
<input class="cross-range" type="range" min="0" max="100" step="1" value="5" oninput="setCloudPercentage(this.value)" id="cloudPercentageSelector" name=cloudPercentage>
</li>
</ul>
</li>
......@@ -322,6 +324,23 @@
</script>
<script>
function setCloudPercentage(clouds) {
//console.log(clouds)
document.getElementById("clouds").value=clouds;
}
function setCloudPercentageSlider(clouds) {
//console.log(clouds)
//TODO
document.getElementById("cloudPercentageSelector").value=clouds;
if(parseInt(clouds)>100){
document.getElementById("cloudPercentageSelector").value=100;
}
if(parseInt(clouds)<0){
document.getElementById("cloudPercentageSelector").value=0;
}
}
//var osmap = new OpenStreetMapsClass("map", -99.145556,19.419444, 10);
var osmap = new sidtMap("map", -89.63873079999999,21.0404457, 7);
osmap.geolocation();
......
<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="#">
......
......@@ -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 %}
......
......@@ -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,17 @@ 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 ################
......@@ -34,12 +46,11 @@ def report_L2ASCL(request, purchase_id):
template = "sclData.html"
reporteDir = 'mask'
folders = ""
purchase = Purchase.objects.values('user__email','is_public').filter(pk=purchase_id)
purchase = Purchase.objects.values('user__email', 'is_public').filter(pk=purchase_id)
email = purchase[0]['user__email']
path = USERS_PATH + email + '/' + purchase_id + '/'
scl_data_path = USERS_PATH + email + "/" + purchase_id + "/scl_data.json"
with open(USERS_PATH + email + "/" + purchase_id + "/findProducts.json") as p:
dataProduct = json.load(p)
startDate = str(dataProduct['startDate'])[:4] + '-' + str(dataProduct['startDate'])[4:6] + '-' + str(
......@@ -47,29 +58,31 @@ def report_L2ASCL(request, purchase_id):
endDate = str(dataProduct['endDate'])[:4] + '-' + str(dataProduct['endDate'])[4:6] + '-' + str(
dataProduct['endDate'])[6:8]
graphData, label, defaultLabel, defaultDataset,datasets = ProcessChartData(scl_data_path)
graphData, label, defaultLabel, defaultDataset, datasets = ProcessChartData(scl_data_path)
image_path = email + "/" + purchase_id + "/" + "out/" + reporteDir + "/TCI/thumbnails/"
SCL_path = email + "/" + purchase_id + "/" + "out/" + reporteDir + "/SCL/"
#PDFGenerator(request, path, reporteDir,)
if os.path.exists(path + reporteDir + ".pdf"):
print ("si existe")
else:
PDFGenerator(request, path, reporteDir, datasets)
return render(request, template, {"graphData": json.dumps(graphData),
"report_name": "SCL Image Classification Data(Km²)",
"startDate": startDate, "endDate": endDate,
"clouds": dataProduct['clouds'], "platform": dataProduct['platform'],
"productLevel": dataProduct['productLevel'], "IMAGE_PATH": image_path,
"SCL_PATH": SCL_path, 'dafaultLabel': defaultLabel,
'defaultDataSet': defaultDataset, "folders": folders,
"zone": reporteDir, "purchaseID": purchase_id,
"labels": graphData['data']['labels'],
"polygon": dataProduct['wkt'],"email": email})
"report_name": "SCL Image Classification Data(Km²)",
"startDate": startDate, "endDate": endDate,
"clouds": dataProduct['clouds'], "platform": dataProduct['platform'],
"productLevel": dataProduct['productLevel'], "IMAGE_PATH": image_path,
"SCL_PATH": SCL_path, 'dafaultLabel': defaultLabel,
'defaultDataSet': defaultDataset, "folders": folders,
"zone": reporteDir, "purchaseID": purchase_id,
"labels": graphData['data']['labels'],
"polygon": dataProduct['wkt'], "email": email})
# -------------------------------------------------------------------------------def Reports(request):
def Reports(request):
progress = 0
productList = []
......@@ -77,7 +90,8 @@ def Reports(request):
folders = []
zip = ""
product_list = Purchase.objects.values('id', 'productList', 'aggreg_date', 'search__clouds', 'search__startDate',
'search__endDate', 'search__process_id__name', 'search__search_name', 'is_public').filter(
'search__endDate', 'search__process_id__name', 'search__search_name',
'is_public').filter(
user_id=request.user.id, purchased=1)
for producto in product_list:
log_info = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/L2ASCL_AreaProcessing.log"
......@@ -120,22 +134,19 @@ def Reports(request):
print("folder out noes not exists")
else:
for files in os.listdir(absolute_path):
if files=='scl_data.json':
#print(files)
if files == 'scl_data.json':
# print(files)
initial_folder = files[:8]
break
elif files.endswith('_sclData.json'):
initial_folder = files[:14]
#if len(folders) == 0:
# initial_folder = "../#"
#else:
# initial_folder = folders.pop(0) + "_sclData"
# if len(folders) == 0:
# initial_folder = "../#"
# else:
# initial_folder = folders.pop(0) + "_sclData"
print(initial_folder)
zip_path = USERS_PATH + request.user.email + "/" + str(producto['id'])
# print(zip_path)
......@@ -180,7 +191,7 @@ def wsProcessProgress(request):
if request.is_ajax():
progress = 0
productList2 = []
product_list = Purchase.objects.values('id','user__email', 'productList', 'aggreg_date', 'search__clouds',
product_list = Purchase.objects.values('id', 'user__email', 'productList', 'aggreg_date', 'search__clouds',
'search__startDate', 'search__endDate',
'search__process_id__name', 'progress').filter(user_id=request.user.id,
purchased=1)
......@@ -227,6 +238,7 @@ def wsProcessProgress(request):
else:
raise Http404
# tiles
def tiles(request, purchase_id, report, layer_type, date, z, x, y):
purchase = Purchase.objects.values('user__email', 'is_public').filter(pk=purchase_id)
......@@ -258,8 +270,6 @@ def tileinfo(request):
purchase = Purchase.objects.values('user__email').filter(pk=int(req['purchase_id'][0]))
email = purchase[0]['user__email']
resource_path = "{}{}/{}/out/{}/TCI/tiles/{}_TCI_10m/tilemapresource.xml".format(
USERS_PATH, email, req['purchase_id'][0], req['report'][0],
req['date'][0]
......@@ -268,7 +278,6 @@ def tileinfo(request):
if not os.path.exists(resource_path):
raise Http404
tree = ET.parse(resource_path)
bounding_box = tree.find('BoundingBox')
sets = [int(set.get('order')) for set in tree.findall('TileSets/TileSet')]
......@@ -292,81 +301,202 @@ def tileinfo(request):
raise Http404
# ------------------------------------------------------------------------
def PDFGenerator(request, ruta, reporteDir, datasets):
thumbs = ruta + 'out/' + reporteDir + '/TCI/thumbnails/'
SCL = ruta + 'out/' + reporteDir + '/SCL/'
# 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
#################################################################################
# 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 #
#################################################################################
path, dirs, files = next(os.walk(thumbs))
w, h = letter
# 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
c = canvas.Canvas(ruta + reporteDir + ".pdf", pagesize=letter, )
# Header #
c.drawImage(USERS_PATH + 'header.png', 170, h - 90, width=300, height=70)
# 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:
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])
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
# 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)
data = [['TCI', 'SCL'], [image1, image2]]
# body #
for file in files:
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/split/'
story = []
# define the style for our paragraph text
styles = getSampleStyleSheet()
styleN = styles['Normal']
date = datetime.strptime(file[:8], '%Y%m%d').strftime('%d/%m/%Y')
# Header
im = Image(USERS_PATH + 'header.png', width=300, height=70)
im.hAlign = 'CENTER'
story.append(im)
c.drawString(280, h - 125, date)
story.append(PageBreak())
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)
path, dirs, files = next(os.walk(thumbs))
print (len(files))
for index, file in enumerate(files):
values = []
labels = []
maxi = 0
#for data in datasets:
for data in datasets[:len(datasets) - 1]:
if maxi > data['data'][index]:
maxi = maxi
else:
maxi = data['data'][index]
#print (maxi)
values.append([data['data'][index]])
labels.append(data['label'])
path1 = thumbs + file
# Header
im = Image(USERS_PATH + 'header.png', width=300, height=70)
im.hAlign = 'CENTER'
story.append(im)
story.append(Spacer(1, .5 * inch))
# add the title
# story.append(Paragraph("<strong>Results for Vizard Experiment</strong>", styleN))
# story.append(Spacer(1, .25 * inch))
# Thumb image #
# 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))
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"
# table with images
story.append(myTable(path1, SCL, file))
story.append(Spacer(1, .5 * inch))
c.drawImage(grafica, 140, h - 650, width=900, height=150)
c.drawImage(USERS_PATH + 'values.png', 70, h - 680, width=500, height=25)
# add barchart and legend
#drawing = myBarChart(values[:len(values) - 1], maxi, file)
drawing = myBarChart(values, maxi, file)
#drawing = myBarLegend(drawing, labels[:len(labels) - 1])
drawing = myBarLegend(drawing, labels)
drawing.hAlign = 'CENTER'
story.append(drawing)
c.showPage()
c.save()
story.append(PageBreak())
# build our document with the list of flowables we put together
doc = SimpleDocTemplate(ruta + reporteDir + ".pdf", pagesize=letter, topMargin=0)
doc.build(story)
pass
#-----------------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------
def ProcessChartData(path):
with open(path) as f:
json_data = OrderedDict(json.load(f))
......@@ -412,18 +542,19 @@ def ProcessChartData(path):
label = graphData['data']['labels'][0]
defaultLabel = graphData['data']['labels'][0]
defaultDataset = label[0:4] + "/" + label[4:6] + "/" + label[6:]
return graphData,label,defaultLabel,defaultDataset,data['datasets']
return graphData, label, defaultLabel, defaultDataset, data['datasets']
#---------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------
def wsIs_Public(request):
if request.is_ajax():
status = request.GET.get("status")
path = "/reports/"+request.GET.get("purchase_id")+"/scl_data"
path = "/reports/" + request.GET.get("purchase_id") + "/scl_data"
purchase = Purchase.objects.get(pk=request.GET.get("purchase_id"))
purchase.is_public = request.GET.get("status")
purchase.save()
#print (purchase.aggreg_date)
# print (purchase.aggreg_date)
return HttpResponse("hola")
......
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