From e81be01725c0822c31e88046513129b4f41a8875 Mon Sep 17 00:00:00 2001 From: Jacqueline Franssen Date: Mon, 19 May 2025 15:16:37 +0200 Subject: [PATCH] add first draft upload --- smart_course_evaluation/manage.py | 22 ++++ .../reports/Kursevaluation_12052025.csv | 21 +++ smart_course_evaluation/reports/__init__.py | 0 smart_course_evaluation/reports/admin.py | 3 + smart_course_evaluation/reports/apps.py | 6 + smart_course_evaluation/reports/forms.py | 6 + .../reports/migrations/__init__.py | 0 smart_course_evaluation/reports/models.py | 3 + .../reports/templates/reports/upload.html | 37 ++++++ smart_course_evaluation/reports/tests.py | 3 + smart_course_evaluation/reports/urls.py | 8 ++ smart_course_evaluation/reports/views.py | 96 ++++++++++++++ .../smart_course_evaluation/__init__.py | 0 .../smart_course_evaluation/asgi.py | 16 +++ .../smart_course_evaluation/settings.py | 123 ++++++++++++++++++ .../smart_course_evaluation/urls.py | 7 + .../smart_course_evaluation/wsgi.py | 16 +++ 17 files changed, 367 insertions(+) create mode 100755 smart_course_evaluation/manage.py create mode 100644 smart_course_evaluation/reports/Kursevaluation_12052025.csv create mode 100644 smart_course_evaluation/reports/__init__.py create mode 100644 smart_course_evaluation/reports/admin.py create mode 100644 smart_course_evaluation/reports/apps.py create mode 100644 smart_course_evaluation/reports/forms.py create mode 100644 smart_course_evaluation/reports/migrations/__init__.py create mode 100644 smart_course_evaluation/reports/models.py create mode 100644 smart_course_evaluation/reports/templates/reports/upload.html create mode 100644 smart_course_evaluation/reports/tests.py create mode 100644 smart_course_evaluation/reports/urls.py create mode 100644 smart_course_evaluation/reports/views.py create mode 100644 smart_course_evaluation/smart_course_evaluation/__init__.py create mode 100644 smart_course_evaluation/smart_course_evaluation/asgi.py create mode 100644 smart_course_evaluation/smart_course_evaluation/settings.py create mode 100644 smart_course_evaluation/smart_course_evaluation/urls.py create mode 100644 smart_course_evaluation/smart_course_evaluation/wsgi.py diff --git a/smart_course_evaluation/manage.py b/smart_course_evaluation/manage.py new file mode 100755 index 0000000..6be589a --- /dev/null +++ b/smart_course_evaluation/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'smart_course_evaluation.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/smart_course_evaluation/reports/Kursevaluation_12052025.csv b/smart_course_evaluation/reports/Kursevaluation_12052025.csv new file mode 100644 index 0000000..cde68e7 --- /dev/null +++ b/smart_course_evaluation/reports/Kursevaluation_12052025.csv @@ -0,0 +1,21 @@ +"Antwort Nr.",Fakultät,"Studiengang (Bitte als komplette Bezeichnung, bspw. Medizintechnik - Master oder Elektromobilität und autonomes Fahren - Bachelor)",Semester,Geschlecht,"Wie hast du von diesem Kurs erfahren?" +1,"B (Biotechnologie)","Biotechnologie - Bachelor",6,Weiblich,"Career Center" +2,"N (Informationstechnik)",Master,1,Weiblich,Mail +3,"N (Informationstechnik)",Informationstechnik/Elektronik,1,Männlich,Mail +4,"M (Maschinenbau)",Maschinenbau,4,Männlich,"Career Center" +5,"B (Biotechnologie)","Biotechnologie- Bachelor",6,Weiblich,"Career Center" +6,"I (Informatik)",Informatik,5,Weiblich,Empfehlung +7,"M (Maschinenbau)","Maschinenbau Bachelor",4,Männlich,Empfehlung +8,"B (Biotechnologie)","Biologische Chemie",4,Männlich,"Career Center" +9,"B (Biotechnologie)",Biotechnologie,4,Männlich,"Career Center" +10,"B (Biotechnologie)","Master Biotechnology Renewable Resources and Bioprocess Technology",1,Weiblich,Mail +11,"M (Maschinenbau)","Maschinenbau - Bachelor",4,Männlich,"Career Center" +12,"B (Biotechnologie)","B.Sc. Biotechnologie",8,Weiblich,"Career Center" +13,"B (Biotechnologie)","Biotechnology Biomedical Science and Technology Master",5,Weiblich,"Career Center" +14,"I (Informatik)","Cybersecurity - Bachelor",2,Männlich,Mail +15,"E (Elektrotechnik)","Automatizierungstechnik - Bachelor",10,Männlich,Mail +16,"B (Biotechnologie)","Biotechnology - Biomedical Science and Technologies",3,Weiblich,"Mail Social Media" +17,"M (Maschinenbau)","Maschinenbau - Bachelor",4,Weiblich,"Career Center" +18,"I (Informatik)","Unternehmens und wirtschaftsinformatik",6,Männlich,"Mail MARS Webseite" +19,"B (Biotechnologie)","Biologische Chemie - Bachelor",7,Weiblich,Mail +20,"M (Maschinenbau)","Bachelor Maschinenbau klassik",10,Männlich,Mail diff --git a/smart_course_evaluation/reports/__init__.py b/smart_course_evaluation/reports/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/smart_course_evaluation/reports/admin.py b/smart_course_evaluation/reports/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/smart_course_evaluation/reports/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/smart_course_evaluation/reports/apps.py b/smart_course_evaluation/reports/apps.py new file mode 100644 index 0000000..cb62b04 --- /dev/null +++ b/smart_course_evaluation/reports/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ReportsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'reports' diff --git a/smart_course_evaluation/reports/forms.py b/smart_course_evaluation/reports/forms.py new file mode 100644 index 0000000..31d0ae1 --- /dev/null +++ b/smart_course_evaluation/reports/forms.py @@ -0,0 +1,6 @@ +# reports/forms.py + +from django import forms + +class CSVUploadForm(forms.Form): + csv_file = forms.FileField(label='Upload CSV File') diff --git a/smart_course_evaluation/reports/migrations/__init__.py b/smart_course_evaluation/reports/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/smart_course_evaluation/reports/models.py b/smart_course_evaluation/reports/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/smart_course_evaluation/reports/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/smart_course_evaluation/reports/templates/reports/upload.html b/smart_course_evaluation/reports/templates/reports/upload.html new file mode 100644 index 0000000..bf877e0 --- /dev/null +++ b/smart_course_evaluation/reports/templates/reports/upload.html @@ -0,0 +1,37 @@ + + + + + + + Upload CSV + + + +
+
+

Upload CSV File for Evaluation

+ + {% if error %} +
{{ error }}
+ {% endif %} + +
+ {% csrf_token %} + {{ form.as_p }} + +
+
+ + {% if charts %} +
+ {% for chart in charts %} +
+ +
+ {% endfor %} +
+ {% endif %} +
+ + diff --git a/smart_course_evaluation/reports/tests.py b/smart_course_evaluation/reports/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/smart_course_evaluation/reports/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/smart_course_evaluation/reports/urls.py b/smart_course_evaluation/reports/urls.py new file mode 100644 index 0000000..9905bf4 --- /dev/null +++ b/smart_course_evaluation/reports/urls.py @@ -0,0 +1,8 @@ +# reports/urls.py + +from django.urls import path +from . import views + +urlpatterns = [ + path('upload/', views.upload_csv, name='upload_csv'), +] diff --git a/smart_course_evaluation/reports/views.py b/smart_course_evaluation/reports/views.py new file mode 100644 index 0000000..c31624b --- /dev/null +++ b/smart_course_evaluation/reports/views.py @@ -0,0 +1,96 @@ +import pandas as pd +import matplotlib.pyplot as plt +import seaborn as sns +from django.shortcuts import render +from .forms import CSVUploadForm +import io +import base64 + +def get_plot_image(): + buffer = io.BytesIO() + plt.savefig(buffer, format='png', bbox_inches='tight') + buffer.seek(0) + image_png = buffer.getvalue() + buffer.close() + return base64.b64encode(image_png).decode('utf-8') + +def upload_csv(request): + charts = [] + if request.method == "POST" and request.FILES.get("csv_file"): + form = CSVUploadForm(request.POST, request.FILES) + if form.is_valid(): + csv_file = request.FILES["csv_file"] + df = pd.read_csv(csv_file) + df.columns = df.columns.str.strip() # Remove any spaces in headers + + # Validate required columns + required_columns = ['Semester', 'Geschlecht', 'Fakultät', 'Wie hast du von diesem Kurs erfahren?'] + missing = [col for col in required_columns if col not in df.columns] + if missing: + print('test') + return render(request, 'reports/upload.html', { + 'form': form, + 'error': f'Missing required columns: {", ".join(missing)}' + }) + + sns.set_theme(style="whitegrid") + + # 1. Semester Distribution + semester_counts = df['Semester'].value_counts().sort_index() + plt.figure(figsize=(8, 4)) + sns.lineplot(x=semester_counts.index, y=semester_counts.values, marker="o") + plt.title("Semester Distribution") + plt.xlabel("Semester") + plt.ylabel("Number of Students") + charts.append(get_plot_image()) + plt.close() + + # 2. Gender Distribution + gender_counts = df['Geschlecht'].value_counts() + plt.figure(figsize=(6, 4)) + ax = sns.barplot(x=gender_counts.index, y=gender_counts.values, palette="pastel", hue=gender_counts.index, legend=False) + for i, v in enumerate(gender_counts.values): + ax.text(i, v + 0.2, str(v), color='black', ha='center', fontweight='bold') + plt.title("Gender Distribution") + plt.xlabel("Gender") + plt.ylabel("Number of Students") + charts.append(get_plot_image()) + plt.close() + + # 3. Faculty Distribution + df['Fakultät'] = df['Fakultät'].replace({ + 'B (Biotechnologie)': 'B', + 'N (Informationstechnik)': 'N', + 'M (Maschinenbau)': 'M', + 'I (Informatik)': 'I', + 'E (Elektrotechnik)': 'E', + }) + faculty_counts = df['Fakultät'].value_counts() + plt.figure(figsize=(6, 4)) + ax = sns.barplot(x=faculty_counts.index, y=faculty_counts.values, palette="muted", hue=faculty_counts.index, legend=False) + for i, v in enumerate(faculty_counts.values): + ax.text(i, v + 0.2, str(v), color='black', ha='center', fontweight='bold') + plt.title("Faculty Distribution") + plt.xlabel("Faculty") + plt.ylabel("Number of Students") + charts.append(get_plot_image()) + plt.close() + print('test2') + + # 4. Course Discovery (Pie Chart) + course_source_counts = df['Wie hast du von diesem Kurs erfahren?'].value_counts() + plt.figure(figsize=(6, 6)) + plt.pie(course_source_counts, labels=course_source_counts.index, autopct='%1.1f%%', startangle=140) + plt.title("How Did Students Hear About the Course?") + charts.append(get_plot_image()) + plt.close() + + return render(request, 'reports/upload.html', { + 'form': form, + 'charts': charts + }) + + else: + form = CSVUploadForm() + + return render(request, 'reports/upload.html', {'form': form}) diff --git a/smart_course_evaluation/smart_course_evaluation/__init__.py b/smart_course_evaluation/smart_course_evaluation/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/smart_course_evaluation/smart_course_evaluation/asgi.py b/smart_course_evaluation/smart_course_evaluation/asgi.py new file mode 100644 index 0000000..1ef1379 --- /dev/null +++ b/smart_course_evaluation/smart_course_evaluation/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for smart_course_evaluation project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'smart_course_evaluation.settings') + +application = get_asgi_application() diff --git a/smart_course_evaluation/smart_course_evaluation/settings.py b/smart_course_evaluation/smart_course_evaluation/settings.py new file mode 100644 index 0000000..c2871d1 --- /dev/null +++ b/smart_course_evaluation/smart_course_evaluation/settings.py @@ -0,0 +1,123 @@ +""" +Django settings for smart_course_evaluation project. + +Generated by 'django-admin startproject' using Django 5.2.1. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-mhih-=1a=w6xyr7vs__' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'reports' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'smart_course_evaluation.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'smart_course_evaluation.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/smart_course_evaluation/smart_course_evaluation/urls.py b/smart_course_evaluation/smart_course_evaluation/urls.py new file mode 100644 index 0000000..313eb1d --- /dev/null +++ b/smart_course_evaluation/smart_course_evaluation/urls.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('reports/', include('reports.urls')), # include app URLs +] diff --git a/smart_course_evaluation/smart_course_evaluation/wsgi.py b/smart_course_evaluation/smart_course_evaluation/wsgi.py new file mode 100644 index 0000000..45f8b23 --- /dev/null +++ b/smart_course_evaluation/smart_course_evaluation/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for smart_course_evaluation project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'smart_course_evaluation.settings') + +application = get_wsgi_application()