added first implementation of statistic backend

This commit is contained in:
tkupek 2016-02-14 16:15:13 +01:00
parent dd1366a509
commit fc15b01d66
11 changed files with 105 additions and 21 deletions

View file

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />

Binary file not shown.

View file

@ -1,7 +0,0 @@
#Settings
INSERT INTO elearning_setting (title, message, active) VALUES ('vcp bayern - elearning', 'servus beim elearning des vcp land bayern!', 1);
#Questions
INSERT INTO elearning_question (id, title, text, options, answer, explanation) VALUES (0, 'Bananen', 'Warum ist die Banane krumm?', 'eins zwei oder drei', 1, 'darum');
INSERT INTO elearning_question (id, title, text, options, answer, explanation) VALUES (1, 'Einstein', 'Wie lautet die Relativitätstheorie?', 'oben unten rechts links', 2, 'ich nehm die drei');
INSERT INTO elearning_question (id, title, text, options, answer, explanation) VALUES (2, 'Wetter', 'Wie wird das Wetter?', 'gut schlecht dramatisch', 3, 'darum');

View file

@ -3,9 +3,7 @@ from __future__ import unicode_literals
import hashlib
import os
import binascii
from django.db import models
from django.db.models.signals import post_init, pre_init
class Setting(models.Model):
@ -49,6 +47,7 @@ class User(models.Model):
token = models.CharField(max_length=40, null=True, default=gen_token)
name = models.CharField(max_length=100, null=False)
last_seen = models.DateTimeField(null=True)
def __str__(self):
return self.name
@ -63,4 +62,4 @@ class UserAnswer(models.Model):
return str(self.user) + " - " + str(self.question)
class Meta:
unique_together = (('user', 'question'),)
unique_together = (('user', 'question'),)

View file

@ -51,3 +51,7 @@ p[id^="explanation_"] {
.message_already_answered {
font-style: italic;
}
.table_headline {
font-weight: bold;
}

View file

@ -7,7 +7,6 @@
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<link href="{% static 'images/favicon.ico' %}" rel="shortcut icon">
<script type="text/javascript" src="{% static 'js/elearning.js' %}"></script>
<title>{{ settings.title }}</title>
</head>

View file

@ -39,7 +39,7 @@
</form>
<p id="explanation_{{ question.id }}" class="hide">{{ question.explanation }}</p>
<div class="margin25" />
<div class="margin25"></div>
{% endfor %}
<div class="margin50" ></div>

View file

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<link href="{% static 'images/favicon.ico' %}" rel="shortcut icon">
<title>{{ settings.title }}</title>
</head>
<body>
<div class="container">
<img src="{{ settings.logo }}" class="mainLogo">
<h1>{{ settings.title }}</h1>
<p>Welcome to the statistic backend!</p>
<hr/>
<div class="margin50" ></div>
<h2>Users</h2>
<table>
<tr class="table_headline">
<td>name</td>
<td>questions answered</td>
<td>last seen</td>
</tr>
{% for user in users %}
<tr>
<td>{{ user.name }}</td>
<td>{{ user.questions_answered }}</td>
<td>{{ user.last_seen }}</td>
</tr>
{% endfor %}
</table>
<div class="margin50" ></div>
<h2>Questions</h2>
<table>
<tr class="table_headline">
<td>title</td>
<td>answers</td>
</tr>
{% for question in questions %}
<tr>
<td>{{ question.title }}</td>
<td>{{ question.answers }}</td>
</tr>
{% endfor %}
</table>
<div class="margin50" ></div>
<hr/>
{{ settings.footer }}
</div>
</body>
</html>

View file

@ -1,3 +1,3 @@
#from django.test import TestCase
# from django.test import TestCase
# Create your tests here.

View file

@ -1,12 +1,14 @@
import datetime
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponse
from django.shortcuts import render_to_response
from tkupek_elearning.elearning.models import Setting, Question, Option, UserAnswer, User
import pdb
# import pdb
def home(request):
def start(request):
token = request.GET.get('token')
@ -15,11 +17,12 @@ def home(request):
except ObjectDoesNotExist:
user = None
settings = Setting.objects.filter(active=1)
if settings:
settings = settings[0]
settings = Setting.objects.get(active=1)
if user is not None:
log_last_seen(user)
settings.message_welcome_user = settings.message_welcome_user.replace('{username}', user.name)
questions_options = {}
@ -52,6 +55,7 @@ def get_answer(request):
question = Question.objects.get(id=request_id)
user = User.objects.get(token=request_token)
log_last_seen(user)
user_answer = get_user_answer(question, user)
@ -80,4 +84,24 @@ def get_user_answer(question, user):
except ObjectDoesNotExist:
user_answer = None
return user_answer;
return user_answer
def log_last_seen(user):
user.last_seen = datetime.datetime.now()
user.save()
def statistic():
settings = Setting.objects.get(active=1)
users = User.objects.all()
for user in users:
user.questions_answered = UserAnswer.objects.filter(user=user.id).count()
questions = Question.objects.all()
for question in questions:
question.answers = UserAnswer.objects.filter(question=question.id).count()
return render_to_response('statistic.html', {'settings': settings, 'users': users, 'questions': questions})

View file

@ -20,6 +20,7 @@ import tkupek_elearning.elearning.views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'start', tkupek_elearning.elearning.views.home),
url(r'api', tkupek_elearning.elearning.views.get_answer)
url(r'start', tkupek_elearning.elearning.views.start),
url(r'api', tkupek_elearning.elearning.views.get_answer),
url(r'statistic', tkupek_elearning.elearning.views.statistic)
]