users

parent 1632f2fa
......@@ -28,5 +28,14 @@
</span>
</a>
</li>
<li>
<a class="treeview " href="#" onclick="window.history.back();">
<i class="fa fa-backward"></i>
<span>Back</span>
<span class="pull-right-container">
<span class="label label-primary pull-right"></span>
</span>
</a>
</li>
</ul>
</div>
\ No newline at end of file
......@@ -194,7 +194,7 @@
<!-- /.info-box-content -->
</div>
<!-- /.info-box -->
</div>
</div>
<div class="col-md-2 col-sm-6 col-xs-12">
<div class="info-box">
......
......@@ -126,6 +126,15 @@
</span>
</a>
</li>
<li>
<a class="treeview " href="#" onclick="window.history.back();">
<i class="fa fa-backward"></i>
<span>Back</span>
<span class="pull-right-container">
<span class="label label-primary pull-right"></span>
</span>
</a>
</li>
</ul>
</div>
<!-- form-group-->
......
......@@ -10,6 +10,7 @@
</span>
</a>
</li>
<li class="treeview">
<a href="#">
<i class="fa fa-file-archive-o"></i>
......@@ -136,5 +137,14 @@
</li>
</ul>
</li>
<li>
<a class="treeview " href="#" onclick="window.history.back();">
<i class="fa fa-backward"></i>
<span>Back</span>
<span class="pull-right-container">
<span class="label label-primary pull-right"></span>
</span>
</a>
</li>
</ul>
</div>
\ No newline at end of file
This diff is collapsed.
......@@ -71,5 +71,7 @@
<!-- /.box-body -->
</div>
<!-- /.box -->
<div><br></div>
</div>
{% endfor %}
\ No newline at end of file
......@@ -28,5 +28,14 @@
</span>
</a>
</li-->
<li>
<a class="treeview " href="#" onclick="window.history.back();">
<i class="fa fa-backward"></i>
<span>Back</span>
<span class="pull-right-container">
<span class="label label-primary pull-right"></span>
</span>
</a>
</li>
</ul>
</div>
\ No newline at end of file
import os
from django.contrib.auth.models import User
from django.shortcuts import render
# Create your views here.
import json
from catalog.models import Search, Purchase
dirname = os.path.dirname(__file__)
configfile = os.path.join(dirname, '../config/config.json')
with open(configfile, 'r') as f:
config = json.load(f)
USERS_PATH = config['PATHS']['PATH_USERS']
#-------------------------------------------
def Users(request):
user_data = []
user_statics = []
......@@ -30,18 +39,110 @@ def Users(request):
"in_process": in_process.count(),
})
return render(request,'User_profile.html',{"user_data" : user_data} )
progress = 0
productList = []
size = 0
folders = []
zip = ""
product_list = Purchase.objects.values('id', 'productList', 'aggreg_date', 'search__clouds', 'search__startDate',
'search__endDate', 'search__process_id__name', 'search__search_name').filter(
user_id=request.user.id, purchased=1).order_by('-aggreg_date')
for producto in product_list:
log_info = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/L2ASCL_AreaProcessing.log"
#####################################################
# progress bar #
#####################################################
if os.stat(log_info).st_size == 0:
progress = 0
else:
if 'Linking Products...' in open(log_info).read():
progress = 20
if 'Merging Images...' in open(log_info).read():
progress = 40
if 'Deleting Images...' in open(log_info).read():
progress = 50
if 'Extracting SCL information...' in open(log_info).read():
progress = 60
if 'Finalizing...' in open(log_info).read():
progress = 100
# item = Purchase.objects.filter(pk=producto['id'])
# item = Purchase.objects.get(pk=producto['id'])
# item.progress = progress
# item.save()
with open(log_info, 'r') as myfile:
log = myfile.read().replace('\n', '')
for p in json.loads(producto['productList']):
size = size + float(p['info']['size'][:-3])
if size > 1000:
size2 = size / 1000
final_size = str(round(size2, 2)) + " GB"
else:
final_size = str(round(size, 2)) + " MB"
initial_folder = "."
absolute_path = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/out"
if not os.path.exists(absolute_path):
print("folder out noes not exists")
else:
folders = os.listdir(path=absolute_path)
print(folders)
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)
# "../ 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"
with open(wkt, 'r') as jsonfile:
polygon = json.load(jsonfile)
for file in os.listdir(path=zip_path):
if file.endswith(".zip"):
zip = zip_path + "/" + file
productList.append({
"search_name": producto['search__search_name'],
"process": producto['search__process_id__name'],
"purchase_date": producto['aggreg_date'],
"startDate": producto['search__startDate'],
"endDate": producto['search__endDate'],
"clouds": producto['search__clouds'],
"size": final_size,
"purchase_id": producto['id'],
"progress": progress,
"log_info": log,
"initial_folder": initial_folder,
"zip": zip,
"polygon": polygon['wkt'],
})
size = 0
final_size = 0
log_info = ""
progress = 0
initial_folder = ""
zip = ""
wkt = ""
return render(request,'User_profile.html',{"user_data" : user_data, "productList" : productList} )
#----------------------------------------------------------------------
def User_id(request,user_id):
user_data = []
user_statics = []
user = User.objects.get(pk=user_id)
searches = Search.objects.filter(user_id=user.id)
purchases = Purchase.objects.filter(user_id=user.id).order_by('aggreg_date')
purchases = Purchase.objects.filter(user_id=user.id)
in_process = Purchase.objects.filter(user_id=user.id).exclude(progress=100)
user_data.append({
"user_fullname": user.first_name+" "+user.last_name,
"searches": searches.count(),
......@@ -49,5 +150,101 @@ def User_id(request,user_id):
"in_process": in_process.count(),
})
user_statics.append({
"user_fullname": user.first_name + " " + user.last_name,
"searches": searches.count(),
"purchases": purchases.count(),
"in_process": in_process.count(),
})
progress = 0
productList = []
size = 0
folders = []
zip = ""
product_list = Purchase.objects.values('id', 'productList', 'aggreg_date', 'search__clouds', 'search__startDate',
'search__endDate', 'search__process_id__name', 'search__search_name').filter(
user_id=user.id, purchased=1).order_by('-aggreg_date')
for producto in product_list:
log_info = USERS_PATH + user.email + "/" + str(producto['id']) + "/L2ASCL_AreaProcessing.log"
#####################################################
# progress bar #
#####################################################
if os.stat(log_info).st_size == 0:
progress = 0
else:
if 'Linking Products...' in open(log_info).read():
progress = 20
if 'Merging Images...' in open(log_info).read():
progress = 40
if 'Deleting Images...' in open(log_info).read():
progress = 50
if 'Extracting SCL information...' in open(log_info).read():
progress = 60
if 'Finalizing...' in open(log_info).read():
progress = 100
# item = Purchase.objects.filter(pk=producto['id'])
# item = Purchase.objects.get(pk=producto['id'])
# item.progress = progress
# item.save()
with open(log_info, 'r') as myfile:
log = myfile.read().replace('\n', '')
for p in json.loads(producto['productList']):
size = size + float(p['info']['size'][:-3])
if size > 1000:
size2 = size / 1000
final_size = str(round(size2, 2)) + " GB"
else:
final_size = str(round(size, 2)) + " MB"
initial_folder = "."
absolute_path = USERS_PATH + user.email + "/" + str(producto['id']) + "/out"
if not os.path.exists(absolute_path):
print("folder out noes not exists")
else:
folders = os.listdir(path=absolute_path)
if len(folders) == 0:
initial_folder = "../#"
else:
initial_folder = folders.pop(0) + "_sclData"
zip_path = USERS_PATH + user.email + "/" + str(producto['id'])
# print(zip_path)
# "../ static / reports / tmpImages / repsat_test_dev / umorales @ centrogeo.edu.mx / "+str(producto['id']) / myzip.zip"
wkt = USERS_PATH + user.email + "/" + str(producto['id']) + "/findProducts.json"
with open(wkt, 'r') as jsonfile:
polygon = json.load(jsonfile)
for file in os.listdir(path=zip_path):
if file.endswith(".zip"):
zip = zip_path + "/" + file
productList.append({
"search_name": producto['search__search_name'],
"process": producto['search__process_id__name'],
"purchase_date": producto['aggreg_date'],
"startDate": producto['search__startDate'],
"endDate": producto['search__endDate'],
"clouds": producto['search__clouds'],
"size": final_size,
"purchase_id": producto['id'],
"progress": progress,
"log_info": log,
"initial_folder": initial_folder,
"zip": zip,
"polygon": polygon['wkt'],
})
size = 0
final_size = 0
log_info = ""
progress = 0
initial_folder = ""
zip = ""
wkt = ""
return render(request,'User_profile.html',{"user_data" : user_data} )
\ No newline at end of file
return render(request,'User_profile.html',{"user_data" : user_data, "productList" : productList} )
\ 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