Skip to content

Commit

Permalink
Merge branch 'main' into docu-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cymed authored Nov 26, 2024
2 parents 7d84e5d + 4a9d9bb commit 81a3178
Show file tree
Hide file tree
Showing 39 changed files with 37,011 additions and 32,919 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 1 addition & 1 deletion .github/workflows/datamodel-create-dumps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
jobs:
datamodel-dumps:
name: Create dumps and schemaspy of datamodel
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
env:
COMPOSE_PROFILES: schemaspy

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/datamodel-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
jobs:
datamodel-tests:
name: Run unit tests on datamodel
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

strategy:
matrix:
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:

static-tests:
name: Run static tests on datamodel
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

build:
needs: datamodel-documentation
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/plugin-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ on:
jobs:
plugin-package:
name: Packages and releases plugin
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'

- name: Install Qt lrelease
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/plugin-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🪲 Plugin | Tests
name: 🔌 Plugin | Tests

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -25,7 +25,7 @@ on:
jobs:
plugin-tests:
name: Run unit tests on plugin
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/project-translation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ on:
paths:
- project/**
- '.github/workflows/project-translation.yml'
pull_request:
branches:
- main
paths:
- project/**
- '.github/workflows/project-translation.yml'
schedule:
- cron: "30 04 * * *"
workflow_dispatch:


jobs:
build:
name: Update project translations
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
Expand All @@ -42,6 +50,7 @@ jobs:
run: docker compose run qgis sh -c 'xvfb-run /usr/src/project/scripts/project-translation-create-source.py /usr/src/project/teksi_wastewater.qgs'

- name: Push to TX
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
working-directory: project
run: ./tx push --source

Expand Down
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-python.python",
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
}
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}
],
"justMyCode": false
},
]
}
65 changes: 65 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Install dependencies",
"type": "shell",
"command": "pip install debugpy \"sqlalchemy~=1.3.22\" \"geoalchemy2>=0.9.0\"",
"windows": {
"options": {
"shell": {
"executable": "C:\\OSGeo4W\\OSGeo4W.bat"
}
}
},
"problemMatcher": []
},
{
"label": "docker-db",
"type": "docker-compose",
"dockerCompose": {
"up": {
"detached": true,
"build": false,
"services": [
"db"
]
},
"files": [
"${workspaceFolder}/docker-compose.yml"
]
}
},
{
"label": "Launch QGIS",
"type": "process",
"args": [
"--project",
"${workspaceFolder}\\project\\teksi_wastewater.qgs"
],
"runOptions": {
"instanceLimit": 1,
"reevaluateOnRerun": false
},
"dependsOn": [
"docker-db"
],
"problemMatcher": [],
"options": {
"env": {
"QGIS_PLUGINPATH": "${workspaceFolder}\\plugin",
"QGIS_PLUGIN_USE_DEBUGGER": "debugpy",
"PGSERVICEFILE": "${workspaceFolder}\\project\\pg_service.conf"
}
},
"windows": {
"command": "C:\\OSGeo4W\\bin\\qgis-ltr-bin.exe"
},
"linux": {
"command": "qgis"
}
}
]
}
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,29 @@ How to start [testing](https://github.com/teksi/wastewater/discussions/72)
Upcoming first version TEKSI Wastewater 2024.0 is due to end of march 2024.

Migration path from QGEP to TEKSI Wastewater is due to end of summer 2024. <!--- // skip-keyword-check -->

## Local development

1. Open OSGeo4W Shell and run `pip install debugpy`.
2. Clone this repository to your local machine.
3. Open QGIS, go to the _Environment_ section in `Settings > Options - System` and add the following custom variables:

| Apply | Variable | Value |
| :----- | :----------------------- | :---------------------- |
| APPEND | QGIS_PLUGINPATH | {repositoryPath}/plugin |
| APPEND | QGIS_PLUGIN_USE_DEBUGGER | debugpy |

4. Install QGIS plugin _Plugin Reloader_. This will allow you to reload the plugin without restarting QGIS.
5. Follow the _prerequisites_ and _Usage (GUI)_ from https://github.com/wapaAdmin/tww2ag6496/blob/main/docs/en/admin-guide/interlis-io/index.rst

## Local development with VS Code

1. Ensure prerequisites are met according to the [admin guide](docs/en/admin-guide/interlis-io/index.rst).
2. Install [Visual Studio Code](https://code.visualstudio.com/) and the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python).
3. Install QGIS LTR
4. Install Docker
5. Install debugpy by running task `Install dependencies` or run `pip install debugpy` in the OSGeo4W Shell on Windows or your python env for qgis.
6. Launch QGIS with task `Launch QGIS`.
7. Wait for QGIS to start and open the plugin in QGIS.
7. Ensure __Developer mode__ is enabled in the plugin settings. This will start the debug server.
8. Attach the debugger with Debug: Start Debugging (F5) with configuration `Python: Remote Attach`
10 changes: 6 additions & 4 deletions datamodel/app/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ def create_app(

run_sql("CREATE SCHEMA tww_app;", pg_service)

run_sql_file("functions/oid_functions.sql", pg_service, variables)
run_sql_file("functions/oid_functions.sql", pg_service)
run_sql_file("functions/modification_functions.sql", pg_service)
run_sql_file("functions/symbology_functions.sql", pg_service)
run_sql_file("functions/reach_direction_change.sql", pg_service, variables)
run_sql_file("functions/14_geometry_functions.sql", pg_service, variables)
run_sql_file("functions/geometry_functions.sql", pg_service, variables)
run_sql_file("functions/update_catchment_area_totals.sql", pg_service, variables)
run_sql_file("functions/organisation_functions.sql", pg_service, variables)
run_sql_file("functions/meta_functions.sql", pg_service, variables)
run_sql_file("functions/network_functions.sql", pg_service)

if extension_names:
for extension in extension_names:
Expand Down Expand Up @@ -140,6 +141,8 @@ def create_app(
"drainage_system": "zone",
}

# Defaults and Triggers
# Has to be fired before view creation otherwise it won't work and will only fail in CI
set_defaults_and_triggers(pg_service, SingleInheritances)

for key in SingleInheritances:
Expand Down Expand Up @@ -251,8 +254,7 @@ def create_app(
pg_service,
).create()

run_sql_file("triggers/network.sql", pg_service)

# Roles
run_sql_file("tww_app_roles.sql", pg_service, variables)


Expand Down
99 changes: 76 additions & 23 deletions datamodel/app/functions/modification_functions.sql
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
------ LAST MODIFIED -----
CREATE FUNCTION tww_app.modification_last_modified() RETURNS trigger AS $$
BEGIN
NEW.last_modification := TIMEOFDAY();

RETURN NEW;
END;
$$ LANGUAGE PLPGSQL;

CREATE FUNCTION tww_app.modification_last_modified_parent() RETURNS trigger AS $$
DECLARE
table_name TEXT;
BEGIN
table_name = TG_ARGV[0];

EXECUTE '
UPDATE ' || table_name || '
SET last_modification = TIMEOFDAY()::timestamp
WHERE obj_id = ''' || NEW.obj_id || '''
';
RETURN NEW;
END;
$$ LANGUAGE PLPGSQL;
--------------------------------------------------
-- Alter modification triggers
--------------------------------------------------

CREATE OR REPLACE FUNCTION tww_app.alter_modification_triggers(action_name text) RETURNS VOID AS
$DO$
Expand Down Expand Up @@ -53,6 +33,10 @@ END;
$DO$
LANGUAGE plpgsql SECURITY DEFINER;

--------------------------------------------------
-- Check if modification triggers are enabled
--------------------------------------------------

CREATE OR REPLACE FUNCTION tww_app.check_modification_enabled() RETURNS BOOL AS
$DO$
DECLARE _disabled_count numeric;
Expand All @@ -70,3 +54,72 @@ BEGIN
END;
$DO$
LANGUAGE plpgsql SECURITY DEFINER;

--------------------------------------------------
-- ON REACH DELETE
--------------------------------------------------
-- Remove linked network element and reach points
-- Remove channel if no reach is left
--------------------------------------------------

CREATE OR REPLACE FUNCTION tww_app.modification_on_reach_delete()
RETURNS trigger AS
$BODY$
DECLARE
channel_id text;
reach_count integer;
BEGIN
-- get channel obj_id
SELECT fk_wastewater_structure INTO channel_id
FROM tww_od.wastewater_networkelement
WHERE wastewater_networkelement.obj_id = OLD.obj_id;

DELETE FROM tww_od.wastewater_networkelement WHERE obj_id = OLD.obj_id;
DELETE FROM tww_od.reach_point WHERE obj_id = OLD.fk_reach_point_from;
DELETE FROM tww_od.reach_point WHERE obj_id = OLD.fk_reach_point_to;

-- delete channel if no reach left
SELECT COUNT(fk_wastewater_structure) INTO reach_count
FROM tww_od.wastewater_networkelement
WHERE fk_wastewater_structure = channel_id;
IF reach_count = 0 THEN
RAISE NOTICE 'Removing channel (%) since no reach is left', channel_id;
DELETE FROM tww_od.channel WHERE obj_id = channel_id;
DELETE FROM tww_od.wastewater_structure WHERE obj_id = channel_id;
END IF;
RETURN NEW;
END; $BODY$
LANGUAGE plpgsql VOLATILE;

CREATE TRIGGER on_reach_1_delete
AFTER DELETE
ON tww_od.reach
FOR EACH ROW
EXECUTE PROCEDURE tww_app.modification_on_reach_delete();

--------------------------------------------------
-- LAST MODIFIED
--------------------------------------------------

CREATE FUNCTION tww_app.modification_last_modified() RETURNS trigger AS $$
BEGIN
NEW.last_modification := TIMEOFDAY();

RETURN NEW;
END;
$$ LANGUAGE PLPGSQL;

CREATE FUNCTION tww_app.modification_last_modified_parent() RETURNS trigger AS $$
DECLARE
table_name TEXT;
BEGIN
table_name = TG_ARGV[0];

EXECUTE '
UPDATE ' || table_name || '
SET last_modification = TIMEOFDAY()::timestamp
WHERE obj_id = ''' || NEW.obj_id || '''
';
RETURN NEW;
END;
$$ LANGUAGE PLPGSQL;
File renamed without changes.
Loading

0 comments on commit 81a3178

Please sign in to comment.