pdf reportes v2

parent aee3f694
{% extends "base_top.html" %}
{% load staticfiles %}
{% block headMedia %}
<link rel="stylesheet" href="{% static 'catalog/css/body.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'reports/css/scldata.css' %}" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
{% endblock %}
{% block messages %}
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-envelope-o"></i>
<span class="label label-success">4</span>
</a>
<ul class="dropdown-menu">
<li class="header">You have 4 messages</li>
<li>
<!-- inner menu: contains the actual data -->
<ul class="menu">
<li><!-- start message -->
<a href="#">
<div class="pull-left">
<img src="dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
</div>
<h4>
Support Team
<small><i class="fa fa-clock-o"></i> 5 mins</small>
</h4>
<p>Why not buy a new awesome theme?</p>
</a>
</li>
<!-- end message -->
<li>
<a href="#">
<div class="pull-left">
<img src="dist/img/user3-128x128.jpg" class="img-circle" alt="User Image">
</div>
<h4>
AdminLTE Design Team
<small><i class="fa fa-clock-o"></i> 2 hours</small>
</h4>
<p>Why not buy a new awesome theme?</p>
</a>
</li>
</ul>
</li>
<li class="footer"><a href="#">See All Messages</a></li>
</ul>
{% endblock %}
{% block notifications %}
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<span class="label label-warning">10</span>
</a>
<ul class="dropdown-menu">
<li class="header">You have 10 notifications</li>
<li>
<!-- inner menu: contains the actual data -->
<ul class="menu">
<li>
<a href="#">
<i class="fa fa-users text-aqua"></i> 5 new members joined today
</a>
</li>
</li>
</ul>
</li>
<li class="footer"><a href="#">View all</a></li>
</ul>
{% endblock %}
{% block tasks %}
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-flag-o"></i>
<span class="label label-danger">9</span>
</a>
<ul c{% load static %}lass="dropdown-menu">
<li class="header">You have 9 tasks</li>
<li>
<!-- inner menu: contains the actual data -->
<ul class="menu">
<li><!-- Task item -->
<a href="#">
<h3>
Design some buttons
<small class="pull-right">20%</small>
</h3>
<div class="progress xs">
<div class="progress-bar progress-bar-aqua" style="width: 20%" role="progressbar"
aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
<span class="sr-only">20% Complete</span>
</div>
</div>
</a>
</li>
<!-- end task item -->
</ul>
</li>
<li class="footer">
<a href="#">View all tasks</a>
</li>
</ul>
{% endblock %}
{% block sidebar %}
{% include 'aside.html' %}
<!-- form-group-->
{% endblock %}
{% block user %}
{% include "user_button.html" %}
{% endblock %}
{% block content %}
<!-- Content Wrapper. Contains page content -->
<!-- Main content -->
<div id="reportPage" class="wrapper" style="background-color: #ecf0f5">
<div class="text-center"><h1>{{ report_name }}</h1></div>
<section class="content">
<div class="row">
<div class="col-md-12" style="margin-bottom: 15px;">
<div class="box box-success">
<div class="box-body with-border">
<div class="row">
<div class="col-lg-2 text-center">
<h4>Zone: {{ zone }}</h4>
</div>
<div class="col-lg-2 text-center">
<h4>Platform: {{ platform }}</h4>
</div>
<div class="col-lg-2 text-center">
<h4>Product level: {{ productLevel }}</h4>
</div>
<div class="col-lg-2 text-center">
<h4>Start date: {{ startDate }}</h4>
</div>
<div class="col-lg-2 text-center">
<h4>End date: {{ endDate }}</h4>
</div>
<div class="col-lg-2 text-center">
<h4>Clouds: {{ clouds }} %</h4>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-8">
<!-- AREA CHART -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"> {{ title }} SCL Image Classification Data(Km²)</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i
class="fa fa-minus"></i>
</button>
<!-- <button type="button" class="btn btn-box-tool" data-widget="remove"><i
class="fa fa-times"></i></button> -->
</div>
</div>
<div class="box-body">
<div id="openchart" class="chart">
<canvas id="myChart" style="height: 594px"></canvas>
</div>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col (LEFT) -->
<div class="col-md-4">
<div class="nav-tabs-custom" id="tabs">
<ul class="nav nav-tabs">
<li ><a href="#images" data-toggle="tab">Images</a></li>
<li><a href="#compared" data-toggle="tab">Comparison</a></li>
<li><a href="#classification" data-toggle="tab">SCL</a></li>
<li class="active"><a href="#map" data-toggle="tab">Map</a></li>
</ul>
<div class="tab-content" style="padding: 0px">
<div class="tab-pane" id="images">
<div class="box box-danger">
<div class="box-header with-border">
<div class="pull-left">
<button type="button" id="play" class="btn btn-block btn-primary btn-xs" style="" onclick="play()">
<i class="fa fa-play"></i> Play
</button>
<button type="button" id="stop" class="btn btn-block btn-primary btn-xs" style="display: none; margin: 0px;"
onclick="stop()">
<i class="fa fa-stop"></i> Stop
</button>
</div>
<h3 class="box-title" id="titleMap" style="margin-left: -40px;">{{ defaultDataSet }}</h3>
</div>
<div class="box-body">
<div class="row img-comp-container">
<div class="col-lg-10 col-md-9 col-xs-10 col-lg-offset-1 col-md-offset-1 col-xs-offset-2"
style="padding: 0px 0px 0px 42px;">
<img onclick="open_big_image(this.src)" width="375" id="satImage" src="../../static/reports/tmpImages/repsat_test_dev/{{ IMAGE_PATH }}{{ dafaultLabel }}_TCI_60m.jpg"
style="margin-left: auto; margin-right: auto; display: block;">
</div>
</div>
</div>
<!-- /.box-body -->
</div>
</div>
<!-- /.tab-pane -->
<div class="tab-pane" id="compared">
<div class="box box-danger">
<div class="box-header with-border">
<h3 class="box-title" id="titleImageFirst">{{ defaultDataSet }}</h3>
<h3 class="box-title"> vs </h3>
<h3 class="box-title" id="titleImageSecond">{{ defaultDataSet }}</h3>
</div>
<div class="box-body">
<div class="row img-comp-container">
<div class="col-lg-3 col-md-2 col-xs-2 listImg">
<label>Image 1</label>
<div class ="list" style="margin-bottom: 20px">
<ul id="imageListFirst">
{% for label in labels %}
{% if label == labels.0 %}
<li class="active" onclick="selectImage1({{label}}, this)">{{ label }}</li>
{% else %}
<li onclick="selectImage1({{label}}, this)">{{ label }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
<label>Image 2</label>
<div class="list">
<ul id="imageListSecond">
{% for label in labels %}
{% if label == labels.1 %}
<li class="active" onclick="selectImage2({{label}}, this)">{{ label }}</li>
{% else %}
<li onclick="selectImage2({{label}}, this)">{{ label }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
<div class="col-lg-10 col-md-9 col-xs-10 col-lg-offset-2 col-md-offset-1 col-xs-offset-2 img-comp-img" id="showImage"
style="padding: 0px 0px 0px 42px;">
<img onclick="open_big_image(this.src)" width="375" id="satImageSecond" src="../../static/reports/tmpImages/repsat_test_dev/{{ IMAGE_PATH }}{{labels.1}}_TCI_60m.jpg"
style="margin-left: auto; margin-right: auto; display: block;">
</div>
<div class="col-lg-10 col-md-9 col-xs-10 col-lg-offset-2 col-md-offset-1 col-xs-offset-2 img-comp-img img-comp-overlay"
id="showSecondImage" style="padding: 0px 0px 0px 42px;">
<img onclick="open_big_image(this.src)" width="375" id="satImageFirst" src="../../static/reports/tmpImages/repsat_test_dev/{{ IMAGE_PATH }}{{labels.0}}_TCI_60m.jpg"
style="margin-left: auto; margin-right: auto; display: block;">
</div>
</div>
</div>
<!-- /.box-body -->
</div>
</div>
<!-- /.tab-pane -->
<div class="tab-pane" id="classification">
<div class="box box-danger">
<div class="box-header with-border">
<h3 class="box-title" >Scene Classification Map - </h3>
<h3 class="box-title" id="titleSCL">{{ defaultDataSet }}</h3>
<!-- <div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i
class="fa fa-minus"></i>
</button>
</div> -->
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-10 col-md-9 col-xs-10 col-lg-offset-1" id="showImageSCL" style="position: relative; height: 550px; padding: 0px 0px 0px 42px;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_saturated"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_saturated.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_shadows"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_shadows.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_cloud_shadows"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_cloud_shadows.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_vegetation"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_vegetation.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_not-vegetated"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_not-vegetated.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_water"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_water.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_unclassified"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_unclassified.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_cloud_medium_probability"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_cloud_medium_probability.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_cloud_high_probability"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_cloud_high_probability.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_thin_cirrus"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_thin_cirrus.png"
style="position: absolute; top: 0; z-index:1;">
<img onclick="window.open(this.src)" class="img-responsive" id="scl_snow"
width="375"
height="400px" src="../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}{{ dafaultLabel }}_SCL_60m_snow.png"
style="position: absolute; top: 0; z-index:1;">
</div>
</div>
</div>
<!-- /.box-body -->
</div>
</div>
<!-- /.tab-pane -->
<div class="tab-pane active" id="map">
<div class="box box-danger">
<div class="box-header with-border">
<h3 class="box-title">Map</h3>
</div>
<div class="box-body" style="max-height: 550px;">
<div id="minimap" style="height: 550px"></div>
</div>
<!-- /.box-body -->
</div>
</div>
<!-- /.tab-pane -->
</div>
<!-- /.tab-content -->
</div>
</div>
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- Footer -->
<footer class=" page-footer font-small special-color-dark pt-5" style="bottom: 0; position: absolute">
<!-- Footer Elements -->
<div class="container">
<!-- Social buttons
<ul class="list-unstyled list-inline text-center">
<li class="list-inline-item">
<a class="btn-floating btn-fb mx-1">
<i class="fa fa-faceboo"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-tw mx-1">
<i class="fa fa-twitter"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-gplus mx-1">
<i class="fa fa-google-plus"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-li mx-1">
<i class="fa fa-linkedin"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-dribbble mx-1">
<i class="fa fa-dribbble"> </i>
</a>
</li>
</ul>-->
<!-- Social buttons -->
</div>
<!-- Footer Elements -->
<!-- Copyright -->
<div class="footer-copyright text-center py-3">© 2019 Copyright:
<a href="http://geoint.mx/"> Centro de Investigación en Ciencias de Información Geoespacial.</a>
</div>
<!-- Copyright -->
</footer>
<!-- Footer -->
<!-- /.content -->
{% endblock %}
{% block scripts %}
<!-- page script -->
<script>
var defaultLegendClickHandler = Chart.defaults.global.legend.onClick;
var newLegendClickHandler = function (e, legendItem) {
var index = legendItem.datasetIndex;
//console.log(e)
console.log(legendItem.datasetIndex)
console.log(legendItem.text)
var ch = this.chart;
var meta = ch.getDatasetMeta(index);
console.log(meta.hidden)
var layer = legendItem.text.toLowerCase();
//layer = layer.replace(" ", "_");
layer = layer.replace(/\s/g,'_'); //reeemplaza los espacios con guion bajo
console.log(layer)
var activePoint = ch.getElementAtEvent(e);
console.log(document.getElementById("titleMap").textContent)
var label = document.getElementById("titleMap").textContent; //obtiene la fecha que se está viendo
label = label.replace(/\//g,''); // reemplaza los diagonales por nada
console.log(label)
if(meta.hidden){
console.log("Mostrar!!!")
SCLlayers.push(layer)
document.getElementById("scl_"+layer).src = "../../static/reports/tmpImages/repsat_test_dev/{{ SCL_PATH }}"+label+"_SCL_60m_"+layer+".png"
}
else{
console.log("Ocultar!!")
SCLlayers.splice(SCLlayers.indexOf(layer), 1);
document.getElementById("scl_"+layer).src = ""
}
//if (index > 1) {
// Do the original logic
//console.log("wooooo")
//defaultLegendClickHandler(e, legendItem);
defaultLegendClickHandler.call(this, e, legendItem);
//} else {
// console.log("holaaaa")
//}
};
var label;
// Recibimos el JSON con los datos desde el View
{% autoescape off %}
let image_path = "{{IMAGE_PATH}}";
let scl_path = "{{SCL_PATH}}";
let zone = "{{ zone }}"
let purchase_id = "{{ purchaseID }}"
let platform = "{{ platform }}";
let productLevel = "{{ productLevel }}";
let startDate = "{{ startDate }}";
let endDate = "{{ endDate }}";
let clouds= "{{ clouds }}";
let oldLabel = "{{defaultDataSet}}";
var config = {{graphData}}
config.options = {
responsive: true,
maintainAspectRatio: false,
// scales: { xAxes: [{ stacked: true }], yAxes: [{ stacked: true }] },
legend: {
display:true,
onClick: newLegendClickHandler,
}
};
console.log(config);
{% endautoescape %}
</script>
<script type="text/javascript" src="{% static 'reports/js/reportImg.js' %}"></script>
<script type="text/javascript" src="{% static 'reports/js/reportPdf.js' %}"></script>
<script type="text/javascript" src="{% static 'reports/js/minimap.js' %}"></script>
{% endblock %}
......@@ -31,35 +31,8 @@ USERS_PATH = config['PATHS']['PATH_USERS']
def report_L2ASCL(request, report, purchase_id):
reporteDir = report.replace('_sclData', '')
path = USERS_PATH + request.user.email + '/' + purchase_id + '/'
#PDFGenerator(request, path, reporteDir)
#if os.path.isfile(path + reporteDir + '.pdf'):
# pass
#else:
##########################################
# Generador de pdfs #
##########################################
# PDFGenerator(request, path, reporteDir)
##########################################
# Generador de pdfs #
##########################################
image_path = request.user.email + "/" + purchase_id + "/" + "out/" + reporteDir + "/TCI/thumbnails/"
SCL_path = request.user.email + "/" + purchase_id + "/" + "out/" + reporteDir + "/SCL/"
absolute_path = USERS_PATH + request.user.email + "/" + purchase_id + "/out"
folders = os.listdir(absolute_path)
json_route = USERS_PATH + request.user.email + "/" + purchase_id + "/"
for file in os.listdir(json_route):
if file.endswith("_sclData.json") and not file.endswith("merge_out_sclData.json"):
with open(USERS_PATH + request.user.email + "/" + purchase_id + "/" + file) as f:
json_data = OrderedDict(json.load(f))
if len(json_data) == 0:
if file[:6] in folders:
folders.remove(file[:6])
scl_data_path = USERS_PATH + request.user.email + "/" + purchase_id + "/" + report + ".json"
with open(USERS_PATH + request.user.email + "/" + purchase_id + "/findProducts.json") as p:
dataProduct = json.load(p)
......@@ -68,78 +41,65 @@ def report_L2ASCL(request, report, purchase_id):
endDate = str(dataProduct['endDate'])[:4] + '-' + str(dataProduct['endDate'])[4:6] + '-' + str(
dataProduct['endDate'])[6:8]
with open(USERS_PATH + request.user.email + "/" + purchase_id + "/" + report + ".json") as f:
json_data = OrderedDict(json.load(f))
if len(json_data) == 0:
graphData = ""
defaultLabel = ""
defaultDataset = ""
folders.remove(reporteDir)
graphData, label, defaultLabel, defaultDataset = ProcessChartData(scl_data_path)
else:
graphData = dict()
graphData['type'] = "line"
if report == 'scl_data':
return render(request,"sclData.html",{"graphData": json.dumps(graphData),
"report_name": "Aqui va el mapa",
"startDate": startDate, "endDate": endDate,
"clouds": dataProduct['clouds'], "platform": dataProduct['platform'],
"productLevel": dataProduct['productLevel'],'dafaultLabel': defaultLabel,
'defaultDataSet': defaultDataset,"purchaseID": purchase_id,
"labels": graphData['data']['labels']})
else:
reporteDir = report.replace('_sclData', '')
data = dict()
data['labels'] = [k for k, v in sorted(json_data.items())]
# data['click']="chartOnClick"
data['datasets'] = list()
labels = set()
for d in json_data:
labels |= set(json_data[d].keys())
labels.remove('date')
# PDFGenerator(request, path, reporteDir)
labelNames = [
"No Data", "Saturated", "Shadows", "Cloud Shadows", "Vegetation",
"Not-Vegetated", "Water", "Unclassified", "Cloud Medium Probability",
"Cloud High Probability", "Thin Cirrus", "Snow"
]
image_path = request.user.email + "/" + purchase_id + "/" + "out/" + reporteDir + "/TCI/thumbnails/"
SCL_path = request.user.email + "/" + purchase_id + "/" + "out/" + reporteDir + "/SCL/"
colors = [
"#383838", "#de3d3d", "#696767", "#98775b", "#44ba5d", "#fff98b",
"#659acc", "#ababab", "#dddddd", "#d9f9ff", "#99d4d9", "#ff8afa"
]
absolute_path = USERS_PATH + request.user.email + "/" + purchase_id + "/out"
for l in labels:
item = dict()
item['label'] = labelNames[int(l)]
folders = os.listdir(absolute_path)
json_route = USERS_PATH + request.user.email + "/" + purchase_id + "/"
# item['fill'] = "false"
if l == "0":
item['hidden'] = "true"
item['data'] = [v[l] * 60 * 60 / 1000000. if (l in v) else 0 for k, v in sorted(json_data.items())]
item['backgroundColor'] = colors[int(l)]
data['datasets'].append(item)
for file in os.listdir(json_route):
if file.endswith("_sclData.json") and not file.endswith("merge_out_sclData.json"):
with open(USERS_PATH + request.user.email + "/" + purchase_id + "/" + file) as f:
json_data = OrderedDict(json.load(f))
if len(json_data) == 0:
if file[:6] in folders:
folders.remove(file[:6])
data['datasets'].sort(key=lambda k: max(k['data']))
PDFGenerator(request, path, reporteDir,data['datasets'])
with open(USERS_PATH + request.user.email + "/" + purchase_id + "/" + report + ".json") as f:
json_data = OrderedDict(json.load(f))
if len(json_data) == 0:
graphData = ""
defaultLabel = ""
defaultDataset = ""
folders.remove(reporteDir)
graphData['data'] = data
label = graphData['data']['labels'][0]
defaultLabel = graphData['data']['labels'][0]
defaultDataset = label[0:4] + "/" + label[4:6] + "/" + label[6:]
# defaultDataset = graphData['data']['datasets'][0]['label']
# print(settings.BASE_URL)
# graphData['options']['responsive']=True
# graphData['options']['maintainAspectRatio']=False
# print(json.dumps(graphData).encode("utf-8"))
return render(request, 'L2ASCL_data.html', {"graphData": json.dumps(graphData), "name": "foo",
return render(request, 'L2ASCL_data.html', {"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']})
"zone": reporteDir, "purchaseID": purchase_id,
"labels": graphData['data']['labels']})
# -------------------------------------------------------------------------------def Reports(request):
# -------------------------------------------------------------------------------
def Reports(request):
......@@ -187,16 +147,26 @@ def Reports(request):
final_size = str(round(size, 2)) + " MB"
initial_folder = "."
absolute_path = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/out"
absolute_path = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/"
if not os.path.exists(absolute_path):
print("folder out noes not exists")
else:
folders = os.listdir(absolute_path)
for files in os.listdir(absolute_path):
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"
print(initial_folder)
if len(folders) == 0:
initial_folder = "../#"
else:
initial_folder = folders.pop(0) + "_sclData"
zip_path = USERS_PATH + request.user.email + "/" + str(producto['id'])
# print(zip_path)
......@@ -354,9 +324,9 @@ def tileinfo(request):
# ------------------------------------------------------------------------
def PDFGenerator(request,ruta, reporteDir, datasets):
thumbs = ruta+'out/'+reporteDir+'/TCI/thumbnails/'
SCL = ruta+'out/'+reporteDir+'/SCL/'
def PDFGenerator(request, ruta, reporteDir, datasets):
thumbs = ruta + 'out/' + reporteDir + '/TCI/thumbnails/'
SCL = ruta + 'out/' + reporteDir + '/SCL/'
#################################################################################
# check https://developers.google.com/chart/image/docs/making_charts #
......@@ -369,27 +339,27 @@ def PDFGenerator(request,ruta, reporteDir, datasets):
path, dirs, files = next(os.walk(thumbs))
w, h = letter
c = canvas.Canvas(ruta+reporteDir + ".pdf", pagesize=letter,)
c = canvas.Canvas(ruta + reporteDir + ".pdf", pagesize=letter, )
# Header #
c.drawImage(USERS_PATH + 'header.png', 170, h - 90, width=300, height=70)
c.showPage()
variable = ""
# aqui estan los datos de todas las lineas #
#for data2 in datasets:
for data2 in datasets:
# solo de la linea verde #
#print(data2['data'][0])
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"
variable += str(data2['data'][0])
variable += ","
print(variable)
# body #
for file in files:
date = datetime.strptime(file[:8], '%Y%m%d').strftime('%d/%m/%Y')
c.drawString(280, h - 125, date)
......@@ -400,29 +370,25 @@ def PDFGenerator(request,ruta, reporteDir, datasets):
# Thumb image #
c.drawImage(thumbs + file, 70, h - 470, height=300, width=200,mask='auto')
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')
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:0,0.0216,0,5.1408,29.8728,34.1892,57.0528,142.6788,506.6496,107.8344,0" \
"&chds=a" \
"&chco=ff8afa|659acc|99d4d9|696767|98775b|ababab|dddddd|d9f9ff|44ba5d|fff98b|383838" \
"&chxt=y" \
"&chm=N,000000,0,-1,11"
"&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)
c.drawImage(USERS_PATH + 'values.png', 70, h - 680, width=500, height=25)
......@@ -430,3 +396,52 @@ def PDFGenerator(request,ruta, reporteDir, datasets):
c.showPage()
c.save()
pass
#---------------------------------------------------------------------------
def ProcessChartData(path):
with open(path) as f:
json_data = OrderedDict(json.load(f))
graphData = dict()
graphData['type'] = "line"
data = dict()
data['labels'] = [k for k, v in sorted(json_data.items())]
# data['click']="chartOnClick"
data['datasets'] = list()
labels = set()
for d in json_data:
labels |= set(json_data[d].keys())
labels.remove('date')
labelNames = [
"No Data", "Saturated", "Shadows", "Cloud Shadows", "Vegetation",
"Not-Vegetated", "Water", "Unclassified", "Cloud Medium Probability",
"Cloud High Probability", "Thin Cirrus", "Snow"
]
colors = [
"#383838", "#de3d3d", "#696767", "#98775b", "#44ba5d", "#fff98b",
"#659acc", "#ababab", "#dddddd", "#d9f9ff", "#99d4d9", "#ff8afa"
]
for l in labels:
item = dict()
item['label'] = labelNames[int(l)]
# item['fill'] = "false"
if l == "0":
item['hidden'] = "true"
item['data'] = [v[l] * 60 * 60 / 1000000. if (l in v) else 0 for k, v in sorted(json_data.items())]
item['backgroundColor'] = colors[int(l)]
data['datasets'].append(item)
data['datasets'].sort(key=lambda k: max(k['data']))
# PDFGenerator(request, path, reporteDir,data['datasets'])
graphData['data'] = data
label = graphData['data']['labels'][0]
defaultLabel = graphData['data']['labels'][0]
defaultDataset = label[0:4] + "/" + label[4:6] + "/" + label[6:]
return graphData,label,defaultLabel,defaultDataset
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