Skip to content

Instantly share code, notes, and snippets.

@andrelp
Created June 29, 2020 12:38
Show Gist options
  • Save andrelp/e9c65d846b9f6c5e1ac3f8b24f2dcc71 to your computer and use it in GitHub Desktop.
Save andrelp/e9c65d846b9f6c5e1ac3f8b24f2dcc71 to your computer and use it in GitHub Desktop.
Notenberechnung
import 'dart:math';
//##############
// - Alle Kurse/Noten so eintragen:
// Note("name", Creditpunkte, Note),
// wobei Note=null wenn unbekannt und Note=1.0,1.3,1.7,... sonst
//
// - Die Bachelorarbeit so eintragen:
// Note("Bachelorarbeit", 15, Note, false, 1.5)
// Das besagt, dass sie eine gewichtung von 1.5 hat und dass die note nicht getrichen werden kann
//
// - Alle Noten aus den Fachbereichen praxis, technik, theorie, mathe, sonstige, wahlpflicht, anwandungsfach jeweils in gleiche Liste
// - !! Keine unbenoteten Fächer: Kein Mentoring, NTW, SPP, PSP
//
// Was wird berechnet?:
// - aus jedem Fachbereich kann max. ein Modul und insgesamt max 30CP gestrichen werden
// - gibt aus derzeiten Schnitt,best- und schlechtmöglichsten und welche Module gestrichen werden sollten!
//##############
List<List<Note>> data = [
//fachbereich praxis
[
Note("Progra", 8, null),
Note("Dsal", 8, null),
Note("SWT", 6, null),
Note("debis", 6, null),
],
//fachbereich technik
[
Note("ti", 6, null),
Note("bus", 6, null),
Note("datkom", 6, null),
],
//fachbereich theorie
[
Note("fosap", 6, null),
Note("buk", 7, null),
Note("malo", 7, null),
],
//fachbereich mathe
[
Note("DS", 6, null),
Note("Afi", 8, null),
Note("LA", 6, null),
Note("Stocha", 6, null),
],
//fachbereich sonstige
[
Note("prosem", 3, null),
Note("Seminar", 5, null),
Note("Bachelor Arbeit", 15, null, false, 1.5),
],
//fachbereich wahlpflicht, hier namen der wahlpflichtfacher eintragn
[
Note("wahlpflicht1", 6, null),
Note("wahlpflicht2", 6, null),
Note("wahlpflicht3", 6, null),
Note("wahlpflicht4", 6, null),
],
//fachbereich anwenungsfach, hier namen der anwandungsfächer mit creditpunkten eintragn
[
Note("Anwenungsfach1", 6, null),
Note("Anwenungsfach2", 6, null),
Note("Anwenungsfach3", 10, null),
]
];
class Note {
bool streichbar;
int cp;
String name;
double note;
double weight;
Note(this.name,this.cp,this.note, [this.streichbar = true, this.weight=1.0]);
bool eq(Note other) => other.name == this.name;
}
Iterable<Note> allNoten(List<List<Note>> data) sync* {
for (var b in data) {
yield* b;
}
}
//erster eintrag: derzeitig, zweiter: bestenfalls, dritter: schlechtestenfalls
List<double> note(List<List<Note>> data, List<Note> exclude) {
double cp = 0;
double weightedNote = 0;
double zusatz = 0;
double weightedNoteZusatzBest = 0;
double weightedNoteZusatzWorst = 0;
for (var n in allNoten(data).where((note) => !exclude.any((exclude) => exclude.eq(note)))) {
if (n.note == null || n.note == 0) {
zusatz += n.cp * n.weight;
weightedNoteZusatzBest += n.cp * 1.0 * n.weight;
weightedNoteZusatzWorst += n.cp * 4.0 * n.weight;
} else {
cp += n.cp * n.weight;
weightedNote += n.cp * n.note * n.weight;
}
}
return [weightedNote/cp, (weightedNote+weightedNoteZusatzBest)/(cp+zusatz), (weightedNote+weightedNoteZusatzWorst)/(cp+zusatz), ];
}
void main() {
List<List<Note>> perms = createPermutations(data);
double bestNote = 6;
double bestNoteBest = 6;
double bestNoteWorst = 6;
List<List<Note>> bestPerms = [];
List<List<Note>> bestPermsBest = [];
List<List<Note>> bestPermsWorst = [];
for (var p in perms) {
if ((p.fold(0, (prev, e) => prev+e.cp)) > 30) continue;
if (p.any((element) => !element.streichbar)) continue;
var n = note(data,p);
if (n[0] == bestNote) {
bestPerms.add(p);
} else if (n[0] < bestNote) {
bestNote = n[0];
bestPerms = List.from([p]);
}
if (n[1] == bestNoteBest) {
bestPermsBest.add(p);
} else if (n[1] < bestNoteBest) {
bestNoteBest = n[1];
bestPermsBest = List.from([p]);
}
if (n[2] == bestNoteWorst) {
bestPermsWorst.add(p);
} else if (n[2] < bestNoteWorst) {
bestNoteWorst = n[2];
bestPermsWorst = List.from([p]);
}
}
var notenOhneStr = note(data, []);
String msg;
if (notenOhneStr[0].isNaN) {
print("\n===============");
print("Noch keine Noten eingetragen!");
} else {
print("\n===============");
print("Aktueller schnitt: ${notenOhneStr[0]}");
print("Aktueller schnitt nach streichen: $bestNote");
msg = "Folgende Noten sollten getrichen werden: ";
msg += bestPerms.reversed.toList().sublist(0,min(3, bestPerms.length)).fold<String>("", (prev, b) => (prev==""?"":prev+"\noder: ") + b.fold<String>("", (prev,n) => (prev==""?"":prev+", ") + n.name));
print(msg);
if (bestPerms.length > 3) print("... ${bestPerms.length - 3} weitere Möglichkeiten");
}
print("\n===============");
print("bestmöglicher schnitt: ${notenOhneStr[1]}");
print("bestmöglicher schnitt nach streichen: $bestNoteBest");
msg = "Folgende Noten sollten getrichen werden: ";
msg += bestPermsBest.reversed.toList().sublist(0,min(3, bestPermsBest.length)).fold<String>("", (prev, b) => (prev==""?"":prev+"\noder: ") + b.fold<String>("", (prev,n) => (prev==""?"":prev+", ") + n.name));
print(msg);
if (bestPermsBest.length > 3) print("... ${bestPermsBest.length - 3} weitere Möglichkeiten");
print("\n===============");
print("schlechtmöglichster schnitt: ${notenOhneStr[2]}");
print("schlechtmöglichster schnitt nach streichen: $bestNoteWorst");
msg = "Folgende Noten sollten getrichen werden: ";
msg += bestPermsWorst.reversed.toList().sublist(0,min(3, bestPermsWorst.length)).fold<String>("", (prev, b) => (prev==""?"":prev+"\noder: ") + b.fold<String>("", (prev,n) => (prev==""?"":prev+", ") + n.name));
print(msg);
if (bestPermsWorst.length > 3) print("... ${bestPermsWorst.length - 3} weitere Möglichkeiten");
}
List<List<Note>> createPermutations(List<List<Note>> data) {
if (data.length == 1) {
List<List<Note>> ret = [[]];
for (var n in data.first) {
ret.add([n]);
}
return ret;
} else {
var rec = createPermutations(data.sublist(1));
List<List<Note>> ret = [];
for (var r in rec) {
ret.add(r);
for (var n in data.first) {
List<Note> erw = List.from(r);
erw.add(n);
ret.add(erw);
}
}
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment