add first draft upload
parent
816700638f
commit
e81be01725
|
|
@ -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()
|
||||
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ReportsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'reports'
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# reports/forms.py
|
||||
|
||||
from django import forms
|
||||
|
||||
class CSVUploadForm(forms.Form):
|
||||
csv_file = forms.FileField(label='Upload CSV File')
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<!-- templates/reports/upload.html -->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Upload CSV</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
<div class="container mt-5">
|
||||
<div class="card p-4 shadow-sm">
|
||||
<h2 class="mb-3">Upload CSV File for Evaluation</h2>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger">{{ error }}</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit" class="btn btn-primary">Upload and View Charts</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% if charts %}
|
||||
<div class="mt-5">
|
||||
{% for chart in charts %}
|
||||
<div class="mb-4">
|
||||
<img src="data:image/png;base64,{{ chart }}" class="img-fluid border shadow-sm" />
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# reports/urls.py
|
||||
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('upload/', views.upload_csv, name='upload_csv'),
|
||||
]
|
||||
|
|
@ -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})
|
||||
|
|
@ -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()
|
||||
|
|
@ -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'
|
||||
|
|
@ -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
|
||||
]
|
||||
|
|
@ -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()
|
||||
Loading…
Reference in New Issue