Skip to content

Commit

Permalink
Merge pull request #24 from MCG-App/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
SLH335 authored Dec 5, 2022
2 parents 8f73854 + 3c6b2ce commit 85a6015
Show file tree
Hide file tree
Showing 22 changed files with 384 additions and 171 deletions.
100 changes: 50 additions & 50 deletions assets/data/courses/courses-11.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/data/courses/courses-12.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
{
"title": "MuG12",
"subject": "Mus",
"teacher": "SchaN",
"teacher": "SchbN",
"times": [
["AMo3", "0.41"],
["AFr4", "0.41"],
Expand Down
8 changes: 4 additions & 4 deletions assets/data/teachers.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
"title": "Herr",
"firstname": "Nick",
"lastname": "Schauberg",
"short": "SchaN",
"short": "SchbN",
"subjects": ["Mus", "Ges"],
"email": "nick.schauberg@lk.brandenburg.de"
},
Expand Down Expand Up @@ -485,9 +485,9 @@
"email": "alexander.tillner@lk.brandenburg.de"
},
{
"title": "Herr/Frau",
"firstname": "N.",
"lastname": "Tres.",
"title": "Herr",
"firstname": "Niklas",
"lastname": "Tresch",
"short": "TresN",
"subjects": [],
"email": ""
Expand Down
40 changes: 32 additions & 8 deletions lib/classes/course.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import 'package:mcgapp/classes/grade.dart';
import 'package:mcgapp/classes/room.dart';
import 'package:mcgapp/classes/subject.dart';
import 'package:mcgapp/enums/subject.dart';
import 'package:mcgapp/classes/teacher.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'group.dart';
import '../enums/group.dart';

Map<String, Course> courses = {};
List<Course> userCourses = [];
Expand Down Expand Up @@ -56,7 +56,7 @@ class Course {
List<Grade> courseGrades = [];

for (Grade grade in Grade.grades) {
if (grade.course.title == title) courseGrades.add(grade);
if (grade.course == this) courseGrades.add(grade);
}
courseGrades.sort((a, b) =>
int.parse(DateFormat('yyyyMMdd').format(b.date)).compareTo(int.parse(DateFormat('yyyyMMdd').format(a.date))));
Expand All @@ -65,14 +65,38 @@ class Course {

double get gradeAverage {
if (courseGrades.isEmpty) return -1;
List<int> gradeList = courseGrades.map((e) => e.grade).toList();
Map<int, double> typeAverages = {};

for (int typeId in gradeTypes.keys) {
List<Grade> typeGrades = courseGrades.where((element) => element.type.id == typeId).toList();
if (typeGrades.isNotEmpty) {
int sum = 0;
for (var element in typeGrades) {
sum += element.grade;
}
double average = sum / typeGrades.length;
typeAverages[typeId] = average;
}
}

double average = 0;
for (int typeId in typeAverages.keys) {
average += typeAverages[typeId]! * (typeAverages.values.length > 1 ? gradeTypes[typeId]! : 1);
}
return average;
}

Map<int, double> get gradeTypes {
Map<int, double> gradeTypes = {};

int sum = 0;
for (var element in gradeList) {
sum += element;
if (group!.level > 10) {
gradeTypes[0] = 0.67;
gradeTypes[2] = 0.33;
} else {
gradeTypes[0] = 1;
}

return sum / gradeList.length;
return gradeTypes;
}

Widget get circleAvatar {
Expand Down
22 changes: 12 additions & 10 deletions lib/classes/grade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import 'package:intl/intl.dart';
import 'package:mcgapp/widgets/bottom_sheet.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../enums/grade_type.dart';
import 'course.dart';

enum GradeFormat { format15, format6 }

enum GradeType { test, exam }

class Grade {

static List<Grade> _grades = [];
static final List<int> _gradeEntries = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
static final List<int> _gradeEntriesSekI = [1, 2, 3, 4, 5, 6];
static final List<int> _gradeEntriesSekII = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];

static List<Grade> get grades => _grades;
static List<int> get gradeEntries => _gradeEntries;
static List<int> get gradeEntries {
if (group!.level > 10) return _gradeEntriesSekII;
return _gradeEntriesSekI;
}

static double get totalAverage {
List<Course> coursesWithGrades = userCourses.where((e) => e.gradeAverage != -1).toList();
Expand Down Expand Up @@ -56,8 +58,8 @@ class Grade {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<String> encodedGrades = [];
for (Grade grade in grades) {
encodedGrades
.add('${grade.title}|${grade.course.title}|${grade.grade}|${DateFormat('yyyy-MM-dd').format(grade.date)}');
encodedGrades.add('${grade.title}|${grade.course.title}|${grade.grade}|'
'${DateFormat('yyyy-MM-dd').format(grade.date)}|${grade.type}');
}
prefs.setStringList('grades', encodedGrades);
}
Expand All @@ -74,7 +76,7 @@ class Grade {
format: GradeFormat.format15,
grade: int.parse(gradeParameters[2]),
date: DateTime.parse(gradeParameters[3]),
type: GradeType.test,
type: GradeType.fromName(gradeParameters[4]),
));
}
_grades = decodedGrades;
Expand Down Expand Up @@ -114,7 +116,7 @@ class Grade {
title: Text(DateFormat('EEEE, d. MMMM yyyy', 'de').format(date)),
),
ListTile(
leading: const Icon(Icons.text_fields),
leading: type.icon,
title: Text(type.name),
),
];
Expand Down Expand Up @@ -161,4 +163,4 @@ class Grade {
),
);
}
}
}
46 changes: 0 additions & 46 deletions lib/classes/group.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/classes/teacher.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:mcgapp/classes/subject.dart';
import 'package:mcgapp/enums/subject.dart';

Map<String, Teacher> teachers = {};

Expand Down
37 changes: 37 additions & 0 deletions lib/enums/grade_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';

enum GradeType {
abipruefung('Abiturprüfung', Icon(Icons.book), 4),
aufgabe('Aufgabe', Icon(Icons.task), 0),
klassenarbeit('Klassenarbeit', Icon(Icons.book), 1),
klausur('Klausur', Icon(Icons.book), 2),
leistungskontrolle('Leistungskontrolle', Icon(Icons.directions_run), 0),
mitarbeit('Mitarbeit', Icon(Icons.back_hand), 0),
pruefung('Prüfung', Icon(Icons.book), 3),
test('Test', Icon(Icons.book), 0),
vortrag('Vortrag', Icon(Icons.co_present), 0);

const GradeType(this.name, this.icon, this.id);
final String name;
final Icon icon;
final int id;

static GradeType fromName(String name) {
return GradeType.values.byName(name.replaceAll('GradeType.', ''));
}

static List<GradeType> fromType(int type) {
return GradeType.values.where((element) => element.id == type).toList();
}

static String getTypeName(int type) {
switch (type) {
case 0: return 'Reguläre Noten';
case 1: return 'Klassenarbeiten';
case 2: return 'Klausuren';
case 3: return 'Prüfungen';
case 4: return 'Abiturprüfungen';
}
return 'Ungültiger Typ';
}
}
47 changes: 47 additions & 0 deletions lib/enums/group.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:mcgapp/classes/teacher.dart';

enum Group {

/*class7a('7a', 7, 'MarcH'),
class7b('7b', 7, 'GrubM'),
class7c('7c', 7, 'GärtS'),
class7d('7d', 7, 'UrSoF'),
class7e('7e', 7, 'RaabI'),
class7f('7f', 7, 'RoggA'),
class8a('8a', 8, 'BohsC'),
class8b('8b', 8, 'FoerA'),
class8c('8c', 8, 'RublT'),
class8d('8d', 8, 'TillA'),
class8e('8e', 8, 'SteiC'),
class9a('9a', 9, 'TigöH'),
class9b('9b', 9, 'SchaR'),*/
class9c('9c', 9, 'GöttO'),
/*class9d('9d', 9, 'SpanF'),
class9e('9e', 9, 'WillA'),
class10a('10a', 10, 'PlauS'),
class10b('10b', 10, 'SchbN'),
class10c('10c', 10, 'KrügJ'),
class10d('10d', 10, 'KössA'),
class10e('10e', 10, 'PelcE'),*/
class11_1('11_1', 11, 'HossA'),
class11_2('11_2', 11, 'HabeJ'),
class11_3('11_3', 11, 'KirsN'),
class11_4('11_4', 11, 'WoizP'),
class11_5('11_5', 11, 'SchulC')/*,
class12_1('12_1', 12, 'GutsA'),
class12_2('12_2', 12, 'KiepF'),
class12_3('12_3', 12, 'WoizM'),
class12_4('12_4', 12, 'DornC'),
class12_5('12_5', 12, 'SydoA')*/;

const Group(this.name, this.level, this._teacher);
final String name;
final int level;
final String _teacher;

Teacher get teacher => Teacher.fromShort(_teacher);

static Group fromName(String name) {
return Group.values.firstWhere((e) => e.name == name);
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
}

String get appName => 'MCG-App';
String get appVersion => '0.3.0-alpha.6';
String get appVersion => '0.3.0-beta.3';

ThemeManager themeManager = ThemeManager();

Expand Down
Loading

0 comments on commit 85a6015

Please sign in to comment.