Skip to content

Commit 0bbb691

Browse files
committed
-v4
1 parent c21274a commit 0bbb691

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/main/java/com/example/Main.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
public class Main {
1818

1919
public static void main(String[] args) {
20-
// Kontrollera om inga argument eller --help anropades
2120
if (args.length == 0 || (args.length == 1 && args[0].equals("--help"))) {
2221
printHelp();
2322
return;
@@ -28,7 +27,6 @@ public static void main(String[] args) {
2827
boolean sorted = false;
2928
int chargingHours = 0;
3029

31-
// 1. Argumenthantering
3230
for (int i = 0; i < args.length; i++) {
3331
switch (args[i]) {
3432
case "--zone" -> {
@@ -84,7 +82,6 @@ public static void main(String[] args) {
8482
}
8583
}
8684

87-
// 2. Datahämtning (hämta idag OCH imorgon)
8885
ElpriserAPI api = new ElpriserAPI(true);
8986
List<Elpris> priser = new ArrayList<>();
9087

@@ -96,18 +93,13 @@ public static void main(String[] args) {
9693
return;
9794
}
9895

99-
// 3. Formatering
10096
DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.forLanguageTag("sv-SE"));
10197
symbols.setDecimalSeparator(',');
10298
DecimalFormat df = new DecimalFormat("#0.00", symbols);
10399

104-
// Ny formattering för prislistan (HH-HH)
105-
DateTimeFormatter hourRangeFormatter = DateTimeFormatter.ofPattern("HH-HH");
106-
// Formattering för laddningsfönster (HH:mm)
107100
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
101+
DateTimeFormatter hourFormatter = DateTimeFormatter.ofPattern("HH");
108102

109-
110-
// 4. Laddningsoptimering (Sliding Window)
111103
if (chargingHours > 0) {
112104
if (chargingHours < 2 || chargingHours > 8) {
113105
System.out.println("Fel: Laddningsfönster måste vara 2h, 4h eller 8h.");
@@ -144,20 +136,17 @@ public static void main(String[] args) {
144136
double totalCostOre = minSum * 100;
145137
double avgOre = totalCostOre / chargingHours;
146138

147-
// OBS: "Påbörja laddning" och "Medelpris" för att matcha testet
148139
System.out.println("Påbörja laddning");
149140

150141
System.out.println("Optimalt laddningsfönster (" + chargingHours + "h):");
151142
System.out.println("Starttid: kl " + start.timeStart().format(timeFormatter));
152143
System.out.println("Sluttid: kl " + end.timeEnd().format(timeFormatter));
153144
System.out.println("Total kostnad: " + df.format(totalCostOre) + " öre");
154-
System.out.println("Medelpris: " + df.format(avgOre) + " öre/kWh"); // Ändrad från Genomsnitt till Medelpris
145+
System.out.println("Medelpris för fönster: " + df.format(avgOre) + " öre");
155146

156147
return;
157148
}
158149

159-
// 5. Statistik och Prislista
160-
161150
List<Double> priserOre = priser.stream()
162151
.map(p -> p.sekPerKWh() * 100)
163152
.toList();
@@ -174,12 +163,14 @@ public static void main(String[] args) {
174163
priserForDisplay.sort(Comparator.comparingDouble(Elpris::sekPerKWh).reversed());
175164
}
176165

177-
// Display priser: Använd hourRangeFormatter för att få HH-HH format
178166
for (Elpris pris : priserForDisplay) {
179-
// Använd hourRangeFormatter (HH-HH) istället för timeFormatter (HH:mm)
180-
String startEndHours = pris.timeStart().format(hourRangeFormatter);
167+
String startHour = pris.timeStart().format(hourFormatter);
168+
String endHour = pris.timeEnd().format(hourFormatter);
169+
170+
String timeRange = startHour + "-" + endHour;
171+
181172
double ore = pris.sekPerKWh() * 100;
182-
System.out.println(startEndHours + " " + df.format(ore) + " öre");
173+
System.out.println(timeRange + " " + df.format(ore) + " öre");
183174
}
184175

185176
System.out.println("----------------------------------------");

0 commit comments

Comments
 (0)