-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
223 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
|
||
|
||
from andes_migrate.andes_helper import AndesHelper | ||
from andes_migrate.projet_mollusque import ProjetMollusque | ||
from andes_migrate.table_peche_sentinelle import TablePecheSentinelle | ||
|
||
|
||
Catch_ID | ||
Date | ||
secteur | ||
fieldNumber #DarwinCore | ||
trait | ||
station | ||
verbatimIdentification #DarwinCore | ||
scientificName #DarwinCore | ||
lifeStage #DarwinCore | ||
identificationRemarks #DarwinCore | ||
taxonRemarks #DarwinCore | ||
organismRemarks #DarwinCore | ||
associatedTaxa #DarwinCore | ||
cote_abond | ||
Abond | ||
Poids_g | ||
Abond_ech | ||
Poids_ech | ||
multiplier | ||
Abon_tot | ||
Poids_tot_g | ||
notes | ||
|
||
|
||
|
||
https://iml-science-1.ent.dfo-mpo.ca:8181/turbot/ | ||
https://dmapps/fr/dfodots/collections/33/view/ | ||
http://iml-science-1.ent.dfo-mpo.ca:8180/turbot/ | ||
recordedBy | ||
class Biodiversity(): | ||
|
||
def __init__(self, andes_db: AndesHelper): | ||
|
||
self.andes_db = andes_db | ||
|
||
# call this form outside | ||
self._init_rows() | ||
|
||
def populate_data(self): | ||
"""Populate data: run all getters""" | ||
# secteur trait no taille poids_vif poids_muscle poids_gonade poids_visceres sexe espece comment | ||
if self.collection_name == 'Conserver le spécimen (Biométrie Centre)': | ||
secteur = "Centre" | ||
if self.collection_name == 'Conserver le spécimen (Biométrie Ouest)': | ||
secteur = "Ouest" | ||
sexe_dict={'0':"I", | ||
'1':'M', | ||
'2':'F', | ||
} | ||
self.data["id_specimen"] = self._get_current_row_pk() | ||
self.data["secteur"] = secteur | ||
self.data["trait"] = self.get_ident_no_trait() | ||
self.data["no"] = int(self.get_observation("Code Collection coquille").strip().split("-")[-1]) | ||
self.data["taille"] = self.get_observation("Longueur (non officiel)").replace(".",",") | ||
self.data["poids_vif"] = self.get_observation("Poids vif").replace(".",",") | ||
self.data["poids_muscle"] = self.get_observation("Poids du muscle").replace(".",",") | ||
self.data["poids_gonade"] = self.get_observation("Poids des gonades").replace(".",",") | ||
self.data["poids_visceres"] = self.get_observation("Poids des viscères").replace(".",",") | ||
self.data["poids_gonade"] = self.get_observation("Poids des gonades").replace(".",",") | ||
self.data["sexe"] = self.get_observation("Sexe") | ||
self.data["comment"] = self.get_comment() | ||
|
||
def __next__(self): | ||
""" | ||
Increment to focus on next row | ||
""" | ||
# print(self.table_name) | ||
# print(f"{self._row_idx} of {len(self._row_list)}") | ||
# print() | ||
if self._row_idx is not None and self._row_list is not None: | ||
if self._row_idx < len(self._row_list): | ||
# increment first, it'l be adjusted in _get_current_row_pk() | ||
self._row_idx += 1 | ||
self.populate_data() | ||
|
||
# self.write_row() | ||
return self.data | ||
else: | ||
raise StopIteration | ||
else: | ||
self.logger.error("Row data not initialise, did you run _init_rows()?") | ||
raise ValueError | ||
|
||
|
||
def _init_rows(self): | ||
"""Initialisation method | ||
This queries the Andes DB and creates a list of row entries to be added to the current table | ||
After running this methods initialises the following attribute: | ||
self._row_list | ||
self._row_idx (hopefully to self._row_idx=0) | ||
self._row_list will be populated with the specimen ids belonging in the collection | ||
self._row_idx will start at 0 | ||
""" | ||
query = ( | ||
"SELECT specimen_id " | ||
"FROM ecosystem_survey_observation " | ||
"LEFT JOIN ecosystem_survey_specimen " | ||
"ON ecosystem_survey_observation.specimen_id = ecosystem_survey_specimen.id " | ||
"LEFT JOIN ecosystem_survey_basket " | ||
"ON ecosystem_survey_specimen.basket_id = ecosystem_survey_basket.id " | ||
"LEFT JOIN ecosystem_survey_catch " | ||
"ON ecosystem_survey_basket.catch_id=ecosystem_survey_catch.id " | ||
"LEFT JOIN shared_models_set " | ||
"ON shared_models_set.id=ecosystem_survey_catch.set_id " | ||
"LEFT JOIN shared_models_observationtype " | ||
"ON shared_models_observationtype.id=observation_type_id " | ||
f"WHERE shared_models_set.cruise_id = {self.proj._get_current_row_pk()} " | ||
f"AND (shared_models_observationtype.nom ='{self.collection_name}' AND observation_value=1) " | ||
) | ||
result = self.andes_db.execute_query(query) | ||
self._assert_not_empty(result) | ||
self._row_list = [specimen[0] for specimen in result] | ||
self._row_idx = 0 | ||
|
||
# @validate_int() | ||
# @log_results | ||
def get_ident_no_trait(self) -> int: | ||
"""IDENT_NO_TRAIT INTEGER / NUMBER(5,0) | ||
Numéro séquentiel d'identification du trait | ||
Andes | ||
----- | ||
shared_models.set.set_number | ||
""" | ||
specimen_pk = self._get_current_row_pk() | ||
query = ( | ||
"SELECT shared_models_set.set_number " | ||
"FROM ecosystem_survey_specimen " | ||
"LEFT JOIN ecosystem_survey_basket " | ||
"ON ecosystem_survey_specimen.basket_id=ecosystem_survey_basket.id " | ||
"LEFT JOIN ecosystem_survey_catch " | ||
"ON ecosystem_survey_basket.catch_id=ecosystem_survey_catch.id " | ||
"LEFT JOIN shared_models_set " | ||
"ON shared_models_set.id=ecosystem_survey_catch.set_id " | ||
f"WHERE ecosystem_survey_specimen.id={specimen_pk} " | ||
) | ||
result = self.andes_db.execute_query(query) | ||
self._assert_one(result) | ||
to_return = result[0][0] | ||
return to_return | ||
|
||
|
||
def get_observation(self, name_fr): | ||
specimen_pk = self._get_current_row_pk() | ||
query = ( | ||
"SELECT observation_value " | ||
"FROM ecosystem_survey_observation " | ||
"LEFT JOIN shared_models_observationtype " | ||
"ON ecosystem_survey_observation.observation_type_id=shared_models_observationtype.id " | ||
f"WHERE ecosystem_survey_observation.specimen_id={specimen_pk} " | ||
f"AND shared_models_observationtype.nom='{name_fr}' " | ||
) | ||
result = self.andes_db.execute_query(query) | ||
try: | ||
self._assert_one(result) | ||
to_return = result[0][0] | ||
except ValueError: | ||
print(specimen_pk, name_fr,result) | ||
to_return = None | ||
if to_return is None: | ||
to_return="" | ||
return to_return | ||
|
||
def get_comment(self): | ||
specimen_pk = self._get_current_row_pk() | ||
query = ( | ||
"SELECT ecosystem_survey_specimen.comment " | ||
"FROM ecosystem_survey_specimen " | ||
f"WHERE ecosystem_survey_specimen.id={specimen_pk} " | ||
) | ||
result = self.andes_db.execute_query(query) | ||
self._assert_one(result) | ||
to_return = result[0][0] | ||
if to_return is None: | ||
to_return="" | ||
to_return.replace("\n", " ") | ||
to_return.replace("\r", " ") | ||
return to_return | ||
|
||
|
||
|
||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.