Skip to content

Commit

Permalink
fix: missing last meal per section (resolve #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
muety committed Jun 22, 2023
1 parent 73b3681 commit af19584
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>edu.kit.aifb.atks</groupId>
<artifactId>mensascraper</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</parent>

<groupId>edu.kit.aifb.atks.mensascraper</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void main(String[] args) {
final var scraper = new KITMensaScraper();
final var day = args.length > 0
? LocalDate.parse(args[0])
: LocalDate.now();
: LocalDate.now(); // TODO: make time-zone aware -> always use "now" for time zone the requested mensa is located in
final var meals = scraper.fetchMeals(MensaLocation.ADENAUERRING, day);
System.out.println(new Gson().toJson(meals));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<parent>
<groupId>edu.kit.aifb.atks</groupId>
<artifactId>mensascraper</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</parent>

<groupId>edu.kit.aifb.atks.mensascraper</groupId>
<artifactId>lib</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<name>mensascraper-lib</name>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ private static List<MensaMeal> parseMeals(Element root, LocalDate day) {
.parallel()
.map(KITMensaScraper::parseSingleLine)
.flatMap(Collection::stream)
.filter(m -> m.getPrice() > 0)
.distinct()
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -138,8 +140,9 @@ private static List<MensaMeal> parseSingleLine(Element el) {

if (isNutrition) {
// parse nutrition info
// nutrition info always comes second, after the meal entry
if (currentMeal == null) {
throw new MensaScraperException("got nutrition table without preceeding meal");
throw new MensaScraperException("got nutrition table without preceding meal");
}
currentMeal.setKcal(parseKcal(mealRow));
currentMeal.setProteins(parseProteins(mealRow));
Expand All @@ -150,15 +153,12 @@ private static List<MensaMeal> parseSingleLine(Element el) {
currentMeal.setSalt(parseSalt(mealRow));
} else {
// parse meal info
if (currentMeal != null) {
meals.add(currentMeal);
}

currentMeal = new MensaMeal();
currentMeal.setName(parseMealName(mealRow));
currentMeal.setAdditives(parseMealAdditives(mealRow));
currentMeal.setPrice(parseMealPrice(mealRow));
currentMeal.setType(parseMealType(mealRow));
meals.add(currentMeal);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import org.junit.jupiter.api.Test;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAdjusters;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -28,7 +29,7 @@ void tearDown() {
void testFetchMealsLive() {
// fetch live data for today, if today is a weekday or next monday otherwise
// note: this test will fail when run on days when canteen is closed, but should be acceptable
final var now = LocalDate.now();
final var now = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).toLocalDate();
final var targetDate = now.getDayOfWeek().getValue() >= DayOfWeek.SATURDAY.getValue()
? now.with(TemporalAdjusters.next(DayOfWeek.MONDAY))
: now;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ void testFetchMeals() throws IOException, InterruptedException {
verify(httpClient, times(2)).send(captor1.capture(), any());
assertEquals("kw=19", captor1.getValue().uri().getQuery());

assertEquals(23, tuesday.size());
assertEquals(24, wednesday.size());
assertEquals(32, tuesday.size());
assertEquals(32, wednesday.size());
assertEquals(tuesday.size(), tuesday.stream().distinct().count());
assertEquals(wednesday.size(), wednesday.stream().distinct().count());
assertEquals("Mini Frühlingsrollen mit Sweet Chili Soße und Mienudeln", tuesday.get(2).getName());
assertEquals("Hausgemachte Gnocchi in Bechamelsoße mit Chorizo", tuesday.get(5).getName()); // bold + normal font
assertEquals("Hausgemachte Gnocchi in Bechamelsoße mit Chorizo", tuesday.get(6).getName()); // bold + normal font
assertEquals(3, tuesday.get(2).getAdditives().size());
assertEquals("Sa", tuesday.get(2).getAdditives().get(0));
assertEquals(3.8f, tuesday.get(2).getPrice());
assertEquals(3.5f, tuesday.get(5).getPrice());
assertEquals(3.5f, tuesday.get(6).getPrice());
assertEquals(1147.0f, tuesday.get(2).getKcal());
assertEquals(1121.0f, tuesday.get(5).getKcal());
assertEquals(1121.0f, tuesday.get(6).getKcal());
assertEquals(23.0f, tuesday.get(2).getProteins());
assertEquals(MensaLine.LINIE_2, tuesday.get(2).getLine());
assertEquals(MensaMealType.VEGAN, tuesday.get(2).getType());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>edu.kit.aifb.atks</groupId>
<artifactId>mensascraper</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<packaging>pom</packaging>

<properties>
Expand Down

0 comments on commit af19584

Please sign in to comment.