marineenergy / apps

shiny apps for MHK-env
https://marineenergy.github.io/apps/
MIT License
3 stars 1 forks source link

handle missing nested Tags #94

Closed bbest closed 2 years ago

bbest commented 2 years ago

Problem

From MarineEnergy.app_Review_GCS_120921.docx - Google Docs:

If a user gets really specific and selects, e.g., Tidal, Physical Interaction/Changes in Flow, Fish/Pelagic Fish, no results appear on any of the pages. There’s an issue with the way Tethys Knowledge Base publications are tagged. For example: If one selects Tidal, Physical Interaction, and Fish, there are 33 entries in Management Measures, 221 FERC Docs, and 0 Tethys Publications. If one selects Tidal and Fish, or Tidal and Fish and Collision, no Tethys Publications appear. But with Current and Fish and Collision or just Fish and Collision, there are 479 hits. We need to figure out what to do about this. For example, if no results appear, have a statement appear, like, “No results found. Recommend a broader search (e.g., Current instead of Tidal or Noise instead of Noise/Underwater.” Or we implement code that automatically searches the next category up on the hierarchy and let the user know that this has been implemented.

Update filter for content based on available tags

Message based on content

A la https://github.com/marineenergy/apps/issues/93:

bbest commented 2 years ago

Sequence of shiny app report-v2 operations

You'll probably want to use direct SQL, ie DBI::getQuery() to take advantage of the Postgres ltree querying to ask whether any children exist. Here's some further reference:

bbest commented 2 years ago

Pseudocode:

# if "Stressor.Noise.Underwater" not in "tethys_pub_tags" & has level > 2
# then check if higher level exists. if so, update to that one and share message

Trick:

dput(ixns) # to output variable
bbest commented 2 years ago

image

bbest commented 2 years ago

Cristina's current approach:

https://github.com/marineenergy/apps/blob/34b378c5c4e374d6c2672b7ce40205db8bb2f452/scripts/shiny_report.R#L455-L461

The problem currently is that per https://github.com/marineenergy/apps/issues/106#issuecomment-1015582361 we need both of these intxns filtering processes to happen per content type, ideally with messages back to the user:

  1. Drop non-applicable tag categories, ie dropping Consequence.Collision tag from interactions querying Publications since this content type lacks the Consequence category; and

  2. Convert missing child tags to parents, ie converting Stressor.Noise.Underwater to Stressor.Noise with Publications since this content type only has the parent Noise tag.

# get ixns by content type
ixns_pubs <– get_ixns_for_content(ixns, "publications") # add attributes with messages

# get data, ie rows, of content by ixns
rowids <- sapply(ixns_pubs, get_rowids_with_ixn, db_tbl = "tethys_pub_tags", categories = tag_cats) %>%
      unlist() %>% unique()
    d <- d %>%
      filter(rowid %in% !!rowids)

And still need to produce an output in server.R per content type like:

cdobbelaere commented 2 years ago

Tags with non-applicable tag categories are now dropped from interactions, but messages demonstrating modifications to missing child tags are now appearing even when there is a NULL message attribute in the corresponding data.

When Noise/Underwater and Fish/DemersalFish are selected, the message on the Publications page appears as expected:

Screen Shot 2022-01-20 at 5 39 56 PM

However, there is a message on both the Documents and Management pages, even though there is data to match the tags in the interaction. This message should not appear at all, but instead it appears as follows:

Screen Shot 2022-01-20 at 5 40 09 PM
bbest commented 2 years ago

Looks like this is working fine with latest overhaul