diff --git a/server/assignments/migrations/0004_auto_20190210_2113.py b/server/assignments/migrations/0004_auto_20190210_2113.py
new file mode 100644
index 00000000..8e8c5a90
--- /dev/null
+++ b/server/assignments/migrations/0004_auto_20190210_2113.py
@@ -0,0 +1,20 @@
+# Generated by Django 2.0.6 on 2019-02-10 21:13
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('assignments', '0003_auto_20181018_0800'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='studentsubmission',
+ name='student',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='submissions', to=settings.AUTH_USER_MODEL),
+ ),
+ ]
diff --git a/server/assignments/models.py b/server/assignments/models.py
index cc53385c..8ece20fa 100644
--- a/server/assignments/models.py
+++ b/server/assignments/models.py
@@ -30,7 +30,7 @@ class StudentSubmission(TimeStampedModel):
text = models.TextField(blank=True)
document = models.URLField(blank=True, default='', max_length=255)
assignment = models.ForeignKey(Assignment, on_delete=models.CASCADE, related_name='submissions')
- student = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
+ student = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, related_name='submissions')
final = models.BooleanField(default=False)
def __str__(self):
diff --git a/server/rooms/migrations/0004_auto_20190210_2125.py b/server/rooms/migrations/0004_auto_20190210_2125.py
new file mode 100644
index 00000000..443f303f
--- /dev/null
+++ b/server/rooms/migrations/0004_auto_20190210_2125.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.0.6 on 2019-02-10 21:25
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('rooms', '0003_remove_roomentry_subtitle'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='room',
+ name='school_class',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rooms', to='users.SchoolClass'),
+ ),
+ ]
diff --git a/server/rooms/models.py b/server/rooms/models.py
index 16da5036..322183b8 100644
--- a/server/rooms/models.py
+++ b/server/rooms/models.py
@@ -13,7 +13,7 @@ class Room(TitleSlugDescriptionModel):
verbose_name = 'Raum'
verbose_name_plural = 'Räume'
- school_class = models.ForeignKey(SchoolClass, blank=False, null=False, on_delete=models.CASCADE)
+ school_class = models.ForeignKey(SchoolClass, blank=False, null=False, on_delete=models.CASCADE, related_name='rooms')
appearance = models.CharField(blank=True, null=False, max_length=255)
def __str__(self):
diff --git a/server/statistics/templates/statistics.html b/server/statistics/templates/statistics.html
index 340b116e..8e60a87e 100644
--- a/server/statistics/templates/statistics.html
+++ b/server/statistics/templates/statistics.html
@@ -1,84 +1,133 @@
{% extends "base.html" %}
{% block body %}
-
Statistics
+ Statistiken
Ergebnisse
-
+
Total Anzahl erfasste Ergebnisse (nur für Schüler gespeichert)
-
+
- 0
+ {{ private_submissions }}
-
+
Total Anzahl erfasste Ergebnisse (mit Lehrperson geteilt)
-
+
- 0
+ {{ shared_submissions }}
-
+
Anzahl erfasste Ergebnisse pro Modul (nur für Schüler gespeichert)
-
+
- 0
+ {% for module in modules %}
+
+ {{ module.title }}
+
+
+ {{ module.private_submissions }}
+
+ {% endfor %}
-
+
Anzahl erfasste Ergebnisse pro Modul (mit Lehrperson geteilt)
-
+
- 0
+ {% for module in modules %}
+
+ {{ module.title }}
+
+
+ {{ module.shared_submissions }}
+
+ {% endfor %}
-
+
Anzahl erfasste Ergebnisse pro Klasse (nur für Schüler gespeichert)
-
+
- 0
+ {% for school_class in classes %}
+
+ {{ school_class.name }}
+
+
+ {{ school_class.private_submissions }}
+
+ {% endfor %}
-
+
Anzahl erfasste Ergebnisse pro Klasse (mit Lehrperson geteilt)
-
+
- 0
+ {% for school_class in classes %}
+
+ {{ school_class.name }}
+
+
+ {{ school_class.shared_submissions }}
+
+ {% endfor %}
Räume
-
+
Anzahl erfasste Räume pro Klasse
-
+
- 0
+ {% for school_class in room_classes %}
+
+ {{ school_class.name }}
+
+
+ {{ school_class.room_count }}
+
+ {% endfor %}
-
+
Anzahl erfasste Raumeinträge pro Klasse
-
+
- 0
+ {% for school_class in room_entries_classes %}
+
+ {{ school_class.name }}
+
+
+ {{ school_class.room_entry_count }}
+
+ {% endfor %}
-
+
Anzahl erfasste Raumeinträge pro Raum
-
+
- 0
+ {% for room in rooms %}
+
+ {{ room.title }}
+
+
+ {{ room.room_entry_count }}
+
+ {% endfor %}
@@ -86,25 +135,25 @@
Inhaltsblöcke
-
+
Total Anzahl erfasste Inhaltsblöcke
-
+
- 0
+ {{ content_block_count }}
-
+
Anzahl erfasste Inhaltsblöcke pro Klasse
-
+
0
-
+
Wieviele Personen haben einen oder mehrere Inhaltsblöcke erfasst?
-
+
0
diff --git a/server/statistics/views.py b/server/statistics/views.py
index 307e83df..be16368c 100644
--- a/server/statistics/views.py
+++ b/server/statistics/views.py
@@ -1,13 +1,51 @@
-from django.http import HttpResponse
-import datetime
-
+from django.db.models import Count, Q
from django.views.generic import TemplateView
+from assignments.models import StudentSubmission
+from books.models import Module, ContentBlock
+from rooms.models import Room
+from users.models import SchoolClass
+
class StatisticsView(TemplateView):
template_name = "statistics.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
- context['test'] = 'hello'
+
+ private_submissions = StudentSubmission.objects.filter(final=False).count()
+ shared_submissions = StudentSubmission.objects.filter(final=True).count()
+
+ private_submissions_by_module = Count('assignments__submissions',
+ filter=Q(assignments__submissions__final=False))
+ shared_submissions_by_module = Count('assignments__submissions', filter=Q(assignments__submissions__final=True))
+
+ modules = Module.objects.values('title').annotate(private_submissions=private_submissions_by_module).annotate(
+ shared_submissions=shared_submissions_by_module)
+
+ private_submissions_by_class = Count('users__submissions', filter=Q(users__submissions__final=False))
+ shared_submissions_by_class = Count('users__submissions', filter=Q(users__submissions__final=True))
+ rooms_by_class = Count('rooms')
+ room_entries_by_class = Count('rooms__room_entries')
+ room_entries_by_room = Count('room_entries')
+
+ classes = SchoolClass.objects.values('name').annotate(
+ private_submissions=private_submissions_by_class).annotate(shared_submissions=shared_submissions_by_class)
+
+ room_classes = SchoolClass.objects.values('name').annotate(room_count=rooms_by_class)
+ room_entries_classes = SchoolClass.objects.values('name').annotate(room_entry_count=room_entries_by_class)
+
+ rooms = Room.objects.values('title').annotate(room_entry_count=room_entries_by_room)
+
+ content_block_count = ContentBlock.objects.count()
+
+ context['private_submissions'] = private_submissions
+ context['shared_submissions'] = shared_submissions
+ context['modules'] = modules
+ context['classes'] = classes
+ context['room_classes'] = room_classes
+ context['room_entries_classes'] = room_entries_classes
+ context['rooms'] = rooms
+ context['content_block_count'] = content_block_count
+
return context