Fixed average, added rgb for grades

This commit is contained in:
Thastertyn 2023-03-06 07:09:05 +01:00
parent 34d84b9e10
commit 99dadb3441
15 changed files with 70 additions and 48 deletions

BIN
jecnak-tui.jar Normal file

Binary file not shown.

View File

@ -47,11 +47,6 @@ public class Rozvrh {
* Stahne rozvrh z www.spsejecna.cz a dale ho zpracuje do formy * Stahne rozvrh z www.spsejecna.cz a dale ho zpracuje do formy
* se kterou da pracovat * se kterou da pracovat
* @param Jsessionid ze stranek * @param Jsessionid ze stranek
* @return Status code
* <newline>
* <ul>
* <li> 0 - Operace probehla bez problemu</li>
* </ul>
* @throws UnknownHostException kdyz neni pripojeni k internetu * @throws UnknownHostException kdyz neni pripojeni k internetu
* @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom * @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom
*/ */
@ -74,7 +69,6 @@ public class Rozvrh {
String predmet = rozvrhDny[i].get(j).select("span.subject").text().replaceAll(" ", "/"); String predmet = rozvrhDny[i].get(j).select("span.subject").text().replaceAll(" ", "/");
// Predmety jako CEL jsou trikrat, staci ale jen jednou // Predmety jako CEL jsou trikrat, staci ale jen jednou
// V hashsetu se neopakuji prvky
HashSet<String> set = new HashSet<>(); HashSet<String> set = new HashSet<>();
String[] split = predmet.split("/"); String[] split = predmet.split("/");
@ -96,6 +90,11 @@ public class Rozvrh {
for(String s : set) { pr = s; break; } for(String s : set) { pr = s; break; }
} }
if(pr.isBlank())
{
pr = "-";
}
rozvrh[i-1][j-1] = pr; rozvrh[i-1][j-1] = pr;
} }
} }

View File

@ -35,8 +35,8 @@ public class Znamky {
private double getAverage(ArrayList<Pair<Integer, Double>> a) private double getAverage(ArrayList<Pair<Integer, Double>> a)
{ {
try{ try{
int divident = 0; double divident = 0;
int divisor = 0; double divisor = 0;
for(Pair<Integer, Double> p : a) for(Pair<Integer, Double> p : a)
{ {
if(p.getValue0() == -1) if(p.getValue0() == -1)
@ -57,10 +57,11 @@ public class Znamky {
} }
} }
public void downloadZnamky(final String Jsessionid) throws UnknownHostException, IOException public void downloadZnamky(final String Jsessionid/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException
{ {
wasDownloaded = true; wasDownloaded = true;
Document znamkyDoc = Downloader.download("https://www.spsejecna.cz" + "/score/student", Jsessionid).get(); //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?schoolYearId=14&schoolYearHalfId=21", Jsessionid).get();
Elements rows = znamkyDoc.select("table.score").select("tr"); Elements rows = znamkyDoc.select("table.score").select("tr");

View File

@ -26,4 +26,14 @@ public class JecnaContent {
{ {
return ""; return "";
} }
public void specify(int y, int hy)
{
}
public void getOptions()
{
}
} }

View File

@ -18,7 +18,7 @@ public class Rozvrh extends JecnaContent {
private String[] labels = {"Den", "7:30-8:15", "8:25-9:10", "9:20-10:05", "10:20-11:05", "11:15-12:00", "12:10-12:55", "13:05-13:50", "14:00-14:45", "14:55-15:40", "15:50-16:35"}; private String[] labels = {"Den", "7:30-8:15", "8:25-9:10", "9:20-10:05", "10:20-11:05", "11:15-12:00", "12:10-12:55", "13:05-13:50", "14:00-14:45", "14:55-15:40", "15:50-16:35"};
//private String[] labels = {"Den", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10."}; //private String[] labels = {"Den", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10."};
String[] days = {"PO", "UT", "ST", "CT", "PA"}; String[] daysLabels = {"PO", "UT", "ST", "CT", "PA"};
Table<String> t = new Table<>(labels); Table<String> t = new Table<>(labels);
@ -28,16 +28,19 @@ public class Rozvrh extends JecnaContent {
try{ try{
rozvrh.downloadRozvrh(Jsessionid); rozvrh.downloadRozvrh(Jsessionid);
String[][] r = rozvrh.getRozvrh(); String[][] rozvrhArray = rozvrh.getRozvrh();
String[] s = new String[labels.length]; String[] den = new String[11];
for(int i = 0; i < r.length; i++) for(int i = 0; i < rozvrhArray.length; i++)
{ {
s[0] = days[i]; den[0] = daysLabels[i];
for(int j = 1; j < r[i].length; j++) { s[j] = r[i][j]; } for(int j = 1; j < rozvrhArray[i].length + 1; j++)
{
den[j] = (rozvrhArray[i][j - 1].isBlank()) ? " - " : rozvrhArray[i][j - 1];
}
t.getTableModel().addRow(s); t.getTableModel().addRow(den);
} }
rozvrhPanel.addComponent(t); rozvrhPanel.addComponent(t);
hasStarted = true; hasStarted = true;

View File

@ -3,6 +3,7 @@ package xyz.thastertyn.Window.Content;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import com.googlecode.lanterna.SGR;
import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.TextColor;
import com.googlecode.lanterna.graphics.SimpleTheme; import com.googlecode.lanterna.graphics.SimpleTheme;
import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.Direction;
@ -53,20 +54,21 @@ public class Znamky extends JecnaContent {
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK)); znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK));
break; break;
case 1: case 1:
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.GREEN)); znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(85,212,0)));
break; break;
case 2: case 2:
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.BLUE)); znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(196,224,80)));
break; break;
case 3: case 3:
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.YELLOW)); znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(255,213,42)));
break; break;
case 4: case 4:
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.MAGENTA)); znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(255,102,0)));
break; break;
case 5: case 5:
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.RED)); znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(255,48,48)));
break; break;
// Todo try set sgr
} }
znamkyZPredmetu.addComponent(znamkaLabel); znamkyZPredmetu.addComponent(znamkaLabel);
@ -76,25 +78,25 @@ public class Znamky extends JecnaContent {
double prumer = predmet.getValue1().getValue1(); double prumer = predmet.getValue1().getValue1();
Label vysl = new Label("" + prumer); Label vysl = new Label(String.format("%.2f", prumer));
if(prumer >= 1 && prumer < 1.5) if(prumer >= 1 && prumer < 1.5)
{ {
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.GREEN)); vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(85,212,0)));
}else if(prumer >= 1.5 && prumer < 2.5) }else if(prumer >= 1.5 && prumer < 2.5)
{ {
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.BLUE)); vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(196,224,80)));
}else if(prumer >= 2.5 && prumer < 3.5) }else if(prumer >= 2.5 && prumer < 3.5)
{ {
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.YELLOW)); vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(255,213,42)));
}else if(prumer >= 3.5 && prumer < 4.5) }else if(prumer >= 3.5 && prumer < 4.5)
{ {
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.MAGENTA)); vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(255,102,0)));
}else if(prumer >= 4.5) }else if(prumer >= 4.5)
{ {
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.RED)); vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, new TextColor.RGB(255,48,48)));
} }
vyslPanel.addComponent(vysl); vyslPanel.addComponent(vysl);

View File

@ -2,9 +2,9 @@ package xyz.thastertyn.Window;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.TextColor;
import com.googlecode.lanterna.gui2.BasicWindow; import com.googlecode.lanterna.gui2.BasicWindow;
import com.googlecode.lanterna.gui2.Border;
import com.googlecode.lanterna.gui2.Borders; import com.googlecode.lanterna.gui2.Borders;
import com.googlecode.lanterna.gui2.DefaultWindowManager; import com.googlecode.lanterna.gui2.DefaultWindowManager;
import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.Direction;
@ -13,7 +13,6 @@ import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.LinearLayout;
import com.googlecode.lanterna.gui2.MultiWindowTextGUI; import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.Separator;
import com.googlecode.lanterna.gui2.Window; import com.googlecode.lanterna.gui2.Window;
import com.googlecode.lanterna.screen.Screen; import com.googlecode.lanterna.screen.Screen;
import com.googlecode.lanterna.screen.TerminalScreen; import com.googlecode.lanterna.screen.TerminalScreen;
@ -52,17 +51,22 @@ public class MainWindow {
window.setComponent(mainPanel); window.setComponent(mainPanel);
mainPanel.addComponent(new Separator(Direction.VERTICAL).setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Fill))); Panel tabs = new Panel()
.setLayoutManager(new LinearLayout(Direction.HORIZONTAL))
.addComponent(new Label("Rozvrh").withBorder(Borders.singleLine()))
.addComponent(new Label("Znamky").withBorder(Borders.singleLine()));
String text = "Jecnak"; mainPanel.addComponent(tabs);
String title = "Jecnak";
Panel content = new Panel(); Panel content = new Panel();
mainPanel.addComponent(content.withBorder(Borders.singleLine(text))); mainPanel.addComponent(content.withBorder(Borders.singleLine(title)));
Login login = new Login(); Login login = new Login();
login.showDialog(textGUI); login.showDialog(textGUI);
window.addWindowListener(new WindowSwitchListener(content, login.getJessionId(), text)); window.addWindowListener(new WindowSwitchListener(content, login.getJessionId(), tabs, title));
textGUI.addWindowAndWait(window); textGUI.addWindowAndWait(window);

View File

@ -23,25 +23,28 @@ public class WindowSwitchListener implements WindowListener {
private String JsessionId; private String JsessionId;
Panel panel; Panel content;
String label; Panel tabs;
String title;
int current = 0; int current = 0;
public WindowSwitchListener(Panel holder, String JsessionId, String label) public WindowSwitchListener(Panel holder, String JsessionId, Panel tabs, String title)
{ {
panel = holder; this.content = holder;
this.tabs = tabs;
this.title = title;
this.JsessionId = JsessionId; this.JsessionId = JsessionId;
this.label = label;
defaultPanel(); defaultPanel();
} }
private void defaultPanel() private void defaultPanel()
{ {
contents[0].download(JsessionId); contents[0].download(JsessionId);
panel.removeAllComponents(); content.removeAllComponents();
panel.addComponent(contents[0].getPanel()); content.addComponent(contents[0].getPanel());
label = contents[0].getLabel(); title = contents[0].getLabel();
} }
public void next() public void next()
@ -58,10 +61,10 @@ public class WindowSwitchListener implements WindowListener {
contents[current].download(JsessionId); contents[current].download(JsessionId);
} }
panel.removeAllComponents(); content.removeAllComponents();
panel.addComponent(contents[current].getPanel()); content.addComponent(contents[current].getPanel());
label = contents[current].getLabel(); title = contents[current].getLabel();
} }
public void previous() public void previous()
@ -77,10 +80,10 @@ public class WindowSwitchListener implements WindowListener {
{ {
contents[current].download(JsessionId); contents[current].download(JsessionId);
} }
panel.removeAllComponents(); content.removeAllComponents();
panel.addComponent(contents[current].getPanel()); content.addComponent(contents[current].getPanel());
label = contents[current].getLabel(); title = contents[current].getLabel();
} }