Move all the document statistics code to the documents.statistics module. Add month names to the statistics.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -31,7 +31,6 @@ from events.links import (
|
||||
)
|
||||
from events.permissions import permission_events_view
|
||||
from mayan.celery import app
|
||||
from mayan_statistics.classes import StatisticNamespace, CharJSLine
|
||||
from navigation import SourceColumn
|
||||
from rest_api.fields import DynamicSerializerField
|
||||
|
||||
@@ -97,11 +96,7 @@ from .queues import * # NOQA
|
||||
# Just import to initialize the search models
|
||||
from .search import document_search, document_page_search # NOQA
|
||||
from .signals import post_version_upload
|
||||
from .statistics import (
|
||||
new_documents_per_month, new_document_pages_per_month,
|
||||
new_document_versions_per_month, total_document_per_month,
|
||||
total_document_page_per_month, total_document_version_per_month
|
||||
)
|
||||
from .statistics import * # NOQA
|
||||
from .widgets import (
|
||||
DocumentPageThumbnailWidget, widget_document_page_number,
|
||||
widget_document_version_page_number
|
||||
@@ -537,50 +532,6 @@ class DocumentsApp(MayanAppConfig):
|
||||
links=(link_document_version_view,), sources=(DocumentVersion,)
|
||||
)
|
||||
|
||||
namespace = StatisticNamespace(slug='documents', label=_('Documents'))
|
||||
namespace.add_statistic(
|
||||
slug='new-documents-per-month',
|
||||
label=_('New documents per month'),
|
||||
func=new_documents_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='new-document-versions-per-month',
|
||||
label=_('New document versions per month'),
|
||||
func=new_document_versions_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='new-document-pages-per-month',
|
||||
label=_('New document pages per month'),
|
||||
func=new_document_pages_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='total-documents-at-each-month',
|
||||
label=_('Total documents at each month'),
|
||||
func=total_document_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='total-document-versions-at-each-month',
|
||||
label=_('Total document versions at each month'),
|
||||
func=total_document_version_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='total-document-pages-at-each-month',
|
||||
label=_('Total document pages at each month'),
|
||||
func=total_document_page_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
|
||||
post_delete.connect(
|
||||
dispatch_uid='handler_remove_empty_duplicates_lists',
|
||||
receiver=handler_remove_empty_duplicates_lists,
|
||||
|
||||
@@ -3,9 +3,19 @@ from __future__ import absolute_import, unicode_literals
|
||||
import datetime
|
||||
|
||||
from django.apps import apps
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
import qsstats
|
||||
|
||||
from mayan_statistics.classes import StatisticNamespace, CharJSLine
|
||||
|
||||
MONTH_NAMES = [
|
||||
_('January'), _('February'), _('March'), _('April'), _('May'),
|
||||
_('June'), _('July'), _('August'), _('September'), _('November'),
|
||||
_('December')
|
||||
]
|
||||
|
||||
|
||||
def new_documents_per_month():
|
||||
Document = apps.get_model(app_label='documents', model_name='Document')
|
||||
@@ -18,7 +28,7 @@ def new_documents_per_month():
|
||||
return {
|
||||
'series': {
|
||||
'Documents': map(
|
||||
lambda x: {x[0].month: x[1]},
|
||||
lambda x: {force_text(MONTH_NAMES[x[0].month]): x[1]},
|
||||
qss.time_series(start=this_year, end=today, interval='months')
|
||||
)
|
||||
}
|
||||
@@ -40,7 +50,7 @@ def new_document_pages_per_month():
|
||||
return {
|
||||
'series': {
|
||||
'Pages': map(
|
||||
lambda x: {x[0].month: x[1]},
|
||||
lambda x: {force_text(MONTH_NAMES[x[0].month]): x[1]},
|
||||
qss.time_series(start=this_year, end=today, interval='months')
|
||||
)
|
||||
}
|
||||
@@ -69,7 +79,7 @@ def new_document_versions_per_month():
|
||||
return {
|
||||
'series': {
|
||||
'Versions': map(
|
||||
lambda x: {x[0].month: x[1]},
|
||||
lambda x: {force_text(MONTH_NAMES[x[0].month]): x[1]},
|
||||
qss.time_series(start=this_year, end=today, interval='months')
|
||||
)
|
||||
}
|
||||
@@ -105,7 +115,13 @@ def total_document_per_month():
|
||||
next_month = month + 1
|
||||
year = this_year
|
||||
|
||||
result.append({month: qss.until(datetime.date(year, next_month, 1))})
|
||||
result.append(
|
||||
{
|
||||
force_text(
|
||||
MONTH_NAMES[month]
|
||||
): qss.until(datetime.date(year, next_month, 1))
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
'series': {
|
||||
@@ -136,7 +152,13 @@ def total_document_version_per_month():
|
||||
next_month = month + 1
|
||||
year = this_year
|
||||
|
||||
result.append({month: qss.until(datetime.date(year, next_month, 1))})
|
||||
result.append(
|
||||
{
|
||||
force_text(
|
||||
MONTH_NAMES[month]
|
||||
): qss.until(datetime.date(year, next_month, 1))
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
'series': {
|
||||
@@ -167,10 +189,61 @@ def total_document_page_per_month():
|
||||
next_month = month + 1
|
||||
year = this_year
|
||||
|
||||
result.append({month: qss.until(datetime.date(year, next_month, 1))})
|
||||
result.append(
|
||||
{
|
||||
force_text(
|
||||
MONTH_NAMES[month]
|
||||
): qss.until(datetime.date(year, next_month, 1))
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
'series': {
|
||||
'Pages': result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace = StatisticNamespace(slug='documents', label=_('Documents'))
|
||||
namespace.add_statistic(
|
||||
slug='new-documents-per-month',
|
||||
label=_('New documents per month'),
|
||||
func=new_documents_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='new-document-versions-per-month',
|
||||
label=_('New document versions per month'),
|
||||
func=new_document_versions_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='new-document-pages-per-month',
|
||||
label=_('New document pages per month'),
|
||||
func=new_document_pages_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='total-documents-at-each-month',
|
||||
label=_('Total documents at each month'),
|
||||
func=total_document_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='total-document-versions-at-each-month',
|
||||
label=_('Total document versions at each month'),
|
||||
func=total_document_version_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
namespace.add_statistic(
|
||||
slug='total-document-pages-at-each-month',
|
||||
label=_('Total document pages at each month'),
|
||||
func=total_document_page_per_month,
|
||||
renderer=CharJSLine,
|
||||
minute='0'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user