Skip to content

Commit 9013593

Browse files
committed
Split hierarchy test
1 parent cc45eb1 commit 9013593

File tree

2 files changed

+77
-13
lines changed

2 files changed

+77
-13
lines changed

plugins/gbif/gbif_data.py

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def taxonomic_percentajes(df):
291291
1. Calcula el total de ocurrencias en el DataFrame.
292292
2. Calcula el porcentaje de géneros que están presentes en el catálogo de vida (Species2000).
293293
3. Calcula el porcentaje de especies presentes en el DataFrame.
294-
4. Calcula el porcentaje de calidad para la jerarquía taxonómica.
294+
4. Calcula el porcentaje de calidad para la jerarquía taxonómica en tres partes: reuino, clase/orden y familia
295295
5. Calcula el porcentaje de identificadores disponibles en el DataFrame.
296296
6. Calcula el porcentaje total de calidad taxonómica combinando los porcentajes ponderados.
297297
7. Imprime el resultado del porcentaje total de calidad taxonómica.
@@ -330,22 +330,56 @@ def taxonomic_percentajes(df):
330330
logger.debug(f"ERROR specificEpithet - {e}")
331331
percentaje_species = 0
332332

333+
# Porcentaje de calidad para el reino
334+
try:
335+
percentaje_kingdom = (
336+
df.value_counts(
337+
subset=["kingdom"],
338+
dropna=False,
339+
)
340+
.reset_index(name="N")
341+
.apply(kingdom_weights, axis=1)
342+
.sum()
343+
/ total_data
344+
* 100
345+
)
346+
except Exception as e:
347+
logger.debug(f"ERROR kingdom - {e}")
348+
percentaje_kingdom = 0
349+
350+
# Porcentaje de calidad para la jerarquía taxonómica
351+
try:
352+
percentaje_class_order = (
353+
df.value_counts(
354+
subset=["class", "order"],
355+
dropna=False,
356+
)
357+
.reset_index(name="N")
358+
.apply(class_order_weights, axis=1)
359+
.sum()
360+
/ total_data
361+
* 100
362+
)
363+
except Exception as e:
364+
logger.debug(f"ERROR class_order - {e}")
365+
percentaje_class_order = 0
366+
333367
# Porcentaje de calidad para la jerarquía taxonómica
334368
try:
335-
percentaje_hierarchy = (
369+
percentaje_family = (
336370
df.value_counts(
337-
subset=["higherClassification", "kingdom", "class", "order", "family"],
371+
subset=["family"],
338372
dropna=False,
339373
)
340374
.reset_index(name="N")
341-
.apply(hierarchy_weights, axis=1)
375+
.apply(family_weights, axis=1)
342376
.sum()
343377
/ total_data
344378
* 100
345379
)
346380
except Exception as e:
347-
logger.debug(f"ERROR hierarchy - {e}")
348-
percentaje_hierarchy = 0
381+
logger.debug(f"ERROR family - {e}")
382+
percentaje_family = 0
349383

350384
# Porcentaje de identificadores disponibles en el DataFrame
351385
try:
@@ -358,15 +392,19 @@ def taxonomic_percentajes(df):
358392
percentaje_taxonomic = (
359393
0.2 * percentaje_genus
360394
+ 0.1 * percentaje_species
361-
+ 0.09 * percentaje_hierarchy
395+
+ 0.03 * percentaje_kingdom
396+
+ 0.03 * percentaje_class_order
397+
+ 0.03 * percentaje_family
362398
+ 0.06 * percentaje_identifiers
363399
)
364400

365401
return {
366402
"Taxonomic": percentaje_taxonomic,
367403
"Genus": 0.2 * percentaje_genus,
368404
"Species": 0.1 * percentaje_species,
369-
"Hierarchy": 0.09 * percentaje_hierarchy,
405+
"Kingdom": 0.03 * percentaje_kingdom,
406+
"Class/Order": 0.03 * percentaje_class_order,
407+
"Family": 0.03 * percentaje_family,
370408
"Identifiers": 0.06 * percentaje_identifiers,
371409
}
372410

@@ -629,6 +667,24 @@ def hierarchy_weights(row):
629667
)
630668

631669

670+
def kingdom_weights(row):
671+
"""Returns N for each not empty sublevel (kingdom)."""
672+
N = row.N
673+
return N if pd.notnull(row.kingdom) else 0
674+
675+
676+
def class_order_weights(row):
677+
"""Returns N for each not empty sublevel (class/order)."""
678+
N = row.N
679+
return N if pd.notnull(row["class"]) or pd.notnull(row.order) else 0
680+
681+
682+
def family_weights(row):
683+
"""Returns N for each not empty sublevel (family)."""
684+
N = row.N
685+
return N if pd.notnull(row.family) else 0
686+
687+
632688
def is_valid_country_code(row):
633689
"""If the countryCode column from the row is valid, return the column N. Otherwise
634690
return 0.

plugins/gbif/plugin.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Plugin(Evaluator):
3939
def __init__(self, item_id, oai_base=None, lang="en", config=None):
4040
logger.debug("Creating GBIF")
4141
plugin = "gbif"
42-
super().__init__(item_id, oai_base, lang, plugin)
42+
super().__init__(item_id, oai_base, lang, plugin, config)
4343
# TO REDEFINE - WHICH IS YOUR PID TYPE?
4444
self.id_type = idutils.detect_identifier_schemes(item_id)[0]
4545
print("Gbif")
@@ -262,8 +262,16 @@ def data_01(self):
262262
<td bgcolor={self.get_color(ica["Species"])}> {ica["Species"]:.2f}% </td>
263263
</tr>
264264
<tr>
265-
<td bgcolor="#D5D5D5"> Hierarchy </td>
266-
<td bgcolor={self.get_color(ica["Hierarchy"])}> {ica["Hierarchy"]:.2f}% </td>
265+
<td bgcolor="#D5D5D5"> Kingdom </td>
266+
<td bgcolor={self.get_color(ica["Kingdom"])}> {ica["Kingdom"]:.2f}% </td>
267+
</tr>
268+
<tr>
269+
<td bgcolor="#D5D5D5"> Class/Order </td>
270+
<td bgcolor={self.get_color(ica["Class/Order"])}> {ica["Class/Order"]:.2f}% </td>
271+
</tr>
272+
<tr>
273+
<td bgcolor="#D5D5D5"> Family </td>
274+
<td bgcolor={self.get_color(ica["Family"])}> {ica["Family"]:.2f}% </td>
267275
</tr>
268276
<tr>
269277
<td bgcolor="#D5D5D5"> Identifiers </td>
@@ -288,7 +296,7 @@ def data_01(self):
288296
</tr>
289297
<tr>
290298
<td bgcolor="#D5D5D5"> IncorrectCoordinates </td>
291-
<td bgcolor="{self.get_color(ica["IncorrectCoordinates"])}"> -{ica["IncorrectCoordinates"]:.2f}% </td>
299+
<td bgcolor="{self.get_color(ica["IncorrectCoordinates"])}"> {ica["IncorrectCoordinates"]:.2f}% </td>
292300
</tr>
293301
294302
<tr>
@@ -309,7 +317,7 @@ def data_01(self):
309317
</tr>
310318
<tr>
311319
<td bgcolor="#D5D5D5"> IncorrectDates </td>
312-
<td bgcolor="{self.get_color(ica["IncorrectDates"])}"> -{ica["IncorrectDates"]:.2f}% </td>
320+
<td bgcolor="{self.get_color(ica["IncorrectDates"])}"> {ica["IncorrectDates"]:.2f}% </td>
313321
</tr>
314322
</table>
315323
"""

0 commit comments

Comments
 (0)