dashboard

parent 09a55449
...@@ -334,7 +334,7 @@ ...@@ -334,7 +334,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="box box-success"> <div class="box box-success">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">Purchases Per Month</h3> <h3 class="box-title" id="purchases_in">Purchases Per Month</h3>
<div class="box-tools pull-right"> <div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i <button type="button" class="btn btn-box-tool" data-widget="collapse"><i
...@@ -346,29 +346,9 @@ ...@@ -346,29 +346,9 @@
<div class="box-body"> <div class="box-body">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<p class="text-center">
<strong>February</strong>
</p>
<div> <div id="mostrar">
<table class="table table-hover">
<thead>
<tr>
<th>User</th>
<th>Purchases</th>
<th>Storage %</th>
<th>Downloads in process</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>12</td>
<td>200 MB</td>
<td>0</td>
</tr>
</tbody>
</table>
</div> </div>
<!-- /.chart-responsive --> <!-- /.chart-responsive -->
</div> </div>
...@@ -456,7 +436,6 @@ ...@@ -456,7 +436,6 @@
</li> </li>
</ul> </ul>
<!-- Social buttons --> <!-- Social buttons -->
</div> </div>
<!-- Footer Elements --> <!-- Footer Elements -->
...@@ -466,6 +445,9 @@ ...@@ -466,6 +445,9 @@
</div> </div>
<!-- Copyright --> <!-- Copyright -->
</footer> </footer>
{% if messages %} {% if messages %}
<div class="container col-md-2 col-lg-2 col-xs-2 col-sm-2" style="bottom: 0; right: 0;position: absolute"> <div class="container col-md-2 col-lg-2 col-xs-2 col-sm-2" style="bottom: 0; right: 0;position: absolute">
...@@ -535,9 +517,10 @@ ...@@ -535,9 +517,10 @@
}); });
$(document).ready(function () { /*$(document).ready(function () {
$('#example').DataTable var table = $('#example').DataTable
({ ({
"ajax": data,
language: language:
{ {
"sProcessing": "Procesando...", "sProcessing": "Procesando...",
...@@ -581,7 +564,7 @@ ...@@ -581,7 +564,7 @@
}], }],
order: [1, 'asc'] order: [1, 'asc']
}); });
}); });*/
// mostrar imagen al dar click en los puntos // mostrar imagen al dar click en los puntos
...@@ -591,32 +574,52 @@ ...@@ -591,32 +574,52 @@
var firstPoint = activePoint[0]; var firstPoint = activePoint[0];
var label = myChart.data.labels[firstPoint._index]; var label = myChart.data.labels[firstPoint._index];
//if (!firstPoint) return; //if (!firstPoint) return;
$('#purchases_in').empty();
$('#purchases_in').append("Purchases in " + label);
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
dataType: "json", dataType: "json",
data: {'title':label}, data: {'title': label},
url: '../administration/ws/report_table', url: '../administration/ws/report_table',
success: function (data) { success: function (data) {
alert(data); $('#mostrar').empty();
$('#mostrar').append("<table class=\"table table-hover\" id=\"example\">"+
"<thead>" +
"<tr>" +
"<th class=\"text-center\">User ID</th>" +
"<th class=\"text-center\">User</th>" +
"<th class=\"text-center\">E-Mail</th>" +
"<th class=\"text-center\">Purchases</th>" +
"<th class=\"text-center\">Storage</th>" +
"<th class=\"text-center\">Downloads in process</th>" +
"</tr>" +
"</thead>" +
"<tbody id=\"tbody\" class=\"text-center\">");
$.each(data, function (key, val) {
$("#tbody").append("<tr>"+
"<td>"+val['user_id']+"</td>"+
"<td>"+val['username']+"</td>"+
"<td>"+val['email']+"</td>"+
"<td>"+val['purchases']+"</td>"+
"<td>"+val['storage']+"</td>"+
"<td>"+val['in_process']+"</td>"+
"</tr>"
);
});
$('#mostrar').append("</tbody>" +
"</table>");
$('#example').DataTable({
});
} }
}); });
}; };
function refresh() {
$.ajax({
type: 'POST',
dataType: "json",
data: {'title':label},
url: '../administration/ws/report_table',
success: function (data) {
alert(data);
}
});
};
</script> </script>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -19,6 +19,7 @@ from catalog.models import Purchase, Search ...@@ -19,6 +19,7 @@ from catalog.models import Purchase, Search
from catalog.views import config from catalog.views import config
USERS_PATH = config['PATHS']['PATH_NAS'] USERS_PATH = config['PATHS']['PATH_NAS']
PATH_USERS = config['PATHS']['PATH_USERS']
size_sentinel =0 size_sentinel =0
size_repsat=0 size_repsat=0
#------------------------------------------------------------ #------------------------------------------------------------
...@@ -52,7 +53,7 @@ def Dashboard(request): ...@@ -52,7 +53,7 @@ def Dashboard(request):
{'quantity': 0, 'date': 'December'}] {'quantity': 0, 'date': 'December'}]
# Obtener el nombre del mes # # Obtener el nombre del mes #
for date in Purchase.objects.filter().extra({'month': "Extract(month from aggreg_date)"}).values_list( for date in Purchase.objects.filter(purchased=True).extra({'month': "Extract(month from aggreg_date)"}).values_list(
'month').annotate(Count('id')): 'month').annotate(Count('id')):
date_name = calendar.month_name[int(date[0])] date_name = calendar.month_name[int(date[0])]
...@@ -161,46 +162,36 @@ def active_users(request): ...@@ -161,46 +162,36 @@ def active_users(request):
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# @csrf_exempt
# def wsPurchasesPM (request):
# if request.is_ajax():
# message = "Yes, AJAX!"
# id = request.user.id
#
# else:
# message = "Not Ajax"
#
# #
#
# return HttpResponse(message)
@csrf_exempt @csrf_exempt
def wsPurchasesPM(request): def wsPurchasesPM(request):
global mes
# print(request.POST.get('title'))
if request.is_ajax(): if request.is_ajax():
date_list = Purchase.objects.dates('aggreg_date', 'month')
for meses in date_list: table_data =[]
datee = datetime.datetime.strptime(str(meses), "%Y-%m-%d") data = Purchase.objects.values('user__username','aggreg_date__month','user_id','user__email').filter(purchased=True,
mes = calendar.month_name[int(datee.month)] aggreg_date__month=to_if(request.POST.get('title'))).annotate(dcount=Count('user__username')).order_by('-dcount')
# print(mes)
for user in data:
# data =Purchase.objects.filter(Q(date__month=1) | Q(date__month=2) | Q(date__month=3)) bytes_size = 0
# data = Purchase.objects.values('user__username').filter(Q(aggreg_date__month=to_if(mes))|Q(user__purchase_user_id = user__user_id)) for path, directories, files in os.walk(PATH_USERS+user['user__email']):
# data = Purchase.objects.values('user__username').filter(aggreg_date__month=to_if(mes)).annotate(count=Count('user_id')).order_by('-count')[:1] for filename in files:
bytes_size += os.lstat(os.path.join(path, filename)).st_size
data = Purchase.objects.values('id', 'user__username', 'aggreg_date', 'search__clouds', for directory in directories:
'search__startDate', bytes_size += os.lstat(os.path.join(path, directory)).st_size
'search__endDate', 'search__process_id__name').filter( bytes_size += os.path.getsize(PATH_USERS+user['user__email'])
aggreg_date__month=to_if(mes)).annotate(count_purchases=Count('id')).order_by('id') storage = best_unit_size(bytes_size)
print(data)
for dato in data: pending = Purchase.objects.filter(user_id=user['user_id'],aggreg_date__month=to_if(request.POST.get('title'))).exclude(progress=100).annotate(dcount=Count('progress'))
print(dato['count_purchases'])
table_data.append({
# return HttpResponse(json.dumps(request.POST.get('title'))) 'user_id':user['user_id'],
return HttpResponse(json.dumps(to_if(mes))) 'username':user['user__username'],
'email':user['user__email'],
'purchases':user['dcount'],
'storage':storage,
'in_process': pending.count(),
})
return HttpResponse(json.dumps(table_data))
else: else:
raise Http404 raise Http404
......
...@@ -140,10 +140,10 @@ def Reports(request): ...@@ -140,10 +140,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', '')
......
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