summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshen2018-12-05 17:50:00 +0530
committerGitHub2018-12-05 17:50:00 +0530
commitcf79305f5220f2dd53a1ea0f4188b25daea7ac05 (patch)
treee8722269a429acf139c2953f34ff7e6982cf623b
parent2aa7dd5097ba6d7189b587a0b1eca29df6bb9142 (diff)
parentde699e3da9b68669860aa68f2e0bacda51825651 (diff)
downloadworkshop_booking-cf79305f5220f2dd53a1ea0f4188b25daea7ac05.tar.gz
workshop_booking-cf79305f5220f2dd53a1ea0f4188b25daea7ac05.tar.bz2
workshop_booking-cf79305f5220f2dd53a1ea0f4188b25daea7ac05.zip
Merge pull request #74 from Akshen/stats
Stats
-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
})