Skip to content

Commit

Permalink
Merge pull request #153 from kronos-et-al/revert-139-129-geflügel-aus…
Browse files Browse the repository at this point in the history
…-dem-gerichtsnamen-erkennen

Revert "Poultry recogniser"
  • Loading branch information
worldofjoni authored Apr 19, 2024
2 parents ff35ef5 + 504ea0f commit fc69a65
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 48 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions backend/migrations/20240313130248_poultry_checker.down.sql

This file was deleted.

5 changes: 0 additions & 5 deletions backend/migrations/20240313130248_poultry_checker.up.sql

This file was deleted.

25 changes: 4 additions & 21 deletions backend/src/layer/data/swka_parser/html_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ lazy_static! {
static ref VOLUME_REGEX: Regex = Regex::new(r"([0-9]*),([0-9]{2}) l").expect(REGEX_PARSE_E_MSG);

static ref ID_REGEX: Regex = Regex::new(r"[0-9]{18,}").expect(REGEX_PARSE_E_MSG);

static ref POULTRY_REGEX: Regex = Regex::new(r"(?i)ente|chicken|pute|geflügel|h[üäua]hn").expect(REGEX_PARSE_E_MSG);
}

const DISH_NODE_CLASS_SELECTOR_PREFIX: &str = "tr.mt-";
Expand Down Expand Up @@ -318,13 +316,12 @@ impl HTMLParser {
}

fn get_dish(dish_node: &ElementRef) -> Option<Dish> {
let name = Self::get_dish_name(dish_node)?;
Some(Dish {
food_type: Self::get_food_type(dish_node, &name).unwrap_or(FoodType::Unknown),
name,
name: Self::get_dish_name(dish_node)?,
price: Self::get_dish_price(dish_node),
allergens: Self::get_dish_allergens(dish_node).unwrap_or_default(),
additives: Self::get_dish_additives(dish_node).unwrap_or_default(),
food_type: Self::get_dish_type(dish_node).unwrap_or(FoodType::Unknown),
env_score: Self::get_dish_env_score(dish_node),
nutrition_data: Self::get_dish_nutrition_data(dish_node),
})
Expand Down Expand Up @@ -400,28 +397,14 @@ impl HTMLParser {
.collect()
}

fn get_food_type(dish_node: &ElementRef, name: &str) -> Option<FoodType> {
let preliminary_dish_type = Self::get_preliminary_food_type(dish_node);
if (preliminary_dish_type.is_none() || Some(FoodType::Unknown) == preliminary_dish_type)
&& Self::is_poultry(name)
{
return Some(FoodType::Poultry);
}
preliminary_dish_type
}

fn get_preliminary_food_type(dish_node: &ElementRef) -> Option<FoodType> {
fn get_dish_type(dish_node: &ElementRef) -> Option<FoodType> {
let dish_type_node = dish_node.select(&DISH_TYPE_NODE_CLASS_SELECTOR).next()?;
dish_type_node
.value()
.attr(DISH_TYPE_ATTRIBUTE_NAME)
.map(FoodType::parse)
}

fn is_poultry(name: &str) -> bool {
POULTRY_REGEX.captures(name).is_some()
}

fn get_dish_env_score(dish_node: &ElementRef) -> Option<ParseEnvironmentInfo> {
let env_info = ParseEnvironmentInfo {
co2_rating: Self::get_co2_rating(dish_node)?,
Expand Down Expand Up @@ -606,7 +589,7 @@ mod tests {
let file_contents = read_from_file(path).unwrap();
let canteen_data = HTMLParser::new().transform(&file_contents, 42_u32).unwrap();

//let remove_for_producton = write_output_to_file(path, &canteen_data);
//let _ = write_output_to_file(path, &canteen_data);
let expected = read_from_file(&path.replace(".html", ".txt"))
.unwrap()
.replace("\r\n", "\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
We,
],
additives: [],
food_type: Poultry,
food_type: Unknown,
env_score: Some(
ParseEnvironmentInfo {
co2_rating: 1,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/layer/data/swka_parser/test_data/test_normal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
We,
],
additives: [],
food_type: Poultry,
food_type: Unknown,
env_score: Some(
ParseEnvironmentInfo {
co2_rating: 1,
Expand Down Expand Up @@ -783,7 +783,7 @@
We,
],
additives: [],
food_type: Poultry,
food_type: Unknown,
env_score: None,
nutrition_data: None,
},
Expand Down Expand Up @@ -4829,7 +4829,7 @@
Colorant,
AntioxidantAgents,
],
food_type: Poultry,
food_type: Unknown,
env_score: None,
nutrition_data: None,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ mod test {
assert!(450.0 < average);
assert!(460.0 > average);

let dishes = [];
let dishes = vec![];
let average = RelationResolver::<MealplanManagementDatabaseMock>::average(dishes.iter());
assert!((average - 0.0).abs() < f64::EPSILON);
}
Expand Down
2 changes: 0 additions & 2 deletions backend/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ pub enum FoodType {
PorkAw,
/// This meal contains fish.
Fish,
/// This meal contains poultry, such as chicken, turkey, or similar
Poultry,
/// It is unknown whether this meal contains any meat or not.
Unknown,
}
Expand Down

0 comments on commit fc69a65

Please sign in to comment.