summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshen2018-10-22 15:25:19 +0530
committerAkshen2018-10-22 15:25:19 +0530
commitaca1be5265bbc4d7f2c97e01dc77b3e7cd68dec8 (patch)
treec602b1222b01ea5fd77890894fc51a7e30a712ed
parentbd0f67273e0630c468971c7470479e13a36a41db (diff)
downloadworkshop_booking-aca1be5265bbc4d7f2c97e01dc77b3e7cd68dec8.tar.gz
workshop_booking-aca1be5265bbc4d7f2c97e01dc77b3e7cd68dec8.tar.bz2
workshop_booking-aca1be5265bbc4d7f2c97e01dc77b3e7cd68dec8.zip
Adds Workshop Month Mean
- Calculates mean for workshops monthly from the beginning to current year - Displays on monthly chart as Line
-rw-r--r--requirements.txt1
-rw-r--r--statistics_app/templates/statistics_app/workshop_stats.html16
-rw-r--r--statistics_app/views.py60
3 files changed, 70 insertions, 7 deletions
diff --git a/requirements.txt b/requirements.txt
index efa8668..26dfdca 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,3 +6,4 @@ pytz==2016.10
six==1.10.0
coverage
pyaml
+pandas==0.18.0
diff --git a/statistics_app/templates/statistics_app/workshop_stats.html b/statistics_app/templates/statistics_app/workshop_stats.html
index 6a48279..f5f5eb0 100644
--- a/statistics_app/templates/statistics_app/workshop_stats.html
+++ b/statistics_app/templates/statistics_app/workshop_stats.html
@@ -153,7 +153,6 @@
{% endif %}
{% endfor %}
</table>
-
<!-- Page Navigation -->
<div class="container">
<div class="Page-Nav" align="center">
@@ -246,7 +245,20 @@
'rgba(191, 191, 191, 1)'
],
borderWidth: 1
- }]
+ },
+ {
+ label: 'Expected Workshops',
+ type: 'line',
+ data: {{ workshop_mean }},
+ fill: false,
+ borderColor: [
+ 'rgba(0, 0, 128, 0.7)'
+ ]
+
+
+ }
+
+ ]
},
options: {
responsive: true,
diff --git a/statistics_app/views.py b/statistics_app/views.py
index a97c5c3..1507196 100644
--- a/statistics_app/views.py
+++ b/statistics_app/views.py
@@ -25,6 +25,7 @@ from os import listdir, path, sep
from zipfile import ZipFile
from django.contrib import messages
from operator import itemgetter
+from pandas import DataFrame
import datetime as dt
import csv
try:
@@ -82,7 +83,7 @@ def pie_chart():
def india_map():
- '''This function returns count of workshops based on states in India.'''
+ '''This function returns count of workshops based on states in India.'''
states = [
['Code', 'State', 'Number'],
@@ -140,13 +141,12 @@ def india_map():
-@login_required
-def workshop_stats(request):
- user = request.user
+def monthly_accepted_chart():
+ '''This function returns workshops accepted for each month
+ in the current year'''
today = datetime.now()
upto = today + dt.timedelta(days=15)
- # For Monthly Chart
workshop_count = [0] * 12
for x in range(12):
workshop_count[x] += RequestedWorkshop.objects.filter(
@@ -158,6 +158,54 @@ def workshop_stats(request):
proposed_workshop_date__month=str(x + 1),
status='ACCEPTED').count()
+ return workshop_count
+
+
+
+def monthly_avg():
+ '''This function returns monthly mean of workshops from the
+ beginning to current year'''
+ current_year = datetime.today().year
+ start_year = 2017
+ total_monthly_workshop = {}
+ for i in range(start_year, current_year+1):
+ total_monthly_workshop[i] = []
+
+ years = total_monthly_workshop.keys()
+
+ for i in years:
+ for j in range(12):
+ data = RequestedWorkshop.objects.filter(
+ requested_workshop_date__year=str(i),
+ requested_workshop_date__month=str(j+1),
+ status='ACCEPTED').count()
+
+ data += ProposeWorkshopDate.objects.filter(
+ proposed_workshop_date__year=str(i),
+ proposed_workshop_date__month=str(j+1),
+ status='ACCEPTED').count()
+ total_monthly_workshop[i].append(data)
+
+ df = DataFrame.from_dict(total_monthly_workshop)
+ monthly_workshop_mean = df.mean(axis=1)
+
+ return list(monthly_workshop_mean)
+
+
+
+@login_required
+def workshop_stats(request):
+ user = request.user
+ today = datetime.now()
+ upto = today + dt.timedelta(days=15)
+
+
+ #For Monthly Chart
+ workshop_count = monthly_accepted_chart()
+
+ #For Monthly Workshop Mean
+ workshop_mean = monthly_avg()
+
# For Pie Chart
workshoptype_count = pie_chart()
@@ -246,6 +294,7 @@ def workshop_stats(request):
{"upcoming_workshops": upcoming_workshops,
"show_workshop_stats": settings.SHOW_WORKSHOP_STATS,
"workshop_count": workshop_count,
+ "workshop_mean": workshop_mean,
"workshoptype_count": workshoptype_count,
"india_map": states})
except BaseException:
@@ -296,6 +345,7 @@ def workshop_stats(request):
"upcoming_workshops": upcoming_workshops,
"show_workshop_stats": settings.SHOW_WORKSHOP_STATS,
"workshop_count": workshop_count,
+ "workshop_mean": workshop_mean,
"workshoptype_count": workshoptype_count,
"india_map": states
})