Finish conversion of statistic to periodic statistics. Add ChartJS support. Add Line chart renderer.
This commit is contained in:
@@ -29,7 +29,7 @@ from events.permissions import permission_events_view
|
||||
from mayan.celery import app
|
||||
from navigation import SourceColumn
|
||||
from rest_api.classes import APIEndPoint
|
||||
from statistics.classes import StatisticNamespace
|
||||
from statistics.classes import StatisticNamespace, CharJSLine
|
||||
|
||||
from .handlers import create_default_document_type
|
||||
from .links import (
|
||||
@@ -72,7 +72,10 @@ from .permissions import (
|
||||
permission_document_view
|
||||
)
|
||||
from .settings import setting_thumbnail_size
|
||||
from .statistics import document_page_count_per_month
|
||||
from .statistics import (
|
||||
new_documents_per_month, new_document_pages_per_month,
|
||||
new_document_versions_per_month
|
||||
)
|
||||
from .widgets import document_thumbnail
|
||||
|
||||
|
||||
@@ -351,9 +354,22 @@ class DocumentsApp(MayanAppConfig):
|
||||
|
||||
namespace = StatisticNamespace(name='documents', label=_('Documents'))
|
||||
namespace.add_statistic(
|
||||
slug='document-page-count-per-month',
|
||||
label=_('Document page count per month'),
|
||||
func=document_page_count_per_month
|
||||
slug='new-documents-per-month',
|
||||
label=_('New documents per month'),
|
||||
func=new_documents_per_month,
|
||||
renderer=CharJSLine
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='new-document-versions-per-month',
|
||||
label=_('New document versions per month'),
|
||||
func=new_document_versions_per_month,
|
||||
renderer=CharJSLine
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='new-document-pages-per-month',
|
||||
label=_('New document pages per month'),
|
||||
func=new_document_pages_per_month,
|
||||
renderer=CharJSLine
|
||||
)
|
||||
|
||||
post_initial_setup.connect(
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import datetime
|
||||
|
||||
import qsstats
|
||||
|
||||
from django.db.models import Avg, Count, Max, Min
|
||||
from django.template.defaultfilters import filesizeformat
|
||||
from django.utils import formats
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from statistics.classes import Statistic
|
||||
@@ -40,41 +46,45 @@ def storage_count(path='.'):
|
||||
return total_count, total_size
|
||||
|
||||
|
||||
def document_page_count_per_month():
|
||||
return (
|
||||
(
|
||||
{'August, 2015': 1244},
|
||||
{'September, 2015': 3123},
|
||||
),
|
||||
)
|
||||
def new_documents_per_month():
|
||||
qss = qsstats.QuerySetStats(Document.passthrough.all(), 'date_added')
|
||||
|
||||
today = datetime.date.today()
|
||||
this_year = datetime.date(year=today.year, month=1, day=1)
|
||||
|
||||
return {
|
||||
'series': {
|
||||
'Document': map(lambda x: {x[0].month: x[1]}, qss.time_series(start=this_year, end=today, interval='months'))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#def get_results(self):
|
||||
# return (
|
||||
## (
|
||||
# {_('Document types'): DocumentType.objects.count()},
|
||||
# ),
|
||||
# )
|
||||
def new_document_versions_per_month():
|
||||
qss = qsstats.QuerySetStats(DocumentVersion.objects.all(), 'document__date_added')
|
||||
|
||||
today = datetime.date.today()
|
||||
this_year = datetime.date(year=today.year, month=1, day=1)
|
||||
|
||||
return {
|
||||
'series': {
|
||||
'Document': map(lambda x: {x[0].month: x[1]}, qss.time_series(start=this_year, end=today, interval='months'))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def new_document_pages_per_month():
|
||||
qss = qsstats.QuerySetStats(DocumentPage.objects.all(), 'document_version__document__date_added')
|
||||
|
||||
today = datetime.date.today()
|
||||
this_year = datetime.date(year=today.year, month=1, day=1)
|
||||
|
||||
return {
|
||||
'series': {
|
||||
'Document': map(lambda x: {x[0].month: x[1]}, qss.time_series(start=this_year, end=today, interval='months'))
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
document_stats = DocumentVersion.objects.annotate(
|
||||
page_count=Count('pages')
|
||||
).aggregate(Min('page_count'), Max('page_count'), Avg('page_count'))
|
||||
results.extend(
|
||||
[
|
||||
_(
|
||||
'Minimum amount of pages per document: %d'
|
||||
) % (document_stats['page_count__min'] or 0),
|
||||
_(
|
||||
'Maximum amount of pages per document: %d'
|
||||
) % (document_stats['page_count__max'] or 0),
|
||||
_(
|
||||
'Average amount of pages per document: %f'
|
||||
) % (document_stats['page_count__avg'] or 0),
|
||||
]
|
||||
)
|
||||
|
||||
return results
|
||||
"""
|
||||
|
||||
class DocumentUsageStatistics(Statistic):
|
||||
@@ -111,3 +121,4 @@ class DocumentUsageStatistics(Statistic):
|
||||
)
|
||||
|
||||
return results
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user