preskupil jsem trochu kod a upravil znamky
This commit is contained in:
parent
12f06c45ff
commit
a633fa6490
@ -1,6 +1,10 @@
|
||||
package xyz.thastertyn;
|
||||
|
||||
import xyz.thastertyn.Display.MainWindow;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
|
||||
import xyz.thastertyn.UserInterface.MainWindow;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
|
@ -1,5 +0,0 @@
|
||||
package xyz.thastertyn.Display.Content;
|
||||
|
||||
public class Jidelna {
|
||||
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
package xyz.thastertyn.Display.Content;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.googlecode.lanterna.TextColor;
|
||||
import com.googlecode.lanterna.graphics.SimpleTheme;
|
||||
import com.googlecode.lanterna.gui2.Direction;
|
||||
import com.googlecode.lanterna.gui2.GridLayout;
|
||||
import com.googlecode.lanterna.gui2.Label;
|
||||
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||
import com.googlecode.lanterna.gui2.Panel;
|
||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||
|
||||
import xyz.thastertyn.Display.Dialogs.OptionsDialog;
|
||||
import xyz.thastertyn.Tuples.Pair;
|
||||
|
||||
public class Znamky extends JecnaContent {
|
||||
|
||||
private Panel mainPanel = new Panel()
|
||||
.setLayoutManager(new GridLayout(3));
|
||||
|
||||
private Label borderLabel = new Label("Znamky");
|
||||
private xyz.thastertyn.Scrape.Znamky znamky = new xyz.thastertyn.Scrape.Znamky();
|
||||
|
||||
private boolean hasStarted = false;
|
||||
|
||||
@Override
|
||||
public void download()
|
||||
{
|
||||
try{
|
||||
znamky.downloadZnamky();
|
||||
|
||||
Panel predmetyPanel = new Panel()
|
||||
.setLayoutManager(new LinearLayout(Direction.VERTICAL))
|
||||
.setLayoutData(GridLayout.createLayoutData(
|
||||
GridLayout.Alignment.BEGINNING,
|
||||
GridLayout.Alignment.BEGINNING,
|
||||
false,
|
||||
false));
|
||||
|
||||
Panel znamkyPanel = new Panel()
|
||||
.setLayoutManager(new LinearLayout(Direction.VERTICAL))
|
||||
.setLayoutData(GridLayout.createLayoutData(
|
||||
GridLayout.Alignment.BEGINNING,
|
||||
GridLayout.Alignment.BEGINNING,
|
||||
false,
|
||||
false));
|
||||
|
||||
Panel vyslednaZnamkaPanel = new Panel().
|
||||
setLayoutManager(new LinearLayout(Direction.VERTICAL))
|
||||
.setLayoutData(GridLayout.createLayoutData(
|
||||
GridLayout.Alignment.END,
|
||||
GridLayout.Alignment.BEGINNING,
|
||||
true,
|
||||
false));
|
||||
|
||||
ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = znamky.getGrades();
|
||||
|
||||
TextColor.RGB vyborny = new TextColor.RGB(85,212,0);
|
||||
TextColor.RGB chvalitebny = new TextColor.RGB(196,224,80);
|
||||
TextColor.RGB dobry = new TextColor.RGB(255,213,42);
|
||||
TextColor.RGB dostatecny = new TextColor.RGB(255,102,0);
|
||||
TextColor.RGB nedostatecny = new TextColor.RGB(255,48,48);
|
||||
|
||||
for(Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>> predmet : grades)
|
||||
{
|
||||
|
||||
Panel jednotliveZnamky = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
|
||||
|
||||
if(predmet.getValue1().getValue0().isEmpty())
|
||||
{
|
||||
jednotliveZnamky.addComponent(new Label(""));
|
||||
}
|
||||
|
||||
for(Pair<Integer, Double> znamka : predmet.getValue1().getValue0())
|
||||
{
|
||||
Label znamkaLabel = new Label(znamka.getValue0() + "");
|
||||
switch(znamka.getValue0())
|
||||
{
|
||||
case -1:
|
||||
znamkaLabel.setText("N");
|
||||
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK));
|
||||
break;
|
||||
case 1:
|
||||
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, vyborny));
|
||||
break;
|
||||
case 2:
|
||||
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, chvalitebny));
|
||||
break;
|
||||
case 3:
|
||||
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, dobry));
|
||||
break;
|
||||
case 4:
|
||||
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, dostatecny));
|
||||
break;
|
||||
case 5:
|
||||
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, nedostatecny));
|
||||
break;
|
||||
}
|
||||
|
||||
jednotliveZnamky.addComponent(znamkaLabel);
|
||||
}
|
||||
|
||||
double prumer = predmet.getValue1().getValue1();
|
||||
|
||||
Label vysl = new Label(String.format("%.2f", prumer));
|
||||
|
||||
if(prumer >= 1 && prumer < 1.5)
|
||||
{
|
||||
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, vyborny));
|
||||
}else if(prumer >= 1.5 && prumer < 2.5)
|
||||
{
|
||||
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, chvalitebny));
|
||||
|
||||
}else if(prumer >= 2.5 && prumer < 3.5)
|
||||
{
|
||||
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, dobry));
|
||||
|
||||
}else if(prumer >= 3.5 && prumer < 4.5)
|
||||
{
|
||||
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, dostatecny));
|
||||
}else if(prumer >= 4.5)
|
||||
{
|
||||
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, nedostatecny));
|
||||
}
|
||||
|
||||
znamkyPanel.addComponent(jednotliveZnamky);
|
||||
predmetyPanel.addComponent(new Label(predmet.getValue0()));
|
||||
vyslednaZnamkaPanel.addComponent(vysl);
|
||||
}
|
||||
|
||||
mainPanel.addComponent(predmetyPanel);
|
||||
mainPanel.addComponent(znamkyPanel);
|
||||
mainPanel.addComponent(vyslednaZnamkaPanel);
|
||||
|
||||
hasStarted = true;
|
||||
}catch(IOException e)
|
||||
{
|
||||
mainPanel.addComponent(new Label("An error has occured"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Panel getPanel()
|
||||
{
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStarted()
|
||||
{
|
||||
return hasStarted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Label getLabel()
|
||||
{
|
||||
return borderLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showOptions(WindowBasedTextGUI textGUI) {
|
||||
OptionsDialog d = new OptionsDialog(znamky.getOptions().getValue0(), znamky.getOptions().getValue1());
|
||||
|
||||
d.showDialog(textGUI);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display.Dialogs;
|
||||
package xyz.thastertyn.Login;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Scrape;
|
||||
package xyz.thastertyn.Login;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
@ -11,6 +11,8 @@ import org.jsoup.Jsoup;
|
||||
import org.jsoup.Connection.Method;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import xyz.thastertyn.Scrape.Downloader;
|
||||
|
||||
public class Login {
|
||||
|
||||
private String Jsessionid = null;
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display;
|
||||
package xyz.thastertyn.Login;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@ -15,14 +15,13 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
|
||||
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
|
||||
|
||||
import xyz.thastertyn.Display.Dialogs.CredentialsInput;
|
||||
import xyz.thastertyn.Tuples.Triplet;
|
||||
|
||||
public class LoginController {
|
||||
|
||||
private WindowBasedTextGUI textGUI;
|
||||
private xyz.thastertyn.Display.Dialogs.CredentialsInput dialog;
|
||||
private xyz.thastertyn.Scrape.Login login = new xyz.thastertyn.Scrape.Login();
|
||||
private xyz.thastertyn.Login.CredentialsInput dialog;
|
||||
private xyz.thastertyn.Login.Login login = new xyz.thastertyn.Login.Login();
|
||||
|
||||
public LoginController(WindowBasedTextGUI textGUI)
|
||||
{
|
@ -1,9 +0,0 @@
|
||||
package xyz.thastertyn.Scrape;
|
||||
|
||||
import xyz.thastertyn.Types.BaseType;
|
||||
|
||||
public abstract class BaseJecnaParser {
|
||||
|
||||
public abstract void download();
|
||||
public abstract BaseType getData();
|
||||
}
|
@ -16,11 +16,11 @@ public class OmluvnyList {
|
||||
|
||||
public void downloadOmluvnyList() throws UnknownHostException, IOException
|
||||
{
|
||||
Document doc = Downloader.download("https://www.spsejecna.cz/absence/student").get();
|
||||
Document omluvnyListDokumentHTML = Downloader.download("https://www.spsejecna.cz/absence/student").get();
|
||||
|
||||
Elements omluv = doc.select("table.absence-list").select("tr");
|
||||
Elements omluvneListy = omluvnyListDokumentHTML.select("table.absence-list").select("tr");
|
||||
|
||||
for(Element e : omluv)
|
||||
for(Element e : omluvneListy)
|
||||
{
|
||||
String date = e.child(0).text();
|
||||
String text = e.child(1).text();
|
||||
|
@ -2,9 +2,11 @@ package xyz.thastertyn.Scrape;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
/**
|
||||
@ -13,8 +15,40 @@ import org.jsoup.select.Elements;
|
||||
public class Rozvrh {
|
||||
|
||||
private String[][] rozvrh = new String[5][10];
|
||||
int pos = 0;
|
||||
|
||||
/**
|
||||
* Stahne rozvrh z www.spsejecna.cz a dale ho zpracuje do formy
|
||||
* se kterou da pracovat
|
||||
* @param Jsessionid ze stranek
|
||||
* @throws UnknownHostException kdyz neni pripojeni k internetu
|
||||
* @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom
|
||||
*/
|
||||
public void downloadRozvrh() throws UnknownHostException, IOException
|
||||
{
|
||||
Document rozvrhDokumentHTML = Downloader.download("https://www.spsejecna.cz/timetable/class").get();
|
||||
|
||||
Elements[] radkyRozvrhuHTML = rozvrhDokumentHTML
|
||||
.select("table.timetable")
|
||||
.select("tr")
|
||||
.stream()
|
||||
.map(Element::children)
|
||||
.toArray(Elements[]::new);
|
||||
|
||||
for(int i = 1; i < 6; i++)
|
||||
{
|
||||
for(int j = 1; j < 11; j++)
|
||||
{
|
||||
String predmet = radkyRozvrhuHTML[i].get(j).select("span.subject").text();
|
||||
|
||||
// Predmety jako CEL jsou trikrat, staci ale jen jednou
|
||||
String[] split = predmet.split(" ");
|
||||
HashSet<String> set = new HashSet<>(Arrays.asList(split));
|
||||
String pr = String.join("/", set);
|
||||
|
||||
rozvrh[i-1][j-1] = pr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPredmet(String pr, int d, int i)
|
||||
{
|
||||
@ -42,61 +76,4 @@ public class Rozvrh {
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stahne rozvrh z www.spsejecna.cz a dale ho zpracuje do formy
|
||||
* se kterou da pracovat
|
||||
* @param Jsessionid ze stranek
|
||||
* @throws UnknownHostException kdyz neni pripojeni k internetu
|
||||
* @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom
|
||||
*/
|
||||
public void downloadRozvrh() throws UnknownHostException, IOException
|
||||
{
|
||||
Document rozvrhDoc = Downloader.download("https://www.spsejecna.cz" + "/timetable/class").get();
|
||||
|
||||
Elements rozvrhTable = rozvrhDoc.select("table.timetable").select("tr");
|
||||
Elements[] rozvrhDny = new Elements[rozvrhTable.size()];
|
||||
|
||||
for(int i = 0; i < rozvrhTable.size(); i++)
|
||||
{
|
||||
rozvrhDny[i] = rozvrhTable.get(i).children();
|
||||
}
|
||||
|
||||
for(int i = 1; i < 6; i++)
|
||||
{
|
||||
for(int j = 1; j < 11; j++)
|
||||
{
|
||||
String predmet = rozvrhDny[i].get(j).select("span.subject").text().replaceAll(" ", "/");
|
||||
|
||||
// Predmety jako CEL jsou trikrat, staci ale jen jednou
|
||||
HashSet<String> set = new HashSet<>();
|
||||
String[] split = predmet.split("/");
|
||||
|
||||
for(String s : split)
|
||||
{
|
||||
set.add(s);
|
||||
}
|
||||
|
||||
String pr = "";
|
||||
|
||||
if(set.size() > 1)
|
||||
{
|
||||
for(String s : set)
|
||||
{
|
||||
pr += s + "/";
|
||||
}
|
||||
pr = pr.substring(0, pr.length() - 1);
|
||||
}else{
|
||||
for(String s : set) { pr = s; break; }
|
||||
}
|
||||
|
||||
if(pr.isBlank())
|
||||
{
|
||||
pr = "-";
|
||||
}
|
||||
|
||||
rozvrh[i-1][j-1] = pr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package xyz.thastertyn.Scrape;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
@ -13,133 +12,90 @@ import org.jsoup.select.Elements;
|
||||
import xyz.thastertyn.Tuples.Pair;
|
||||
import xyz.thastertyn.Types.Option;
|
||||
import xyz.thastertyn.Types.Options;
|
||||
import xyz.thastertyn.Types.Predmet;
|
||||
import xyz.thastertyn.Types.Znamka;
|
||||
|
||||
public class Znamky {
|
||||
|
||||
private boolean wasDownloaded;
|
||||
|
||||
// schoolYear, schoolYearId
|
||||
private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>();
|
||||
private ArrayList<Predmet> predmety = new ArrayList<>();
|
||||
|
||||
// Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
|
||||
// int znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
|
||||
private Options schoolYearOptions = new Options("Skolni R.");
|
||||
private Options schoolHalfYearOptions = new Options("Pololeti");
|
||||
|
||||
public void downloadZnamky(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException
|
||||
{
|
||||
//String url = String.format("https://www.spsejecna.cz/score/student?schoolYearId=%d&schoolYearHalfId=%d", schoolYearId, schoolYearHalfId);
|
||||
Document znamkyDoc = Downloader.download("https://www.spsejecna.cz/score/student").get();
|
||||
Document znamkyDokumentHTML = Downloader.download("https://www.spsejecna.cz/score/student").get();
|
||||
|
||||
Elements rows = znamkyDoc.select("table.score").select("tr");
|
||||
// Predmety ulozene v <tr>
|
||||
Elements[] radkyPredmetuHTML = znamkyDokumentHTML
|
||||
.select("table.score")
|
||||
.select("tr")
|
||||
.stream()
|
||||
.map(Element::children)
|
||||
.toArray(Elements[]::new);
|
||||
|
||||
Elements[] rows_split = new Elements[rows.size()];
|
||||
int subjectIndex = 0;
|
||||
|
||||
for (int i = 0; i < rows.size(); i++)
|
||||
for(int i = 1; i < radkyPredmetuHTML.length; i++)
|
||||
{
|
||||
rows_split[i] = rows.get(i).children();
|
||||
}
|
||||
String plnyNazevPredmetu = radkyPredmetuHTML[i].get(0).text();
|
||||
|
||||
int subj = 0;
|
||||
String jmenoPredmetu = Pattern
|
||||
.compile("\\((.*?)\\)")
|
||||
.matcher(plnyNazevPredmetu)
|
||||
.results()
|
||||
.findFirst()
|
||||
.map(m -> m.group(1))
|
||||
.orElse(plnyNazevPredmetu);
|
||||
|
||||
for(int i = 1; i < rows_split.length; i++)
|
||||
{
|
||||
String predmetFull = rows_split[i].get(0).text();
|
||||
predmety.add(new Predmet(jmenoPredmetu));
|
||||
|
||||
Matcher matcher = Pattern.compile("\\((.*)\\)").matcher(predmetFull);
|
||||
|
||||
String predmet = matcher.find() ? matcher.group(1) : predmetFull;
|
||||
addSubject(predmet);
|
||||
|
||||
for(Element znamkaElement : rows_split[i].get(1).select("a.score"))
|
||||
for(Element znamkaElement : radkyPredmetuHTML[i].get(1).select("a.score"))
|
||||
{
|
||||
if(znamkaElement == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
String zn = znamkaElement.select("span.value").text();
|
||||
int znamka;
|
||||
if(zn.toLowerCase().equals("n") || zn.toLowerCase().equals("u"))
|
||||
{
|
||||
znamka = -1;
|
||||
}else{
|
||||
znamka = Integer.parseInt(znamkaElement.select("span.value").text());
|
||||
}
|
||||
boolean jeMala = false;
|
||||
|
||||
String textZnamky = znamkaElement.select("span.value").text();
|
||||
|
||||
znamka = textZnamky.matches("\\d") ?
|
||||
Integer.parseInt(textZnamky) :
|
||||
-1; // Nejspis se jedna o N (Nehodnocen)
|
||||
|
||||
// Mala znamka se bude pocitat jako polovicni vaha
|
||||
if(znamkaElement.hasClass("scoreSmall"))
|
||||
{
|
||||
addGrade(subj, predmet, znamka, 0.5);
|
||||
}else{
|
||||
addGrade(subj, predmet, znamka, 1);
|
||||
}
|
||||
jeMala = znamkaElement.hasClass("scoreSmall");
|
||||
|
||||
predmety.get(subjectIndex).addZnamka(new Znamka(znamka, jeMala, textZnamky));
|
||||
}
|
||||
|
||||
grades.get(subj).getValue1().setValue1(getAverage(grades.get(subj).getValue1().getValue0()));
|
||||
subj++;
|
||||
subjectIndex++;
|
||||
}
|
||||
|
||||
Element optionsPanel = znamkyDoc.selectFirst("form.listConfigure");
|
||||
Element optionsPanel = znamkyDokumentHTML.selectFirst("form.listConfigure");
|
||||
|
||||
Elements schoolYear = optionsPanel.select("select[id=schoolYearId]").select("option");
|
||||
Elements schoolYearId = optionsPanel.select("select[id=schoolYearHalfId]").select("option");
|
||||
Elements skolniRoky = optionsPanel.select("select[id=schoolYearId]").select("option");
|
||||
Elements pololeti = optionsPanel.select("select[id=schoolYearHalfId]").select("option");
|
||||
|
||||
for(Element e : schoolYear)
|
||||
for(Element e : skolniRoky)
|
||||
{
|
||||
this.schoolYearOptions.addOption(new Option(e.text(), e.attr("value")));
|
||||
schoolYearOptions.addOption(new Option(e.text(), e.attr("value")));
|
||||
}
|
||||
|
||||
for(Element e : schoolYearId)
|
||||
for(Element e : pololeti)
|
||||
{
|
||||
this.schoolHalfYearOptions.addOption(new Option(e.text(), e.attr("value")));
|
||||
schoolHalfYearOptions.addOption(new Option(e.text(), e.attr("value")));
|
||||
}
|
||||
|
||||
wasDownloaded = true;
|
||||
}
|
||||
|
||||
private void addGrade(int index, String subject, int grade, double weight)
|
||||
{
|
||||
Pair<Integer, Double> znamka = new Pair<>(grade, weight);
|
||||
|
||||
grades.get(index).getValue1().getValue0().add(znamka);
|
||||
}
|
||||
|
||||
private void addSubject(String subject)
|
||||
{
|
||||
Pair<ArrayList<Pair<Integer, Double>>, Double> p = new Pair<>(new ArrayList<Pair<Integer, Double>>(), 0.0);
|
||||
|
||||
grades.add(new Pair<>(subject, p));
|
||||
}
|
||||
|
||||
private double getAverage(ArrayList<Pair<Integer, Double>> a)
|
||||
{
|
||||
try{
|
||||
double divident = 0;
|
||||
double divisor = 0;
|
||||
for(Pair<Integer, Double> p : a)
|
||||
{
|
||||
if(p.getValue0() == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
divident += p.getValue0() * p.getValue1();
|
||||
divisor += p.getValue1();
|
||||
}
|
||||
|
||||
double prumer = (double) divident / divisor;
|
||||
return (double) Math.round(prumer * 100) / 100;
|
||||
|
||||
}catch(ArithmeticException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> getGrades()
|
||||
public ArrayList<Predmet> getPredmety()
|
||||
{
|
||||
return grades;
|
||||
return predmety;
|
||||
}
|
||||
|
||||
public Pair<Options, Options> getOptions()
|
||||
@ -150,17 +106,8 @@ public class Znamky {
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(wasDownloaded)
|
||||
{
|
||||
String s = "";
|
||||
|
||||
for(Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>> p : grades)
|
||||
{
|
||||
s += p.getValue0() + " | " + p.getValue1().getValue0().toString() + " { " + p.getValue1().getValue1() + " } ";
|
||||
}
|
||||
return s;
|
||||
}else{
|
||||
return "Nothing was downloaded";
|
||||
}
|
||||
return (wasDownloaded) ?
|
||||
"All up and ready for use" :
|
||||
"Nothing downloaded yet";
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package xyz.thastertyn.Types;
|
||||
|
||||
public abstract class BaseType {
|
||||
|
||||
}
|
56
src/main/java/xyz/thastertyn/Types/Predmet.java
Normal file
56
src/main/java/xyz/thastertyn/Types/Predmet.java
Normal file
@ -0,0 +1,56 @@
|
||||
package xyz.thastertyn.Types;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Predmet {
|
||||
|
||||
private ArrayList<Znamka> znamky = new ArrayList<>();
|
||||
private String jmenoPredmetu = "";
|
||||
|
||||
private int vyslednaZnamka = 0;
|
||||
|
||||
public Predmet(String jmenoPredmetu)
|
||||
{
|
||||
this.jmenoPredmetu = jmenoPredmetu;
|
||||
}
|
||||
|
||||
public void addZnamka(Znamka novaZnamka)
|
||||
{
|
||||
znamky.add(novaZnamka);
|
||||
}
|
||||
|
||||
public double getPrumer()
|
||||
{
|
||||
if(vyslednaZnamka != 0)
|
||||
{
|
||||
return vyslednaZnamka;
|
||||
}
|
||||
|
||||
if(znamky.isEmpty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int celkem = znamky
|
||||
.stream()
|
||||
.mapToInt((z) -> z.getZnamka() * z.getVaha())
|
||||
.sum();
|
||||
|
||||
int vahy = znamky
|
||||
.stream()
|
||||
.mapToInt((z) -> z.getVaha())
|
||||
.sum();
|
||||
|
||||
return (double) celkem / vahy;
|
||||
}
|
||||
|
||||
public String getJmenoPredmetu()
|
||||
{
|
||||
return jmenoPredmetu;
|
||||
}
|
||||
|
||||
public ArrayList<Znamka> getZnamky()
|
||||
{
|
||||
return znamky;
|
||||
}
|
||||
}
|
@ -3,17 +3,28 @@ package xyz.thastertyn.Types;
|
||||
public class Znamka {
|
||||
|
||||
private int znamka;
|
||||
private boolean malaZnamka;
|
||||
private String text;
|
||||
private String datum;
|
||||
private String znamkaJakoText;
|
||||
private int vaha;
|
||||
|
||||
|
||||
public Znamka(int znamka, boolean malaZnamka, String text, String datum)
|
||||
public Znamka(int znamka, boolean malaZnamka, String znamkaJakoText/*, String text, String datum*/)
|
||||
{
|
||||
this.znamka = znamka;
|
||||
this.malaZnamka = malaZnamka;
|
||||
this.datum = datum;
|
||||
this.text = text;
|
||||
this.vaha = (malaZnamka) ? 1 : 2;
|
||||
this.znamkaJakoText = znamkaJakoText;
|
||||
}
|
||||
|
||||
}
|
||||
public int getZnamka()
|
||||
{
|
||||
return znamka;
|
||||
}
|
||||
|
||||
public int getVaha()
|
||||
{
|
||||
return vaha;
|
||||
}
|
||||
|
||||
public String getText()
|
||||
{
|
||||
return znamkaJakoText;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display.Content;
|
||||
package xyz.thastertyn.UserInterface.Content;
|
||||
|
||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
|
@ -0,0 +1,5 @@
|
||||
package xyz.thastertyn.UserInterface.Content;
|
||||
|
||||
public class Jidelna {
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display.Content;
|
||||
package xyz.thastertyn.UserInterface.Content;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display.Content;
|
||||
package xyz.thastertyn.UserInterface.Content;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display.Content;
|
||||
package xyz.thastertyn.UserInterface.Content;
|
||||
|
||||
|
||||
import java.io.IOException;
|
144
src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java
Normal file
144
src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java
Normal file
@ -0,0 +1,144 @@
|
||||
package xyz.thastertyn.UserInterface.Content;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.googlecode.lanterna.TextColor;
|
||||
import com.googlecode.lanterna.TextColor.ANSI;
|
||||
import com.googlecode.lanterna.graphics.SimpleTheme;
|
||||
import com.googlecode.lanterna.gui2.Direction;
|
||||
import com.googlecode.lanterna.gui2.GridLayout;
|
||||
import com.googlecode.lanterna.gui2.Label;
|
||||
import com.googlecode.lanterna.gui2.LayoutData;
|
||||
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||
import com.googlecode.lanterna.gui2.Panel;
|
||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||
|
||||
import xyz.thastertyn.Types.Predmet;
|
||||
import xyz.thastertyn.Types.Znamka;
|
||||
import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog;
|
||||
|
||||
public class Znamky extends JecnaContent {
|
||||
|
||||
private final TextColor.RGB VYBORNY = new TextColor.RGB(85,212,0);
|
||||
private final TextColor.RGB CHVALITEBNY = new TextColor.RGB(196,224,80);
|
||||
private final TextColor.RGB DOBRY = new TextColor.RGB(255,213,42);
|
||||
private final TextColor.RGB DOSTATECNY = new TextColor.RGB(255,102,0);
|
||||
private final TextColor.RGB NEDOSTATECNY = new TextColor.RGB(255,48,48);
|
||||
private final TextColor.RGB NEHODNOCEN = new TextColor.RGB(0,0,0);
|
||||
|
||||
private final LayoutData ALIGN_LEFT = GridLayout.createLayoutData(
|
||||
GridLayout.Alignment.BEGINNING,
|
||||
GridLayout.Alignment.BEGINNING,
|
||||
false,
|
||||
false);
|
||||
|
||||
private final LayoutData ALIGN_RIGHT = GridLayout.createLayoutData(
|
||||
GridLayout.Alignment.END,
|
||||
GridLayout.Alignment.BEGINNING,
|
||||
true,
|
||||
false);
|
||||
|
||||
private Panel mainPanel = new Panel()
|
||||
.setLayoutManager(new GridLayout(3));
|
||||
|
||||
private Label borderLabel = new Label("Znamky");
|
||||
private xyz.thastertyn.Scrape.Znamky znamky = new xyz.thastertyn.Scrape.Znamky();
|
||||
|
||||
private boolean hasStarted = false;
|
||||
|
||||
@Override
|
||||
public void download()
|
||||
{
|
||||
try{
|
||||
znamky.downloadZnamky();
|
||||
|
||||
ArrayList<Predmet> predmety = znamky.getPredmety();
|
||||
|
||||
HashMap<Integer, SimpleTheme> barvy = new HashMap<>();
|
||||
barvy.put(1, new SimpleTheme(ANSI.BLACK, VYBORNY));
|
||||
barvy.put(2, new SimpleTheme(ANSI.BLACK, CHVALITEBNY));
|
||||
barvy.put(3, new SimpleTheme(ANSI.BLACK, DOBRY));
|
||||
barvy.put(4, new SimpleTheme(ANSI.BLACK, DOSTATECNY));
|
||||
barvy.put(5, new SimpleTheme(ANSI.BLACK, NEDOSTATECNY));
|
||||
barvy.put(-1, new SimpleTheme(ANSI.WHITE, NEHODNOCEN));
|
||||
|
||||
// Sloupec pro jmena predmetu
|
||||
Panel jmemaPredmetu = new Panel()
|
||||
.setLayoutManager(new LinearLayout(Direction.VERTICAL))
|
||||
.setLayoutData(ALIGN_LEFT)
|
||||
.addTo(mainPanel);
|
||||
|
||||
// Sloupec pro znamky z predmetu
|
||||
Panel znamky = new Panel()
|
||||
.setLayoutManager(new LinearLayout(Direction.VERTICAL))
|
||||
.setLayoutData(ALIGN_LEFT)
|
||||
.addTo(mainPanel);
|
||||
|
||||
// Sloupec pro vyslednou znamku
|
||||
Panel vysledneZnamky = new Panel()
|
||||
.setLayoutManager(new LinearLayout(Direction.VERTICAL))
|
||||
.setLayoutData(ALIGN_RIGHT)
|
||||
.addTo(mainPanel);
|
||||
|
||||
for(Predmet predmet : predmety)
|
||||
{
|
||||
Panel jednotliveZnamky = new Panel()
|
||||
.setLayoutManager(new LinearLayout(Direction.HORIZONTAL))
|
||||
.addTo(znamky);
|
||||
|
||||
if(predmet.getZnamky().isEmpty())
|
||||
{
|
||||
jednotliveZnamky.addComponent(new Label(""));
|
||||
}
|
||||
|
||||
for(Znamka znamka : predmet.getZnamky())
|
||||
{
|
||||
Label znamkaLabel = new Label(znamka.getText());
|
||||
znamkaLabel.setTheme(barvy.get(znamka.getZnamka()));
|
||||
jednotliveZnamky.addComponent(znamkaLabel);
|
||||
}
|
||||
|
||||
double prumer = predmet.getPrumer();
|
||||
|
||||
Label vysl = new Label(String.format("%.2f", prumer));
|
||||
|
||||
vysl.setTheme(barvy.get((int) Math.round(prumer)));
|
||||
|
||||
jmemaPredmetu.addComponent(new Label(predmet.getJmenoPredmetu()));
|
||||
vysledneZnamky.addComponent(vysl);
|
||||
}
|
||||
|
||||
hasStarted = true;
|
||||
}catch(IOException e)
|
||||
{
|
||||
mainPanel.addComponent(new Label("An error has occured"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Panel getPanel()
|
||||
{
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStarted()
|
||||
{
|
||||
return hasStarted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Label getLabel()
|
||||
{
|
||||
return borderLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showOptions(WindowBasedTextGUI textGUI) {
|
||||
OptionsDialog d = new OptionsDialog(znamky.getOptions().getValue0(), znamky.getOptions().getValue1());
|
||||
|
||||
d.showDialog(textGUI);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display.Dialogs;
|
||||
package xyz.thastertyn.UserInterface.Dialogs;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display;
|
||||
package xyz.thastertyn.UserInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@ -18,6 +18,8 @@ import com.googlecode.lanterna.screen.TerminalScreen;
|
||||
import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
|
||||
import com.googlecode.lanterna.terminal.Terminal;
|
||||
|
||||
import xyz.thastertyn.Login.LoginController;
|
||||
|
||||
public class MainWindow {
|
||||
|
||||
private Terminal terminal;
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.Display;
|
||||
package xyz.thastertyn.UserInterface;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@ -17,11 +17,11 @@ import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
|
||||
import com.googlecode.lanterna.input.KeyStroke;
|
||||
import com.googlecode.lanterna.input.KeyType;
|
||||
|
||||
import xyz.thastertyn.Display.Content.JecnaContent;
|
||||
import xyz.thastertyn.Display.Content.OmluvnyList;
|
||||
import xyz.thastertyn.Display.Content.Rozvrh;
|
||||
import xyz.thastertyn.Display.Content.Sdeleni;
|
||||
import xyz.thastertyn.Display.Content.Znamky;
|
||||
import xyz.thastertyn.UserInterface.Content.JecnaContent;
|
||||
import xyz.thastertyn.UserInterface.Content.OmluvnyList;
|
||||
import xyz.thastertyn.UserInterface.Content.Rozvrh;
|
||||
import xyz.thastertyn.UserInterface.Content.Sdeleni;
|
||||
import xyz.thastertyn.UserInterface.Content.Znamky;
|
||||
|
||||
public class WindowSwitchListener implements WindowListener {
|
||||
|
Loading…
x
Reference in New Issue
Block a user