浏览代码

Added graph of seum activity

Denis Merigoux 9 年之前
父节点
当前提交
d3a09f6087
共有 5 个文件被更改,包括 191 次插入11 次删除
  1. 1 0
      .gitignore
  2. 25 9
      counter/templates/homeTemplate.html
  3. 30 1
      counter/views.py
  4. 1 1
      seum/settings.py
  5. 134 0
      seum/settings.py.default

+ 1 - 0
.gitignore

@@ -66,3 +66,4 @@ target/
66 66
 
67 67
 #Custom
68 68
 python3/
69
+seum/settings.py

+ 25 - 9
counter/templates/homeTemplate.html

@@ -46,7 +46,23 @@
46 46
 		<div class="col-sm-12">
47 47
 			<div class="panel panel-default">
48 48
 				<div class="panel-heading">
49
-					<h2 class="panel-title">Graphe du seum</h2>
49
+					<h2 class="panel-title">Timeline des 24 heures du seum</h2>
50
+				</div>
51
+				<div class="panel-body timeline graphs">
52
+					{% if noTimeline %}
53
+					<div class="text-center text-muted">
54
+						<p>Pas de seum dans les dernières 24 heures...</p>
55
+					</div>
56
+					{% else %} {{ line_chart.as_html }} {% endif %}
57
+				</div>
58
+			</div>
59
+		</div>
60
+	</div>
61
+	<div class="row">
62
+		<div class="col-sm-12">
63
+			<div class="panel panel-default">
64
+				<div class="panel-heading">
65
+					<h2 class="panel-title">Graphe des jours sans seum</h2>
50 66
 				</div>
51 67
 				<div class="panel-body graphs">
52 68
 					{% if noGraph %}
@@ -62,14 +78,14 @@
62 78
 		<div class="col-sm-12">
63 79
 			<div class="panel panel-default">
64 80
 				<div class="panel-heading">
65
-					<h2 class="panel-title">Timeline du seum</h2>
81
+					<h2 class="panel-title">Meilleurs seumeurs</h2>
66 82
 				</div>
67
-				<div class="panel-body timeline graphs">
68
-					{% if noTimeline %}
83
+				<div class="panel-body graphs">
84
+					{% if noBestSeum %}
69 85
 					<div class="text-center text-muted">
70
-						<p>Pas de seum dans les dernières 24 heures...</p>
86
+						<p>Personne n'a eu le seum...</p>
71 87
 					</div>
72
-					{% else %} {{ line_chart.as_html }} {% endif %}
88
+					{% else %} {{ best_chart.as_html }} {% endif %}
73 89
 				</div>
74 90
 			</div>
75 91
 		</div>
@@ -78,14 +94,14 @@
78 94
 		<div class="col-sm-12">
79 95
 			<div class="panel panel-default">
80 96
 				<div class="panel-heading">
81
-					<h2 class="panel-title">Meilleurs seumeurs</h2>
97
+					<h2 class="panel-title">Activité seumesque</h2>
82 98
 				</div>
83 99
 				<div class="panel-body graphs">
84
-					{% if noBestSeum %}
100
+					{% if noSeumActivity %}
85 101
 					<div class="text-center text-muted">
86 102
 						<p>Personne n'a eu le seum...</p>
87 103
 					</div>
88
-					{% else %} {{ best_chart.as_html }} {% endif %}
104
+					{% else %} {{ activity_chart.as_html }} {% endif %}
89 105
 				</div>
90 106
 			</div>
91 107
 		</div>

+ 30 - 1
counter/views.py

@@ -151,15 +151,44 @@ def home(request):
151 151
             'vAxis': {'title': 'Nombre de seums'},
152 152
             'hAxis': {'title': 'Trigramme'},
153 153
         })
154
+    # Graph of seum activity
155
+    resets = Reset.objects.filter(
156
+        timestamp__gte=timezone.now() - timedelta(days=365))
157
+    months = {}
158
+    for reset in resets:
159
+        monthDate = datetime(reset.timestamp.year, reset.timestamp.month, 1)
160
+        months[monthDate] = months.get(monthDate, 0) + 1
161
+
162
+    monthList = sorted(months.items(), key=lambda t: t[0])
163
+    seumActivity = []
164
+    for month in monthList:
165
+        seumActivity.append(
166
+            [format_datetime(month[0], locale='fr',
167
+                             format="MMM Y").capitalize(), month[1]])
168
+    if (len(seumActivity) == 0):
169
+        noSeumActivity = True
170
+        activity_chart = None
171
+    else:
172
+        noSeumActivity = False
173
+        seumActivity.insert(0, ['Mois', 'Nombre de seums'])
174
+        activity_data = SimpleDataSource(seumActivity)
175
+        activity_chart = gchart.ColumnChart(activity_data, options={
176
+            'title': '',
177
+            'legend': 'none',
178
+            'vAxis': {'title': 'Nombre de seums'},
179
+            'hAxis': {'title': 'Mois'},
180
+        })
154 181
 
155 182
     return render(request, 'homeTemplate.html', {
156 183
         'counters': counters,
157 184
         'col_chart': col_chart,
158 185
         'line_chart': line_chart,
159 186
         'best_chart': best_chart,
187
+        'activity_chart': activity_chart,
160 188
         'noTimeline': noTimeline,
161 189
         'noGraph': noGraph,
162
-        'noBestSeum': noBestSeum
190
+        'noBestSeum': noBestSeum,
191
+        'noSeumActivity': noSeumActivity,
163 192
     })
164 193
 
165 194
 

+ 1 - 1
seum/settings.py

@@ -23,7 +23,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, "static/")
23 23
 SECRET_KEY = '(#lovv#uky9unr9azzqy14gktpf0(d&+cp@++l95*y4e%m%_ex'
24 24
 
25 25
 # SECURITY WARNING: don't run with debug turned on in production!
26
-DEBUG = False
26
+DEBUG = True
27 27
 
28 28
 ALLOWED_HOSTS = ['seum.merigoux.ovh']
29 29
 

+ 134 - 0
seum/settings.py.default

@@ -0,0 +1,134 @@
1
+"""
2
+Django settings for seum project.
3
+
4
+Generated by 'django-admin startproject' using Django 1.9.4.
5
+
6
+For more information on this file, see
7
+https://docs.djangoproject.com/en/1.9/topics/settings/
8
+
9
+For the full list of settings and their values, see
10
+https://docs.djangoproject.com/en/1.9/ref/settings/
11
+"""
12
+
13
+import os
14
+
15
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17
+STATIC_ROOT = os.path.join(BASE_DIR, "static/")
18
+
19
+# Quick-start development settings - unsuitable for production
20
+# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
21
+
22
+# SECURITY WARNING: keep the secret key used in production secret!
23
+SECRET_KEY = '(#lovv#uky9unr9azzqy14gktpf0(d&+cp@++l95*y4e%m%_ex'
24
+
25
+# SECURITY WARNING: don't run with debug turned on in production!
26
+DEBUG = True
27
+
28
+ALLOWED_HOSTS = ['seum.merigoux.ovh']
29
+
30
+
31
+# Application definition
32
+
33
+INSTALLED_APPS = [
34
+    'babel',
35
+    'graphos',
36
+    'bootstrap3',
37
+    'django.contrib.admin',
38
+    'django.contrib.auth',
39
+    'django.contrib.contenttypes',
40
+    'django.contrib.sessions',
41
+    'django.contrib.messages',
42
+    'django.contrib.staticfiles',
43
+    'counter'
44
+]
45
+
46
+MIDDLEWARE_CLASSES = [
47
+    'django.middleware.security.SecurityMiddleware',
48
+    'django.contrib.sessions.middleware.SessionMiddleware',
49
+    'django.middleware.common.CommonMiddleware',
50
+    'django.middleware.csrf.CsrfViewMiddleware',
51
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
52
+    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
53
+    'django.contrib.messages.middleware.MessageMiddleware',
54
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
55
+]
56
+
57
+ROOT_URLCONF = 'seum.urls'
58
+
59
+TEMPLATES = [
60
+    {
61
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
62
+        'DIRS': [],
63
+        'APP_DIRS': True,
64
+        'OPTIONS': {
65
+            'context_processors': [
66
+                'django.template.context_processors.debug',
67
+                'django.template.context_processors.request',
68
+                'django.contrib.auth.context_processors.auth',
69
+                'django.contrib.messages.context_processors.messages',
70
+            ],
71
+        },
72
+    },
73
+]
74
+
75
+WSGI_APPLICATION = 'seum.wsgi.application'
76
+
77
+
78
+# Database
79
+# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
80
+
81
+DATABASES = {
82
+    'default': {
83
+        'ENGINE': 'django.db.backends.sqlite3',
84
+        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
85
+    }
86
+}
87
+
88
+
89
+# Password validation
90
+# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
91
+
92
+AUTH_PASSWORD_VALIDATORS = [
93
+    {
94
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
95
+    },
96
+    {
97
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
98
+    },
99
+    {
100
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
101
+    },
102
+    {
103
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
104
+    },
105
+]
106
+
107
+
108
+# Internationalization
109
+# https://docs.djangoproject.com/en/1.9/topics/i18n/
110
+
111
+LANGUAGE_CODE = 'en-US'
112
+
113
+TIME_ZONE = 'UTC'
114
+
115
+USE_I18N = True
116
+
117
+USE_L10N = True
118
+
119
+USE_TZ = True
120
+
121
+
122
+# Static files (CSS, JavaScript, Images)
123
+# https://docs.djangoproject.com/en/1.9/howto/static-files/
124
+
125
+STATIC_URL = '/static/'
126
+
127
+#Emailing
128
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
129
+EMAIL_HOST = 'localhost'
130
+EMAIL_PORT = 25
131
+EMAIL_HOST_USER = ''
132
+EMAIL_HOST_PASSWORD = ''
133
+EMAIL_USE_TLS = False
134
+DEFAULT_FROM_EMAIL = 'SeumMan <seum@merigoux.ovh>'