API

Main Class

class nofa.gui.ins_mw.InsMw(iface, mc, plugin_dir)[source]

A main window for inserting data into NOFA database.

chck_mand_wdgs(mand_wdgs, exc)[source]

Checks if the given mandatory widgets are filled.

Parameters:
  • mand_wdgs (list) – A list of mandatory widgets.
  • exc (Exception) – An exception that should be raised.
dsc_from_iface()[source]

Disconnects the plugin from the QGIS interface.

get_wdg_list(wdgs, pydate=True, forbi=False)[source]

Returns the data from the given list of widgets.

Parameters:
  • wdgs (list) – A list of widgets whose data should be returned.
  • pydate (bool) – True to convert QDate to datetime.date, False otherwise.
  • forbi (bool) – True to allow forbidden text, False otherwise.
Returns:

A list of data from event input widgets.

Return type:

list

pop_cb(cb_dict)[source]

Populates combo boxe(s) and/or list widget(s).

Parameters:cb_dict (dict) –
A combo box dictionary:
- key - <combo box name>
- value - [<fill method>, [<arguments>], <default value>]
pop_dtst_cb()[source]

Populates the dataset combo box.

pop_prj_cb()[source]

Populates the project combo box.

pop_ref_cb()[source]

Populates the reference combo box.

prep()[source]

Prepares the whole plugin to be shown.

set_mand_wdgs(wdgs)[source]

Sets mandatory widgets. Mandatory widgets have predefined color when they are not filled/selected.

  • QLineEdit – must contain at least one
  • QComboBox – selected value can not be in list of forbidden strings
  • QDateEdit – user must edit (click) on it at least once
Parameters:wdgs (list) – A list of widgets to be set as mandatory.
upd_dtst(dtst_str=None)[source]

Updates a dataset according to the last selected.

Parameters:dtst_str (str) – A dataset string <ID> - <name>.
upd_prj(prj_str=None)[source]

Updates a project according to the last selected.

Parameters:prj_str (str) – A project string <name> - <organisation>.
upd_ref(ref_str=None)[source]

Updates a reference according to the last selected.

Parameters:ref_str (str) – A reference string <author>: <title> (<year>) @<ID>.

Database Handling

nofa.db.chck_locid(con, locid)[source]

Checks if a location ID is in the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • locid (str) – A location ID.
Returns:

True when location ID was found, False otherwise.

Return type:

bool

nofa.db.chck_nofa_tbls(con)[source]

Checks if the database is NOFA.

Parameters:con (psycopg2.connection) – A connection.
Returns:True when database is NOFA, False otherwise.
Return type:bool
nofa.db.get_acs_list(con)[source]

Returns a list of access rights that is used to populate access rights combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of access rights.
Return type:list
nofa.db.get_cntry_code_list(con)[source]

Returns a list of country codes that is used to populate country code combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of country codes.
Return type:list
nofa.db.get_cnty_list(con, cntry_code)[source]

Returns a list of counties that is used to populate county combo box.

Parameters:
  • con (psycopg2.connection) – A connection.
  • cntry_code (str) – A country code.
Returns:

A list of counties.

Return type:

list

nofa.db.get_col_def_val(con, schema, tbl, col)[source]

Returns a column default value for the given table in the given schema. This function returns a default value with database function or cast.

Parameters:
  • con (psycopg2.connection) – A connection.
  • schema (str) – A schema.
  • tbl (str) – A table.
  • col (str) – A column.
Returns:

A column default value.

Return type:

str

nofa.db.get_con(con_info)[source]

Returns a connection.

Returns:A connection.
Return type:psycopg2.connection
nofa.db.get_dtst_cnt(con, id)[source]

Returns a number of datasets with the given ID.

Parameters:
  • con (psycopg2.connection) – A connection.
  • id (str) – A dataset ID.
Returns:

A number of datasets with the given ID.

Return type:

int

nofa.db.get_dtst_info(con, dtst_id)[source]

Returns information about a dataset with the given ID.

Parameters:
  • con (psycopg2.connection) – A connection.
  • dtst_id (str) – A dataset ID.
Returns:

A tuple containing:
- list – a list of dataset items
- list – a list of dataset headers

Return type:

tuple

nofa.db.get_dtst_list(con)[source]

Returns a list with information about datasets that is used to populate dataset combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list with information about datasets.
Return type:list
nofa.db.get_dtst_mtdt_str(dtst_str)[source]

Returns a dataset metadata string <name>.

Parameters:dtst_str (str) – A dataset string <ID> - <name>.
Returns:A dataset metadata string <name>.
Return type:str
nofa.db.get_dtst_str(id, name)[source]

Returns a dataset string <ID> - <name>.

Parameters:
  • id (str) – A dataset ID.
  • name (str) – A dataset name.
Returns:

A dataset string <ID> - <name>.

Return type:

str

nofa.db.get_ectp_id(con, ectp)[source]

Returns an ecotype ID based on the given vernacular name.

Parameters:
  • con (psycopg2.connection) – A connection.
  • txn (str) – An ecotype vernacular name.
Returns:

An ecotype ID, None when there is no ecotype.

Return type:

int

nofa.db.get_ectp_list(con, txn_name)[source]

Returns a list of ecotypes that is used to populate ecotype combo box.

Parameters:
  • con (psycopg2.connection) – A connection.
  • txn_name (str) – A taxon name.
Returns:

A list of ecotypes.

Return type:

list

nofa.db.get_estbms_list(con)[source]

Returns a list of establishment means that is used to populate establishment means combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of establishment means.
Return type:list
nofa.db.get_fam_dict(con)[source]

Returns a defaultdict with family as keys and taxons as values.

Parameters:con (psycopg2.connection) – A connection.
Returns:
A defaultdict:
- key - str – family
- value - str – taxons
Return type:collections.defaultdict
nofa.db.get_hist_dtst_list(con, usr, ins_dt_strt, ins_dt_end, upd_dt_strt, upd_dt_end)[source]

Returns a list of history datasets that is used to populate dataset history table. Also returns a list of history datasets headers. Data are filtered based on input values.

Parameters:
  • con (psycopg2.connection) – A connection.
  • usr (str) – An username.
  • ins_dt_strt (datetime.date) – Insert date start.
  • ins_dt_end (datetime.date) – Insert date end.
  • upd_dt_strt (datetime.date) – Update date start.
  • upd_dt_end (datetime.date) – Update date end.
Returns:

A tuple containing:
- list – a list of history datasets
- list – a list of history datasets headers

Return type:

tuple

nofa.db.get_hist_event_list(con, usr, ins_dt_strt, ins_dt_end, upd_dt_strt, upd_dt_end)[source]

Returns a list of history events that is used to populate event history table. Also returns a list of history events headers. Data are filtered based on input values.

Parameters:
  • con (psycopg2.connection) – A connection.
  • usr (str) – An username.
  • ins_dt_strt (datetime.date) – Insert date start.
  • ins_dt_end (datetime.date) – Insert date end.
  • upd_dt_strt (datetime.date) – Update date start.
  • upd_dt_end (datetime.date) – Update date end.
Returns:

A tuple containing:
- list – a list of history events
- list – a list of history events headers

Return type:

tuple

nofa.db.get_hist_loc_list(con, usr, ins_dt_strt, ins_dt_end, upd_dt_strt, upd_dt_end)[source]

Returns a list of history locations that is used to populate location history table. Also returns a list of history locations headers. Data are filtered based on input values.

Parameters:
  • con (psycopg2.connection) – A connection.
  • usr (str) – An username.
  • ins_dt_strt (datetime.date) – Insert date start.
  • ins_dt_end (datetime.date) – Insert date end.
  • upd_dt_strt (datetime.date) – Update date start.
  • upd_dt_end (datetime.date) – Update date end.
Returns:

A tuple containing:
- list – a list of history locations
- list – a list of history locations headers

Return type:

tuple

nofa.db.get_hist_occ_list(con, usr, ins_dt_strt, ins_dt_end, upd_dt_strt, upd_dt_end)[source]

Returns a list of history occurrences that is used to populate occurrence history table. Also returns a list of history occurrences headers. Data are filtered based on input values.

Parameters:
  • con (psycopg2.connection) – A connection.
  • usr (str) – An username.
  • ins_dt_strt (datetime.date) – Insert date start.
  • ins_dt_end (datetime.date) – Insert date end.
  • upd_dt_strt (datetime.date) – Update date start.
  • upd_dt_end (datetime.date) – Update date end.
Returns:

A tuple containing:
- list – a list of history occurrences
- list – a list of history occurrences headers

Return type:

tuple

nofa.db.get_hist_prj_list(con, usr, ins_dt_strt, ins_dt_end, upd_dt_strt, upd_dt_end)[source]

Returns a list of history projects that is used to populate project history table. Also returns a list of history projects headers. Data are filtered based on input values.

Parameters:
  • con (psycopg2.connection) – A connection.
  • usr (str) – An username.
  • ins_dt_strt (datetime.date) – Insert date start.
  • ins_dt_end (datetime.date) – Insert date end.
  • upd_dt_strt (datetime.date) – Update date start.
  • upd_dt_end (datetime.date) – Update date end.
Returns:

A tuple containing:
- list – a list of history projects
- list – a list of history projects headers

Return type:

tuple

nofa.db.get_hist_ref_list(con, usr, ins_dt_strt, ins_dt_end, upd_dt_strt, upd_dt_end)[source]

Returns a list of history references that is used to populate reference history table. Also returns a list of history references headers. Data are filtered based on input values.

Parameters:
  • con (psycopg2.connection) – A connection.
  • usr (str) – An username.
  • ins_dt_strt (datetime.date) – Insert date start.
  • ins_dt_end (datetime.date) – Insert date end.
  • upd_dt_strt (datetime.date) – Update date start.
  • upd_dt_end (datetime.date) – Update date end.
Returns:

A tuple containing:
- list – a list of history references
- list – a list of history references headers

Return type:

tuple

nofa.db.get_inst_list(con)[source]

Returns a list of institutions that is used to populate institution combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of institutions.
Return type:list
nofa.db.get_loc_by_fltrs(con, wb, cntry_code, cnty, muni)[source]

Returns location IDs with the given filters.

Parameters:
  • con (psycopg2.connection) – A connection.
  • wb (str) – A water body.
  • cntry_code (str) – A country code.
  • cnty (str) – A county.
  • muni (str) – A municipality.
Returns:

A list of location IDs.

Return type:

list

nofa.db.get_locid_from_nvl(con, nvl)[source]

Returns a location ID based on the given Norwegian VatLnr.

Parameters:
  • con (psycopg2.connection) – A connection.
  • nvl (int) – A Norwegian VatLnr.
Returns:

A location ID.

Return type:

str

nofa.db.get_mpt_str(x, y)[source]

Returns a multi point string with the given coordinates.

Parameters:
  • x (float) – X coordinate.
  • y (float) – Y coordinate.
Returns:

A multi point string.

Return type:

str

nofa.db.get_muni_list(con, cntry_code, cnty)[source]

Returns a list of municipalities that is used to populate municipality combo box.

Parameters:
  • con (psycopg2.connection) – A connection.
  • cntry_code (str) – A country code.
  • cnty (str) – A county.
Returns:

A list of municipalities.

Return type:

list

nofa.db.get_nrst_locid(con, utm33_geom)[source]

Returns an ID of the nearest location.

Parameters:
  • con (psycopg2.connection) – A connection.
  • utm33_geom (str) – A geometry in UTM33 (EPSG: 25833).
Returns:

A location ID. None where there is no lake within the given distance.

Return type:

uuid.UUID

nofa.db.get_occstat_list(con)[source]

Returns a list of occurrence statuses that is used to populate occurrence status combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of occurrence statuses.
Return type:list
nofa.db.get_oqt_list(con)[source]

Returns a list of organism quantity types that is used to populate organism quantity type combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of organism quantity types.
Return type:list
nofa.db.get_poptrend_list(con)[source]

Returns a list of population trends that is used to populate population trend combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of population trends.
Return type:list
nofa.db.get_prj_id(con, prj_name, prj_org)[source]

Returns a project ID with the given organization number and name.

Parameters:
  • con (psycopg2.connection) – A connection.
  • prj_name (str) – A project name.
  • prj_org (str) – A project organization.
Returns:

A project ID with the given organization number and name.

Return type:

int

nofa.db.get_prj_info(con, prj_id)[source]

Returns information about a project with the given project name and organization.

Parameters:
  • con (psycopg2.connection) – A connection.
  • prj_id (int) – A project ID.
Returns:

A tuple containing:
- list – a list of project items
- list – a list of project headers

Return type:

tuple

nofa.db.get_prj_list(con)[source]

Returns a list with information about projects that is used to populate project combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list with information about projects.
Return type:list
nofa.db.get_prj_mtdt_str(prj_str)[source]

Returns a projects metadata string <name> - <organisation>.

Parameters:prj_str (str) – A project string <name> - <organization>.
Returns:A projects metadata string <name> - <organisation>.
Return type:str
nofa.db.get_prj_str(name, org)[source]

Returns a project string <name> - <organisation>.

Parameters:
  • name (str) – A project name.
  • org (str) – A project organization.
Returns:

A project string <name> - <organisation>.

Return type:

str

nofa.db.get_pt_str(x, y)[source]

Returns a point string with the given coordinates.

Parameters:
  • x (float) – X coordinate.
  • y (float) – Y coordinate.
Returns:

A point string.

Return type:

str

nofa.db.get_ref_info(con, ref_id)[source]

Returns information about a reference with the given reference ID.

Parameters:
  • con (psycopg2.connection) – A connection.
  • ref_id (str) – A reference ID.
Returns:

A tuple containing:
- list – a list of reference items
- list – a list of reference headers

Return type:

tuple

nofa.db.get_ref_list(con)[source]

Returns a list with information about references that is used to populate reference combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list with information about references.
Return type:list
nofa.db.get_ref_mtdt_str(ref_str)[source]

Returns a reference metadata string <author>: <title> (<year>).

Parameters:ref_str (str) – A reference string <author>: <title> (<year>) @<ID>.
Returns:A reference metadata string <author>: <title> (<year>).
Return type:str
nofa.db.get_ref_str(au, ttl, yr, id)[source]

Returns a reference string <author>: <title> (<year>) @<ID>.

Parameters:
  • au (str) – A reference author.
  • ttl (str) – A reference title.
  • yr (int) – A reference year.
  • id (str) – A reference ID.
Returns:

A reference string <author>: <title> (<year>) @<ID>.

Return type:

str

nofa.db.get_reftp_list(con)[source]

Returns a list of reference types that is used to populate reference type combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of reference types.
Return type:list
nofa.db.get_reliab_list(con)[source]

Returns a list of reliabilities that is used to populate reliability combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of reliabilities.
Return type:list
nofa.db.get_smpp_list(con)[source]

Returns a list of sampling protocols that is used to populate sampling protocol combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of sampling protocols.
Return type:list
nofa.db.get_smpsu_list(con)[source]

Returns a list of sample size units that is used to populate sample size unit combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of sample size units.
Return type:list
nofa.db.get_spwnc_list(con)[source]

Returns a list of spawning conditions that is used to populate spawning condition combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of spawning conditions.
Return type:list
nofa.db.get_spwnl_list(con)[source]

Returns a list of spawning locations that is used to populate spawning location combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of spawning locations.
Return type:list
nofa.db.get_txn_id(con, txn)[source]

Returns a taxon ID based on the given scientific name.

Parameters:
  • con (psycopg2.connection) – A connection.
  • txn (str) – A taxon scientific name.
Returns:

A taxon ID.

Return type:

int

nofa.db.get_txn_list(con)[source]

Returns a list of taxons that is used to populate taxon combo box.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of taxons.
Return type:list
nofa.db.get_usr_list(con)[source]

Returns a list of users whose accounts are active.

Parameters:con (psycopg2.connection) – A connection.
Returns:A list of users whose accounts are active.
Return type:list
nofa.db.get_utm33_geom(con, geom_str, srid)[source]

Returns a geometry in UTM33 (EPSG: 25833).

Parameters:
  • con (psycopg2.connection) – A connection.
  • geom_str (str) – A geometry string.
  • srid (int) – SRID.
Returns:

A geometry in UTM33 (EPSG: 25833).

Return type:

str

nofa.db.ins_dtst(con, dtst_list)[source]

Insert a dataset to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • dtst_list (list) – A dataset list
nofa.db.ins_dtst_log(con, id, usr)[source]

Insert a dataset log to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • id (str) – A dataset ID.
  • usr (str) – An username.
nofa.db.ins_event(con, loc_id, event_id, event_list, dtst_id, prj_id, ref_id)[source]

Insert an event to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • loc_id (uuid.UUID) – A location ID.
  • event_id (uuid.UUID) – An event ID.
  • event_list (list) – A list of data from event input widgets.
  • dtst_id (str) – A dataset ID.
  • prj_id (str) – A project ID.
  • ref_id (int) – A reference ID.
nofa.db.ins_event_log(con, loc_id, event_id, dtst_id, prj_id, ref_id, usr)[source]

Insert an event log to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • loc_id (str) – A location ID.
  • event_id (uuid.UUID) – An event ID.
  • dtst_id (str) – A dataset ID.
  • prj_id (str) – A project ID.
  • ref_id (int) – A reference ID.
  • usr (str) – An username.
nofa.db.ins_loc_log(con, id, name, usr)[source]

Insert a location log to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • id (str) – A location ID.
  • name (str) – A location name.
  • usr (str) – An username.
nofa.db.ins_new_loc(con, locid, utm33_geom, verb_loc)[source]

Insert a new location and returns its location ID.

Parameters:
  • con (psycopg2.connection) – A connection.
  • locid (uuid.UUID) – A location ID.
  • utm33_geom (str) – A geometry in UTM33 (EPSG: 25833).
  • verb_loc (str) – A verbatimLocality.
nofa.db.ins_occ(con, occ_id, txn_id, ectp_id, occ_row_list, event_id)[source]

insert an occurrence to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • occ_id (uuid.UUID) – An occurrence ID.
  • txn_id (int) – A taxon ID.
  • ectp_id (int) – An ecotype ID, None when there is no ecotype.
  • occ_row_list (list) – A list of data in the row in the occurrence table.
  • event_id (uuid.UUID) – An event ID.
Returns:

An ecotype ID, None when there is no ecotype.

Return type:

int

nofa.db.ins_occ_log(con, occ_id, event_id, dtst_id, prj_id, ref_id, loc_id, usr)[source]

Insert an occurrence log to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • occ_id (uuid.UUID) – An occurrence ID.
  • event_id (uuid.UUID) – An event ID.
  • dtst_id (str) – A dataset ID.
  • prj_id (str) – A project ID.
  • ref_id (int) – A reference ID.
  • loc_id (uuid.UUID) – A location ID.
  • usr (str) – An username.
nofa.db.ins_prj(con, prj_list)[source]

Insert an event to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • prj_list (list) – A project list
Returns:

A project ID.

Return type:

int

nofa.db.ins_prj_log(con, id, usr)[source]

Insert a project log to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • id (str) – A project ID.
  • usr (str) – An username.
nofa.db.ins_ref(con, ref_list)[source]

Insert an event to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • ref_list (list) – A reference list
Returns:

A reference ID.

Return type:

int

nofa.db.ins_ref_log(con, id, usr)[source]

Insert a reference log to the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • id (str) – A reference ID.
  • usr (str) – An username.
nofa.db.ins_txncvg(con, txn_id, event_id)[source]

Insert a taxon coverage into the database.

Parameters:
  • con (psycopg2.connection) – A connection.
  • txn_id (int) – A taxon ID.
  • event_id (uuid.UUID) – An event ID.
nofa.db.split_dtst_str(dtst_str)[source]

Splits a dataset string <ID> - <name> and returns its information.

Parameters:dtst_str (str) – A dataset string <ID> - <name>.
Returns:
A tuple containing:
- str – dataset ID
- str – name
Return type:tuple
nofa.db.split_prj_str(prj_str)[source]

Splits a project string <name> - <organization> and returns its information.

Parameters:prj_str (str) – A project string <name> - <organization>.
Returns:
A tuple containing:
- str – project name
- str – organization
Return type:tuple
nofa.db.split_ref_str(ref_str)[source]

Splits a reference string <author>: <title> (<year>) @<ID> and returns its information.

Parameters:ref_str (str) – A reference string <author>: <title> (<year>) @<ID>.
Returns:
A tuple containing:
- str – author
- str – year
- str – title
- int – ID
Return type:tuple