From 0f39be89c3d5620b8187b1d7621b7680800c268b Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Tue, 30 Aug 2022 14:54:33 +1000 Subject: Display IUCN status in TileInfoModal --- backend/tilo.py | 7 ++++++- backend/tolData/README.md | 4 ++-- src/components/TileInfoModal.vue | 32 ++++++++++++++++++++++++++++++++ src/tol.ts | 2 ++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/backend/tilo.py b/backend/tilo.py index bb7af16..196f193 100755 --- a/backend/tilo.py +++ b/backend/tilo.py @@ -36,7 +36,7 @@ ROOT_NAME = "cellular organisms" # Classes for objects sent as responses (matches lib.ts types in client-side code) class TolNode: " Used when responding to 'node' and 'chain' requests " - def __init__(self, otolId, children, parent=None, tips=0, pSupport=False, commonName=None, imgName=None): + def __init__(self, otolId, children, parent=None, tips=0, pSupport=False, commonName=None, imgName=None, iucn=None): self.otolId = otolId # string | null self.children = children # string[] self.parent = parent # string | null @@ -44,6 +44,7 @@ class TolNode: self.pSupport = pSupport # boolean self.commonName = commonName # null | string self.imgName = imgName # null | string | [string,string] | [null, string] | [string, null] + self.iucn = iucn # null | string class SearchSugg: " Represents a search suggestion " def __init__(self, name, canonicalName=None): @@ -133,6 +134,10 @@ def lookupNodes(names, tree, dbCur): query = f"SELECT name, alt_name FROM names WHERE pref_alt = 1 AND name IN ({queryParamStr})" for (name, altName) in dbCur.execute(query, names): nameToNodes[name].commonName = altName + # Get IUCN status + query = f"SELECT name, iucn FROM node_iucn WHERE name IN ({queryParamStr})" + for (name, iucn) in dbCur.execute(query, names): + nameToNodes[name].iucn = iucn # return nameToNodes def lookupSuggs(searchStr, suggLimit, tree, dbCur): diff --git a/backend/tolData/README.md b/backend/tolData/README.md index 1248098..ece07b4 100644 --- a/backend/tolData/README.md +++ b/backend/tolData/README.md @@ -74,8 +74,8 @@ Some of the scripts use third-party packages: files in wikidata/, and 'dump-index files' in enwiki/, as specified in their READMEs. 2. Run genMappingData.py, which adds the `eol_ids` and `wiki_ids` tables, - using the files obtained above, and the `nodes` table. It also uses - 'picked mappings' files, if they exist. + as well as `node_iucn`. It uses the files obtained above, the `nodes` table, + and 'picked mappings' files, if they exist. - pickedEolIds.txt contains lines like `3785967|405349`, specifying an otol ID and an eol ID to map it to. The eol ID can be empty, in which case the otol ID won't be mapped. diff --git a/src/components/TileInfoModal.vue b/src/components/TileInfoModal.vue index 421f22f..a6b2986 100644 --- a/src/components/TileInfoModal.vue +++ b/src/components/TileInfoModal.vue @@ -20,6 +20,11 @@
Children: {{(tolNode.children.length).toLocaleString()}}
Tips: {{(tolNode.tips).toLocaleString()}}
+
+ IUCN: + {{getDisplayIucn(tolNode.iucn)}} +
OTOL @@ -170,6 +175,21 @@ export default defineComponent({ overflow: 'visible auto', }; }, + iucnStyles(): Record { + let col = 'currentcolor'; + switch (this.tolNode.iucn){ + case 'least concern': col = 'green'; break; + case 'near threatened': col = 'limegreen'; break; + case 'vulnerable': col = 'goldenrod'; break; + case 'endangered': col = 'darkorange'; break; + case 'critically endangered': col = 'red'; break; + case 'extinct in the wild': + case 'extinct species': col = 'gray'; break; + } + return { + color: col, + }; + }, linkCopyLabelStyles(): Record { return { color: this.uiOpts.textColor, @@ -186,6 +206,18 @@ export default defineComponent({ return `${capitalizeWords(tolNode.commonName)} (aka ${capitalizeWords(name)})`; } }, + getDisplayIucn(iucn: string){ + switch (this.tolNode.iucn){ + case 'least concern': return 'LC'; + case 'near threatened': return 'NT'; + case 'vulnerable': return 'VN'; + case 'endangered': return 'EN'; + case 'critically endangered': return 'CR'; + case 'extinct in the wild': return 'EX'; + case 'extinct species': return 'ES'; + case 'data deficient': return 'DD'; + } + }, getImgStyles(tolNode: TolNode | null): Record { let imgName = null; if (tolNode != null && typeof(tolNode.imgName) === 'string'){ // Exclude string-array case diff --git a/src/tol.ts b/src/tol.ts index 2618bfc..bd299b3 100644 --- a/src/tol.ts +++ b/src/tol.ts @@ -12,6 +12,7 @@ export class TolNode { commonName: null | string; imgName: null | string | [string, string] | [null, string] | [string, null]; // Pairs represent compound images + iucn: null | string; constructor(children: string[] = [], parent = null, tips = 0, pSupport = false){ this.otolId = null; this.children = children; @@ -20,6 +21,7 @@ export class TolNode { this.pSupport = pSupport; this.commonName = null; this.imgName = null; + this.iucn = null; } } // Maps TolNode names to TolNode objects -- cgit v1.2.3