user profile

parent d54b9530
...@@ -135,6 +135,15 @@ ...@@ -135,6 +135,15 @@
</span> </span>
</a> </a>
</li> </li>
<li>
<a class="treeview submenu" href="../../static/reports/tmpImages/repsat_test_dev/{{ request.user.email }}/{{ purchaseID }}/{{ zone }}.pdf" id="downloadPdf">
<i class="fa fa-file-pdf-o"></i>
<span>Export to PDF v2</span>
<span class="pull-right-container">
<span class="label label-primary pull-right"></span>
</span>
</a>
</li>
</ul> </ul>
</li> </li>
<li> <li>
......
...@@ -9,6 +9,7 @@ from collections import OrderedDict ...@@ -9,6 +9,7 @@ from collections import OrderedDict
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import render, render_to_response from django.shortcuts import render, render_to_response
from fpdf import FPDF
from GeoInt_SIDT.tasks import add from GeoInt_SIDT.tasks import add
from catalog.models import Purchase from catalog.models import Purchase
...@@ -30,35 +31,42 @@ USERS_PATH = config['PATHS']['PATH_USERS'] ...@@ -30,35 +31,42 @@ USERS_PATH = config['PATHS']['PATH_USERS']
def report_L2ASCL(request, report, purchase_id): def report_L2ASCL(request, report, purchase_id):
reporteDir = report.replace('_sclData', '')
reporteDir = report.replace('_sclData','') ##########################################
image_path = request.user.email + "/" + purchase_id + "/" + "out/"+reporteDir+"/TCI/thumbnails/" # Generador de pdfs #
SCL_path = request.user.email + "/" + purchase_id + "/" + "out/"+reporteDir+"/SCL/" ##########################################
PDFGenerator(request, reporteDir, purchase_id)
##########################################
# Generador de pdfs #
##########################################
image_path = request.user.email + "/" + purchase_id + "/" + "out/" + reporteDir + "/TCI/thumbnails/"
SCL_path = request.user.email + "/" + purchase_id + "/" + "out/" + reporteDir + "/SCL/"
print(image_path) print(image_path)
absolute_path = USERS_PATH + request.user.email + "/" + purchase_id + "/out" absolute_path = USERS_PATH + request.user.email + "/" + purchase_id + "/out"
folders = os.listdir(path=absolute_path) folders = os.listdir(path=absolute_path)
json_route= USERS_PATH + request.user.email + "/" + purchase_id + "/" json_route = USERS_PATH + request.user.email + "/" + purchase_id + "/"
for file in os.listdir(path=json_route): for file in os.listdir(path=json_route):
if file.endswith("_sclData.json") and not file.endswith("merge_out_sclData.json"): 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: with open(USERS_PATH + request.user.email + "/" + purchase_id + "/" + file) as f:
json_data = OrderedDict(json.load(f)) json_data = OrderedDict(json.load(f))
if len(json_data)==0: if len(json_data) == 0:
if file[:6] in folders: if file[:6] in folders:
folders.remove(file[:6]) folders.remove(file[:6])
with open(USERS_PATH + request.user.email + "/" + purchase_id + "/findProducts.json") as p: with open(USERS_PATH + request.user.email + "/" + purchase_id + "/findProducts.json") as p:
dataProduct = json.load(p) dataProduct = json.load(p)
startDate = str(dataProduct['startDate'])[:4] +'-'+ str(dataProduct['startDate'])[4:6]+'-'+ str(dataProduct['startDate'])[6:8] startDate = str(dataProduct['startDate'])[:4] + '-' + str(dataProduct['startDate'])[4:6] + '-' + str(
endDate = str(dataProduct['endDate'])[:4] +'-'+ str(dataProduct['endDate'])[4:6]+'-'+ str(dataProduct['endDate'])[6:8] dataProduct['startDate'])[6:8]
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: with open(USERS_PATH + request.user.email + "/" + purchase_id + "/" + report + ".json") as f:
json_data = OrderedDict(json.load(f)) json_data = OrderedDict(json.load(f))
if len(json_data)==0: if len(json_data) == 0:
graphData = "" graphData = ""
defaultLabel="" defaultLabel = ""
defaultDataset="" defaultDataset = ""
folders.remove(reporteDir) folders.remove(reporteDir)
else: else:
...@@ -99,26 +107,34 @@ def report_L2ASCL(request, report, purchase_id): ...@@ -99,26 +107,34 @@ def report_L2ASCL(request, report, purchase_id):
data['datasets'].sort(key=lambda k: max(k['data'])) data['datasets'].sort(key=lambda k: max(k['data']))
graphData['data'] = data graphData['data'] = data
label = graphData['data']['labels'][0] label = graphData['data']['labels'][0]
defaultLabel = graphData['data']['labels'][0] defaultLabel = graphData['data']['labels'][0]
defaultDataset = label[0:4]+"/"+label[4:6]+"/"+label[6:] defaultDataset = label[0:4] + "/" + label[4:6] + "/" + label[6:]
#defaultDataset = graphData['data']['datasets'][0]['label'] # defaultDataset = graphData['data']['datasets'][0]['label']
# print(settings.BASE_URL) # print(settings.BASE_URL)
# graphData['options']['responsive']=True # graphData['options']['responsive']=True
# graphData['options']['maintainAspectRatio']=False # graphData['options']['maintainAspectRatio']=False
# print(json.dumps(graphData).encode("utf-8")) # print(json.dumps(graphData).encode("utf-8"))
return render(request, 'L2ASCL_data.html', {"graphData": json.dumps(graphData),"name":"foo", "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 }) return render(request, 'L2ASCL_data.html', {"graphData": json.dumps(graphData), "name": "foo",
"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})
# -------------------------------------------------------------------------------def Reports(request): # -------------------------------------------------------------------------------def Reports(request):
def Reports(request): def Reports(request):
progress = 0 progress = 0
productList = [] productList = []
size = 0 size = 0
folders=[] folders = []
zip ="" zip = ""
product_list = Purchase.objects.values('id', 'productList', 'aggreg_date', 'search__clouds', 'search__startDate', product_list = Purchase.objects.values('id', 'productList', 'aggreg_date', 'search__clouds', 'search__startDate',
'search__endDate', 'search__process_id__name', 'search__search_name').filter( 'search__endDate', 'search__process_id__name', 'search__search_name').filter(
user_id=request.user.id, purchased=1) user_id=request.user.id, purchased=1)
...@@ -141,10 +157,10 @@ def Reports(request): ...@@ -141,10 +157,10 @@ def Reports(request):
progress = 60 progress = 60
if 'Finalizing...' in open(log_info).read(): if 'Finalizing...' in open(log_info).read():
progress = 100 progress = 100
# item = Purchase.objects.filter(pk=producto['id']) # item = Purchase.objects.filter(pk=producto['id'])
# item = Purchase.objects.get(pk=producto['id']) # item = Purchase.objects.get(pk=producto['id'])
# item.progress = progress # item.progress = progress
# item.save() # item.save()
with open(log_info, 'r') as myfile: with open(log_info, 'r') as myfile:
log = myfile.read().replace('\n', '') log = myfile.read().replace('\n', '')
...@@ -158,21 +174,21 @@ def Reports(request): ...@@ -158,21 +174,21 @@ def Reports(request):
final_size = str(round(size, 2)) + " MB" final_size = str(round(size, 2)) + " MB"
initial_folder = "." initial_folder = "."
absolute_path = USERS_PATH + request.user.email + "/" +str(producto['id'])+ "/out" absolute_path = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/out"
if not os.path.exists(absolute_path): if not os.path.exists(absolute_path):
print("folder out noes not exists") print("folder out noes not exists")
else: else:
folders = os.listdir(path=absolute_path) folders = os.listdir(path=absolute_path)
print(folders) print(folders)
if len(folders)==0: if len(folders) == 0:
initial_folder="../#" initial_folder = "../#"
else: else:
initial_folder = folders.pop(0)+"_sclData" initial_folder = folders.pop(0) + "_sclData"
zip_path = USERS_PATH + request.user.email + "/" +str(producto['id']) zip_path = USERS_PATH + request.user.email + "/" + str(producto['id'])
#print(zip_path) # print(zip_path)
#"../ static / reports / tmpImages / repsat_test_dev / umorales @ centrogeo.edu.mx / "+str(producto['id']) / myzip.zip" # "../ static / reports / tmpImages / repsat_test_dev / umorales @ centrogeo.edu.mx / "+str(producto['id']) / myzip.zip"
wkt = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/findProducts.json" wkt = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/findProducts.json"
with open(wkt, 'r') as jsonfile: with open(wkt, 'r') as jsonfile:
...@@ -180,7 +196,7 @@ def Reports(request): ...@@ -180,7 +196,7 @@ def Reports(request):
for file in os.listdir(path=zip_path): for file in os.listdir(path=zip_path):
if file.endswith(".zip"): if file.endswith(".zip"):
zip = zip_path+"/"+file zip = zip_path + "/" + file
productList.append({ productList.append({
"search_name": producto['search__search_name'], "search_name": producto['search__search_name'],
"process": producto['search__process_id__name'], "process": producto['search__process_id__name'],
...@@ -192,8 +208,8 @@ def Reports(request): ...@@ -192,8 +208,8 @@ def Reports(request):
"purchase_id": producto['id'], "purchase_id": producto['id'],
"progress": progress, "progress": progress,
"log_info": log, "log_info": log,
"initial_folder" :initial_folder, "initial_folder": initial_folder,
"zip" : zip, "zip": zip,
"polygon": polygon['wkt'], "polygon": polygon['wkt'],
}) })
size = 0 size = 0
...@@ -201,9 +217,8 @@ def Reports(request): ...@@ -201,9 +217,8 @@ def Reports(request):
log_info = "" log_info = ""
progress = 0 progress = 0
initial_folder = "" initial_folder = ""
zip ="" zip = ""
wkt ="" wkt = ""
return render(request, 'Reports.html', {"productList": productList}) return render(request, 'Reports.html', {"productList": productList})
...@@ -215,7 +230,8 @@ def wsProcessProgress(request): ...@@ -215,7 +230,8 @@ def wsProcessProgress(request):
productList2 = [] productList2 = []
product_list = Purchase.objects.values('id', 'productList', 'aggreg_date', 'search__clouds', product_list = Purchase.objects.values('id', 'productList', 'aggreg_date', 'search__clouds',
'search__startDate', 'search__endDate', 'search__startDate', 'search__endDate',
'search__process_id__name', 'progress').filter(user_id=request.user.id, purchased=1) 'search__process_id__name', 'progress').filter(user_id=request.user.id,
purchased=1)
for producto in product_list: for producto in product_list:
log_info = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/L2ASCL_AreaProcessing.log" log_info = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/L2ASCL_AreaProcessing.log"
...@@ -236,9 +252,9 @@ def wsProcessProgress(request): ...@@ -236,9 +252,9 @@ def wsProcessProgress(request):
if 'Finalizing...' in open(log_info).read(): if 'Finalizing...' in open(log_info).read():
progress = 100 progress = 100
#item = Purchase.objects.get(pk=producto['id']) # item = Purchase.objects.get(pk=producto['id'])
#item.progress = progress # item.progress = progress
#item.save() # item.save()
productList2.append({ productList2.append({
"purchase_id": producto['id'], "purchase_id": producto['id'],
...@@ -265,3 +281,64 @@ def wsProcessProgress(request): ...@@ -265,3 +281,64 @@ def wsProcessProgress(request):
# result = add.apply_async((2, 1), countdown=3) # result = add.apply_async((2, 1), countdown=3)
# result.get() # result.get()
# return render_to_response('reports_table.html', {"result": result.get()}) # return render_to_response('reports_table.html', {"result": result.get()})
def PDFGenerator(request, reporteDir, purchase_id):
class PDF(FPDF):
def header(self):
#self.image('logo.jpg')
# Arial bold 15
self.set_font('Arial', 'B', 15)
# Move to the right
self.cell(80)
# Title
self.cell(30, 10, 'Title', 1, 0, 'C')
# Line break
self.ln(20)
def imagenes(self):
#################################################################################
# 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 #
#################################################################################
url = "http://chart.apis.google.com/chart" \
"?cht=p3" \
"&chd=t:60,40" \
"&chs=500x200" \
"&chl=Hello|World" \
"&.png"
self.image(url)
# Arial bold 15
self.set_font('Arial', 'B', 15)
# Move to the right
self.cell(80)
# Title
self.cell(30, 10, 'Title', 1, 0, 'C')
# Line break
self.ln(20)
# Page footer
def footer(self):
# Position at 1.5 cm from bottom
self.set_y(-15)
# Arial italic 8
self.set_font('Arial', 'I', 8)
# Page number
self.cell(0, 10, 'Page ' + str(self.page_no()) + '/{nb}', 0, 0, 'C')
# Instantiation of inherited class
pdf = PDF()
pdf.alias_nb_pages()
pdf.add_page()
pdf.set_font('Times', '', 12)
for i in range(1, 41):
pdf.imagenes()
path = USERS_PATH + request.user.email + '/' + purchase_id + '/'
pdf.output(path + reporteDir + '.pdf', 'F')
\ No newline at end of file
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