remove threat status text if no iucn data is available

This commit is contained in:
Owen
2024-12-29 20:16:11 +01:00
committed by Owen Rees
parent edf4364498
commit ffe6fca781
5 changed files with 164 additions and 2 deletions
+9
View File
@@ -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**
+3 -1
View File
@@ -79,13 +79,15 @@ defmodule PlantIdDiscordBot.PlantNet.Parser do
best_result = hd(data["results"]) best_result = hd(data["results"])
other_results = tl(data["results"]) other_results = tl(data["results"])
best_guess_name = best_result["species"]["scientificNameWithoutAuthor"] best_guess_name = best_result["species"]["scientificNameWithoutAuthor"]
best_result_iucn_category = best_result["iucn"]["category"]
score = round(best_result["score"] * 100) |> Integer.to_string() 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"], ", ")}**. 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"]}>) [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)} #{get_alternatives(other_results)}
""" """
+1 -1
View File
@@ -4,7 +4,7 @@ defmodule PlantidDiscordBot.MixProject do
def project do def project do
[ [
app: :plantid_discord_bot, app: :plantid_discord_bot,
version: "0.1.1", version: "0.1.2",
elixir: "~> 1.16", elixir: "~> 1.16",
start_permanent: Mix.env() == :prod, start_permanent: Mix.env() == :prod,
deps: deps() deps: deps()
+8
View File
@@ -26,4 +26,12 @@ defmodule PlantIdDiscordBotTest.PlantNet.Parser do
assert result == PlantNetFixtures.parsed_response_with_urls() assert result == PlantNetFixtures.parsed_response_with_urls()
end 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 end
+143
View File
@@ -210,6 +210,72 @@ defmodule PlantNetFixtures do
"version" => "2024-11-19 (7.3)" "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 %{ @plantnet_parsed_response_with_urls %{
"bestMatch" => "Prunus cerasifera Ehrh.", "bestMatch" => "Prunus cerasifera Ehrh.",
"language" => "en", "language" => "en",
@@ -283,8 +349,85 @@ defmodule PlantNetFixtures do
"version" => "2024-11-19 (7.3)" "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 raw_response, do: @plantnet_raw_response
def parsed_response, do: @plantnet_parsed_response def parsed_response, do: @plantnet_parsed_response
def parsed_response_filtered_by_score, do: @plantnet_parsed_response_filtered_by_score 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 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 end