geodatafarm.database_scripts package¶
Module contents¶
Submodules¶
geodatafarm.database_scripts.create_new_farm module¶
-
class
geodatafarm.database_scripts.create_new_farm.
CreateFarm
(parent_widget, new_farm)¶ Bases:
object
-
add_schemas
()¶ Adds schemas to the new database
-
add_tables
(first_year)¶ Add field, crops and manual tables to the database
-
connect_to_source
()¶ Connects the plugin to another database
-
create_new_farm
()¶ Sends a request to the server and asks it to create the database for the farm, when the database is created does the server return a message telling if the farm name or user name is taken else a message that the database has been created.
-
create_spec_functions
()¶ Generates the function makegrid_2d in the users postgres database.
-
run
()¶ Presents the sub widget CreateFarm
-
geodatafarm.database_scripts.db module¶
-
class
geodatafarm.database_scripts.db.
DB
(dock_widget, path=None, tr=None)¶ Bases:
object
-
add_postgis_layer
(table, geom_col, schema, extra_name='', filter_text='')¶ Creates a qgis layer from a postgres database table.
Parameters: - table (str) – The table that should be added
- geom_col (str) – the geometry column in that table
- schema (str) – The schema
- extra_name (str, optional) – for a “pre name” in front of the table
- filter_text (str, optional) – SQL statement to filter the data
Returns: A QgsVectorLayer ready to be styled.
Return type: QgsVectorLayer
-
check_table_exists
(table_name, schema)¶ Checks if a table already exists.
Parameters: - table_name (str) –
- schema (str) –
Returns: Return type: bool
-
create_indexes
(tbl_name, params_to_eval, schema)¶ Drops is exists and create a gist index and btree indexes for params_to_eval a table
Parameters: - tbl_name (str) – table name
- params_to_eval (list) – of text strings with columns to make indexes over
- schema (str) – schema name
-
create_table
(sql, tbl_name)¶ Create s table, if table exists the table is dropped.
Parameters: - sql (str) – With the sql statement to create the table
- tbl_name (str) – table name
-
execute_and_return
(sql)¶ Execute and returns an SQL statement
Parameters: sql (str) – text string with the sql statement Returns: the data requested in the statement Return type: list of lists
-
execute_sql
(sql)¶ Parameters: sql (str) – text string with the sql statement
-
get_all_columns
(table, schema, exclude='')¶ Get all columns of a table
Parameters: - table (str) –
- schema (str) –
- exclude (str, optional, string with comma sep names) –
Returns: Return type: list of lists
-
get_conn
()¶ A function that checks if the database is created and sets then the database name, user name and password.
Returns: Return type: bool
-
get_distinct
(table, column, schema)¶ Get distinct values from a schema.table
Parameters: - table (str) –
- column (str) –
- schema (str) –
Returns: [distinct value, count]
Return type: list
-
get_indexes
(tables, schema)¶ Get indexes of tables in a schema, returns a dict.
Parameters: - tables (str) – what table(s) to look for. (separated by comma if multiple)
- schema (str) – schema name
Returns: int as first arg and for each int ‘tbl_name’,’index_name’, ‘index_col’ and ‘schema’
Return type: dict
-
get_tables_in_db
(schema)¶ Get the tables in schema
Parameters: schema (str) – Returns: A list of tables in the database Return type: list
-
remove_table
(tbl_schema_name)¶ Function that removes a table from the database
Parameters: tbl_schema_name (str) – string with schema.table
-
test_connection
()¶ Tests to open the connection and then closes it again :returns: :rtype: bool
-
update_row_id
(schema, table)¶ Update the field_row_id :param schema: :type schema: str :param table: :type table: str
-
-
exception
geodatafarm.database_scripts.db.
DBException
¶ Bases:
Exception
geodatafarm.database_scripts.mean_analyse module¶
-
class
geodatafarm.database_scripts.mean_analyse.
Analyze
(parent_widget, tables_to_analyse)¶ Bases:
object
-
check_consistency
()¶ Checks that the harvest tables is intersecting some of the input data If the data is an activity does it also check that the year is the same
-
default_layout
()¶ Creating the layout, (the UI file only contains the plotting area). This function adds parameters names and default value both in a scroll area bellow and to the right of the drawing area.
-
fill_dict_tables
()¶ Fills the dict tables
-
get_initial_distinct_values
(parameter_to_eval, tbl, schema)¶ Calls the database and gets distinct values
Parameters: - parameter_to_eval (str, What parameter to eval) –
- tbl (str, In what table is the param located) –
- schema (str, In what schema) –
Returns: analyse_params{‘distinct_values’:[],’distinct_count’:[]}
Return type: dict
-
plot_data
(result, values)¶ Plots the data from the sql query.
Parameters: - result (Unused parameter) –
- values (list) –
- if success:
- [True, dict]
- else:
- [False, message, tracback]
-
run
()¶ Starts this widget
-
update_checked_field
(other_parameters, main_investigate_col)¶ Updates the parameters listed as checked in layout_dict
Parameters: - other_parameters (dict) –
- main_investigate_col (dict) –
-
update_pic
()¶ Collects the data that the user gave as input and starts the QgsTask that runs the SQL query. On finish plot_data is called
-
update_top_panel
(nbr, col)¶ Updates the top right panel with the data that complies the diagram
Parameters: - nbr (int, what number to update) –
- col (str, the name och parameter to update) –
-
-
geodatafarm.database_scripts.mean_analyse.
sql_query
(task, investigating_param, other_parameters, db, min_counts)¶ Function that creates and runs the SQL questions to the database, creates filters and connects the correct tables to each other. Runs one question for each interval.
Parameters: - task (QgsTask) –
- investigating_param (dict) –
- other_parameters (dict) –
- db (DB) –
- min_counts (int, the minimum data points that are required.) –
Returns: - if success:
[bool, dict]
- else:
[bool, str, str]
Return type: list
geodatafarm.database_scripts.plan_ahead module¶
-
class
geodatafarm.database_scripts.plan_ahead.
PlanAhead
(parent)¶ Bases:
object
A class that fill the tab plan ahead with content
-
save_data
()¶ Saves the plan
-
set_widget_connections
()¶ A simple function that sets the buttons on the plan ahead tab
-
update_fields
()¶ A function that updates the crops and field table.
-
update_sum
()¶ Update the yearly summary for current and last year
-
view_year
()¶ Add a background map to the canvas.
-
geodatafarm.database_scripts.table_managment module¶
-
class
geodatafarm.database_scripts.table_managment.
TableManagement
(parent)¶ Bases:
object
-
edit_param_name
()¶ Edit the name of all selected parameters.
-
edit_tbl_name
()¶ This function pops a question if the user wants to rename the selected tables to. Then it is replaced and the manual table is also updated.
-
merge_tbls
()¶ Merging two data sets into one.
-
remove_table_from_db
()¶ Removes the selected tables from the database
-
retrieve_params
()¶ This function is trigged by “edit” table, and basically fills the left list widget, all attributes that have a index get selected by default.
-
run
()¶ Connects the push buttons and enable the visibility of the dialog.
-
save_table
()¶ Updates the attribute indexes that are checked in the list widget
-
update_table_list
()¶ Update the list of tables in the docket widget
-