summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-07-26 13:17:37 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-07-26 13:17:37 +0200
commitb8ec4a8daf3ca973abefef2e1baa833a01f2bdcd (patch)
treeb9965fbe2fd173d3e58755d784030de25a82b88a
parent16f5a02a379009ad21cf3633d977f8886b830d9b (diff)
downloadIshtar-b8ec4a8daf3ca973abefef2e1baa833a01f2bdcd.tar.bz2
Ishtar-b8ec4a8daf3ca973abefef2e1baa833a01f2bdcd.zip
Archaeological file dashboard (closes #521)
-rw-r--r--ishtar/ishtar_base/models.py134
-rw-r--r--ishtar/templates/dashboard_file.html231
2 files changed, 288 insertions, 77 deletions
diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py
index 6f29196ce..e686b6ca2 100644
--- a/ishtar/ishtar_base/models.py
+++ b/ishtar/ishtar_base/models.py
@@ -28,7 +28,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.safestring import SafeUnicode, mark_safe
from django.core.urlresolvers import reverse, NoReverseMatch
from django.db.utils import DatabaseError
-from django.db.models import Q, Max, Count
+from django.db.models import Q, Max, Count, Sum
from django.db.models.signals import m2m_changed
from django.contrib.auth.models import User
@@ -360,8 +360,8 @@ class UserDashboard:
def __init__(self):
types = IshtarUser.objects.values('person__person_type',
'person__person_type__label')
- self.types = types.annotate(number=Count('pk')).order_by(
- 'person__person_type')
+ self.types = types.annotate(number=Count('pk'))\
+ .order_by('person__person_type')
class FileDashboard:
def __init__(self):
@@ -372,36 +372,114 @@ class FileDashboard:
types = File.objects.values('file_type', 'file_type__label')
self.types = types.annotate(number=Count('pk')).order_by('file_type')
- self.by_years = main_dashboard.values
+ by_year = File.objects.extra(
+ {'date':"date_trunc('year', creation_date)"})
+ self.by_year = by_year.values('date')\
+ .annotate(number=Count('pk')).order_by('-date')
now = datetime.date.today()
limit = datetime.date(now.year, now.month, 1) - datetime.timedelta(365)
by_month = File.objects.filter(creation_date__gt=limit).extra(
- {'month':"date_trunc('month', creation_date)"})
- self.by_month = by_month.values('month').annotate(number=Count('pk')
- ).order_by('-month')
+ {'date':"date_trunc('month', creation_date)"})
+ self.by_month = by_month.values('date')\
+ .annotate(number=Count('pk')).order_by('-date')
- # programmed
- self.prog = {}
+ # research
+ self.research = {}
prog_type = FileType.objects.get(txt_idx='prog')
- progs = File.objects.filter(file_type=prog_type)
- self.prog['total_number'] = progs.count()
- by_year = progs.extra({'year':"date_trunc('year', creation_date)"})
- self.prog['by_year'] = by_year.values('year').annotate(number=Count('pk')
- ).order_by('-year')
- by_month = progs.filter(creation_date__gt=limit).extra(
- {'month':"date_trunc('month', creation_date)"})
- self.prog['by_month'] = by_month.values('month').annotate(
- number=Count('pk')).order_by('-month')
-
- self.prog['by_dpts'] = FileByDepartment.objects.filter(
- file__file_type=prog_type).values('department'
- ).annotate(number=Count('file')).order_by('-number')
+ researchs = File.objects.filter(file_type=prog_type)
+ self.research['total_number'] = researchs.count()
+ by_year = researchs.extra({'date':"date_trunc('year', creation_date)"})
+ self.research['by_year'] = by_year.values('date')\
+ .annotate(number=Count('pk'))\
+ .order_by('-date')
+ by_month = researchs.filter(creation_date__gt=limit)\
+ .extra({'date':"date_trunc('month', creation_date)"})
+ self.research['by_month'] = by_month.values('date')\
+ .annotate(number=Count('pk'))\
+ .order_by('-date')
+
+ self.research['by_dpt'] = FileByDepartment.objects\
+ .filter(file__file_type=prog_type)\
+ .values('department__label')\
+ .annotate(number=Count('file'))\
+ .order_by('department__label')
FileTown = File.towns.through
- self.prog['towns'] = FileTown.objects.filter(
- file__file_type=prog_type).values('town'
- ).annotate(number=Count('file')).order_by('-number')
-
+ self.research['towns'] = FileTown.objects\
+ .filter(file__file_type=prog_type)\
+ .values('town__name')\
+ .annotate(number=Count('file'))\
+ .order_by('-number','town__name')[:10]
+
+ # rescue
+ rescue_type = FileType.objects.get(txt_idx='preventive')
+ rescues = File.objects.filter(file_type=rescue_type)
+ self.rescue = {}
+ self.rescue['total_number'] = rescues.count()
+ self.rescue['saisine'] = rescues.values('saisine_type__label')\
+ .annotate(number=Count('pk'))\
+ .order_by('saisine_type__label')
+ self.rescue['administrative_act'] = AdministrativeAct.objects\
+ .filter(associated_file__isnull=False)\
+ .values('act_type__label')\
+ .annotate(number=Count('pk'))\
+ .order_by('act_type__pk')
+
+ by_year = rescues.extra({'date':"date_trunc('year', creation_date)"})
+ self.rescue['by_year'] = by_year.values('date')\
+ .annotate(number=Count('pk'))\
+ .order_by('-date')
+ by_month = rescues.filter(creation_date__gt=limit)\
+ .extra({'date':"date_trunc('month', creation_date)"})
+ self.rescue['by_month'] = by_month.values('date')\
+ .annotate(number=Count('pk'))\
+ .order_by('-date')
+
+ self.rescue['by_dpt'] = FileByDepartment.objects\
+ .filter(file__file_type=rescue_type)\
+ .values('department__label')\
+ .annotate(number=Count('file'))\
+ .order_by('department__label')
+ self.rescue['towns'] = FileTown.objects\
+ .filter(file__file_type=rescue_type)\
+ .values('town__name')\
+ .annotate(number=Count('file'))\
+ .order_by('-number','town__name')[:10]
+
+ self.rescue['with_associated_operation'] = rescues\
+ .filter(operations__isnull=False).count()
+
+ self.rescue['with_associated_operation_percent'] = round(
+ float(self.rescue['with_associated_operation'])\
+ /self.rescue['total_number']*100, 2)
+
+ by_year_operationnal = rescues.filter(operations__isnull=False)\
+ .extra({'date':"date_trunc('year', creation_date)"})
+ by_year_operationnal = by_year_operationnal.values('date')\
+ .annotate(number=Count('pk'))\
+ .order_by('-date')
+ percents, idx = [], 0
+ for dct in self.rescue['by_year']:
+ if idx > len(by_year_operationnal):
+ break
+ if by_year_operationnal[idx]['date'] != dct['date'] or\
+ not dct['number']:
+ continue
+ val = round(float(by_year_operationnal[idx]['number'])/\
+ dct['number']*100, 2)
+ percents.append({'date':dct['date'], 'number':val})
+ self.rescue['operational_by_year'] = percents
+
+ self.rescue['surface_by_town'] = FileTown.objects\
+ .filter(file__file_type=rescue_type)\
+ .values('town__name')\
+ .annotate(number=Sum('file__total_surface'))\
+ .order_by('-number','town__name')[:10]
+ self.rescue['surface_by_dpt'] = FileByDepartment.objects\
+ .filter(file__file_type=rescue_type)\
+ .values('department__label')\
+ .annotate(number=Sum('file__total_surface'))\
+ .order_by('department__label')
class Dashboard:
def __init__(self, model):
@@ -411,8 +489,8 @@ class Dashboard:
# last edited - created
self.recents, self.lasts = [], []
for last_lst, modif_type in ((self.lasts, '+'), (self.recents, '~')):
- last_ids = history_model.objects.values('id').annotate(hd=\
- Max('history_date'))
+ last_ids = history_model.objects.values('id')\
+ .annotate(hd=Max('history_date'))
last_ids = last_ids.filter(history_type=modif_type)
if self.model == Item:
last_ids = last_ids.filter(downstream_treatment_id__isnull=True)
diff --git a/ishtar/templates/dashboard_file.html b/ishtar/templates/dashboard_file.html
index e710dbe16..cebd147f4 100644
--- a/ishtar/templates/dashboard_file.html
+++ b/ishtar/templates/dashboard_file.html
@@ -6,77 +6,210 @@
{% endblock %}
{% block content %}
<div class='dashboard'>
-{% for lbl, dashboard in items %}
+ <h2>{% trans "Archaeological files" %}</h2>
<div>
- <h3>{{lbl}}</h3>
- <h4>{% trans "Numbers" %}</h4>
+ <h3>{% trans "Global informations" %}</h3>
+
<p><strong>{% trans "Total:" %}</strong> {{dashboard.total_number}}</p>
+ {% for type in dashboard.types %}
+ <p><strong>{{type.file_type__label}}{% trans ":"%}</strong> {{type.number}}</p>
+ {% endfor %}
<div class='table'>
<table>
- {% for idx, lbl, values in dashboard.values %}
- <tr class='idx {% if forloop.counter0|divisibleby:"2" %}even{%else%}odd{%endif%}'>
- <th>{{lbl}}</th>
- {% for value in values %}<td>{{value}}</td>{% endfor%}
+ <caption>{% trans "By year"%}</caption>
+ <tr>
+ {% for year in dashboard.by_year %}<th>{{year.date.year}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for year in dashboard.by_year %}<td>{{year.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "By month"%}</caption>
+ <tr>
+ {% for month in dashboard.by_month %}<th>{{month.date|date:"F Y"|capfirst}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for month in dashboard.by_month %}<td>{{month.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ </div>
+ <div>
+
+ <h3>{% trans "Research archaeology" %}</h3>
+
+ <p><strong>{% trans "Total:" %}</strong> {{dashboard.research.total_number}}</p>
+ <div class='table'>
+ <table>
+ <caption>{% trans "By year"%}</caption>
+ <tr>
+ {% for year in dashboard.research.by_year %}<th>{{year.date.year}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for year in dashboard.research.by_year %}<td>{{year.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "By month"%}</caption>
+ <tr>
+ {% for month in dashboard.research.by_month %}<th>{{month.date|date:"F Y"|capfirst}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for month in dashboard.research.by_month %}<td>{{month.number}}</td>{% endfor%}
</tr>
- {% endfor%}
</table>
</div>
- {% if dashboard.years %}
- <h4>{% trans "By years" %}</h4>
- <ul>
- <li><strong>{% trans "Average:" %}</strong> {{dashboard.average}}</li>
- <li><strong>{% trans "Variance:" %}</strong> {{dashboard.variance}}</li>
- <li><strong>{% trans "Standard deviation:" %}</strong> {{dashboard.standard_deviation}}</li>
- <li><strong>{% trans "Median:" %}</strong> {{dashboard.median}}</li>
- <li><strong>{% trans "Mode:" %}</strong> {{dashboard.mode}}</li>
- </ul>
- {% endif %}
- {% if dashboard.operation_average %}
- <h4>{% trans "By operations" %}</h4>
- <ul>
- <li><strong>{% trans "Average:" %}</strong> {{dashboard.operation_average}}</li>
- <li><strong>{% trans "Variance:" %}</strong> {{dashboard.operation_variance}}</li>
- <li><strong>{% trans "Standard deviation:" %}</strong> {{dashboard.operation_standard_deviation}}</li>
- <li><strong>{% trans "Median:" %}</strong> {{dashboard.operation_median}}</li>
- <li><strong>{% trans "Mode:" %}</strong> {{dashboard.operation_mode}}</li>
- </ul>
- {% endif %}
- <h4>{% trans "Created last" %}</h4>
+
<div class='table'>
<table>
- <tr><th>{{lbl}}</th><th>{% trans "Created" %}</th><th></th></tr>
- {% for item in dashboard.lasts %}<tr>
- <td class='ref'>{{item}}</td>
- <td>{{item.history_date}}</td>
- <td>{% if item.get_show_url %}<a href="#" onclick='load_window("{{item.get_show_url}}")'>{%trans "Show"%}</a>{%endif%}</td>
- </tr>{% endfor %}
+ <caption>{% trans "By department"%}</caption>
+ <tr>
+ {% for dpt in dashboard.research.by_dpt %}<th>{{dpt.department__label}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for dpt in dashboard.research.by_dpt %}<td>{{dpt.number}}</td>{% endfor%}
+ </tr>
</table>
</div>
- <h4>{% trans "Recent changes" %}</h4>
+
<div class='table'>
<table>
- <tr><th>{{lbl}}</th><th>{% trans "Modified" %}</th><th></th></tr>
- {% for item in dashboard.recents %}<tr>
- <td class='ref'>{{item}}</td>
- <td>{{item.history_date}}</td>
- <td>{% if item.get_show_url %}<a href="#" onclick='load_window("{{item.get_show_url}}")'>{%trans "Show"%}</a>{%endif%}</td>
- </tr>{% endfor %}
+ <caption>{% trans "Main towns"%}</caption>
+ <tr>
+ {% for town in dashboard.research.towns %}<th>{{town.town__name}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for town in dashboard.research.towns %}<td>{{town.number}}</td>{% endfor%}
+ </tr>
</table>
</div>
+
</div>
-{% endfor%}
<div>
- <h3>{% trans "Users" %}</h3>
+
+ <h3>{% trans "Rescue archaeology" %}</h3>
+
+ <p><strong>{% trans "Total:" %}</strong> {{dashboard.rescue.total_number}}</p>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "By saisine type"%}</caption>
+ <tr>
+ {% for saisine in dashboard.rescue.saisine %}<th>{{saisine.saisine_type__label}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for saisine in dashboard.rescue.saisine %}<td>{{saisine.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "By administrative act"%}</caption>
+ <tr>
+ {% for act in dashboard.rescue.administrative_act %}<th>{{act.act_type__label}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for act in dashboard.rescue.administrative_act %}<td>{{act.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "By year"%}</caption>
+ <tr>
+ {% for year in dashboard.rescue.by_year %}<th>{{year.date.year}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for year in dashboard.rescue.by_year %}<td>{{year.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "By month"%}</caption>
+ <tr>
+ {% for month in dashboard.rescue.by_month %}<th>{{month.date|date:"F Y"|capfirst}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for month in dashboard.rescue.by_month %}<td>{{month.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ <p><strong>{% trans "Archaeological files linked to at least one operation:" %}</strong> {{dashboard.rescue.with_associated_operation}}</p>
+ <p><strong>{% trans "Archaeological files linked to at least one operation (%):" %}</strong> {{dashboard.rescue.with_associated_operation_percent}}</p>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "Archaeological files linked to at least one operation (%)"%}</caption>
+ <tr>
+ {% for year in dashboard.rescue.operational_by_year %}<th>{{year.date.year}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for year in dashboard.rescue.operational_by_year %}<td>{{year.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "By department"%}</caption>
+ <tr>
+ {% for dpt in dashboard.rescue.by_dpt %}<th>{{dpt.department__label}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for dpt in dashboard.rescue.by_dpt %}<td>{{dpt.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "Surface by department (m²)"%}</caption>
+ <tr>
+ {% for dpt in dashboard.rescue.surface_by_dpt %}<th>{{dpt.department__label}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for dpt in dashboard.rescue.surface_by_dpt %}<td>{{dpt.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
<div class='table'>
<table>
- <tr><th>{% trans "User type" %}</th><th>{% trans "Number" %}</th></tr>
- {% for user_type in ishtar_users.types %}
+ <caption>{% trans "Main towns by number"%}</caption>
+ <tr>
+ {% for town in dashboard.rescue.towns %}<th>{{town.town__name}}</th>{% endfor %}
+ </tr>
<tr>
- <td class='string'>{{user_type.person__person_type__label}}</td>
- <td>{{user_type.number}}</td>
+ {% for town in dashboard.rescue.towns %}<td>{{town.number}}</td>{% endfor%}
</tr>
- {% endfor%}
</table>
</div>
+
+ <div class='table'>
+ <table>
+ <caption>{% trans "Main towns by surface (m²)"%}</caption>
+ <tr>
+ {% for town in dashboard.rescue.surface_by_town %}<th>{{town.town__name}}</th>{% endfor %}
+ </tr>
+ <tr>
+ {% for town in dashboard.rescue.surface_by_town %}<td>{{town.number}}</td>{% endfor%}
+ </tr>
+ </table>
+ </div>
+
+ </div>
</div>
{% endblock %}