diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..8f40936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +**0.1.2** + +- bug fixes around `Threat Status`, choosing to not display when no IUCU data is available + +**0.1.1** + +- removed logger backend code in favour of `LoggerWebhookBackend` + +**0.1.0 - Initial Release** diff --git a/lib/plantnet/parser.ex b/lib/plantnet/parser.ex index 37732ed..d9757aa 100644 --- a/lib/plantnet/parser.ex +++ b/lib/plantnet/parser.ex @@ -79,13 +79,15 @@ defmodule PlantIdDiscordBot.PlantNet.Parser do best_result = hd(data["results"]) other_results = tl(data["results"]) best_guess_name = best_result["species"]["scientificNameWithoutAuthor"] + best_result_iucn_category = best_result["iucn"]["category"] score = round(best_result["score"] * 100) |> Integer.to_string() """ My best guess is **#{best_guess_name}** with a confidence of **#{score}%**. Common names include **#{Enum.join(best_result["species"]["commonNames"], ", ")}**. [GBIF](<#{best_result["gbif_url"]}>) | [PFAF](<#{best_result["pfaf_url"]}>) | [POWO](<#{best_result["powo_url"]}>) - Threat status: #{best_result["iucn"]["category"]} + + #{if best_result_iucn_category, do: "Threat status: #{best_result_iucn_category}", else: ""} #{get_alternatives(other_results)} """ diff --git a/mix.exs b/mix.exs index 43094e7..525f265 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule PlantidDiscordBot.MixProject do def project do [ app: :plantid_discord_bot, - version: "0.1.1", + version: "0.1.2", elixir: "~> 1.16", start_permanent: Mix.env() == :prod, deps: deps() diff --git a/test/plantnet/parser_test.exs b/test/plantnet/parser_test.exs index dadaebb..5d11b51 100644 --- a/test/plantnet/parser_test.exs +++ b/test/plantnet/parser_test.exs @@ -26,4 +26,12 @@ defmodule PlantIdDiscordBotTest.PlantNet.Parser do assert result == PlantNetFixtures.parsed_response_with_urls() end + + test "no iucn data prevents 'Threat Status' from being show in response message" do + message = + PlantNetFixtures.parsed_response_with_urls_no_iucn() + |> Parser.generate_response_message() + + refute String.contains?(message, "Threat status: ") + end end diff --git a/test/test_helper.exs b/test/test_helper.exs index 4c95c98..b7a8b28 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -210,6 +210,72 @@ defmodule PlantNetFixtures do "version" => "2024-11-19 (7.3)" } + @plantnet_parsed_response_filtered_by_score_no_iucn %{ + "bestMatch" => "Prunus cerasifera Ehrh.", + "language" => "en", + "preferedReferential" => "k-world-flora", + "query" => %{ + "images" => [ + "https://upload.wikimedia.org/wikipedia/commons/f/ff/Prunus_cerasifera_A.jpg", + "https://le-jardin-de-pascal.com/2195113-large_default/prunus-cerasifera-atropurpurea-prunier-myrobolan-nigra.jpg" + ], + "includeRelatedImages" => false, + "noReject" => false, + "organs" => ["auto", "auto"], + "project" => "all" + }, + "remainingIdentificationRequests" => 488, + "results" => [ + %{ + "gbif" => %{"id" => "3021730"}, + "powo" => %{"id" => "729568-1"}, + "score" => 0.87871, + "species" => %{ + "commonNames" => ["Cherry plum, myrobalan", "Cherry Plum", "Purple-leaf Plum"], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus cerasifera Ehrh.", + "scientificNameAuthorship" => "Ehrh.", + "scientificNameWithoutAuthor" => "Prunus cerasifera" + } + }, + %{ + "gbif" => %{"id" => "3022465"}, + "powo" => %{"id" => "2959315-4"}, + "score" => 0.31668, + "species" => %{ + "commonNames" => [ + "Dwarf red-leaf plum", + "Purple-leaf sand cherry", + "Purple-leaved sand cherry" + ], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus × cistena N.E.Hansen ex Koehne", + "scientificNameAuthorship" => "N.E.Hansen ex Koehne", + "scientificNameWithoutAuthor" => "Prunus × cistena" + } + } + ], + "version" => "2024-11-19 (7.3)" + } + @plantnet_parsed_response_with_urls %{ "bestMatch" => "Prunus cerasifera Ehrh.", "language" => "en", @@ -283,8 +349,85 @@ defmodule PlantNetFixtures do "version" => "2024-11-19 (7.3)" } + @plantnet_parsed_response_with_urls_no_iucn %{ + "bestMatch" => "Prunus cerasifera Ehrh.", + "language" => "en", + "preferedReferential" => "k-world-flora", + "query" => %{ + "images" => [ + "https://upload.wikimedia.org/wikipedia/commons/f/ff/Prunus_cerasifera_A.jpg", + "https://le-jardin-de-pascal.com/2195113-large_default/prunus-cerasifera-atropurpurea-prunier-myrobolan-nigra.jpg" + ], + "includeRelatedImages" => false, + "noReject" => false, + "organs" => ["auto", "auto"], + "project" => "all" + }, + "remainingIdentificationRequests" => 488, + "results" => [ + %{ + "gbif" => %{"id" => "3021730"}, + "gbif_url" => "https://www.gbif.org/species/3021730", + "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+cerasifera", + "powo" => %{"id" => "729568-1"}, + "powo_url" => "https://powo.science.kew.org/taxon/729568-1", + "score" => 0.87871, + "species" => %{ + "commonNames" => ["Cherry plum, myrobalan", "Cherry Plum", "Purple-leaf Plum"], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus cerasifera Ehrh.", + "scientificNameAuthorship" => "Ehrh.", + "scientificNameWithoutAuthor" => "Prunus cerasifera" + } + }, + %{ + "gbif" => %{"id" => "3022465"}, + "gbif_url" => "https://www.gbif.org/species/3022465", + "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+×+cistena", + "powo" => %{"id" => "2959315-4"}, + "powo_url" => "https://powo.science.kew.org/taxon/2959315-4", + "score" => 0.31668, + "species" => %{ + "commonNames" => [ + "Dwarf red-leaf plum", + "Purple-leaf sand cherry", + "Purple-leaved sand cherry" + ], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus × cistena N.E.Hansen ex Koehne", + "scientificNameAuthorship" => "N.E.Hansen ex Koehne", + "scientificNameWithoutAuthor" => "Prunus × cistena" + } + } + ], + "version" => "2024-11-19 (7.3)" + } + def raw_response, do: @plantnet_raw_response def parsed_response, do: @plantnet_parsed_response def parsed_response_filtered_by_score, do: @plantnet_parsed_response_filtered_by_score def parsed_response_with_urls, do: @plantnet_parsed_response_with_urls + + def plantnet_parsed_response_filtered_by_score_no_iucn, + do: @plantnet_parsed_response_filtered_by_score_no_iucn + + def parsed_response_with_urls_no_iucn, do: @plantnet_parsed_response_with_urls_no_iucn end