Skip to content

Commit c029479

Browse files
authored
Merge pull request #2 from norwegian-geotechnical-institute/feature/adding_nadag
add nadag api and change pyproject version
2 parents e79d600 + 04cdeca commit c029479

8 files changed

Lines changed: 608 additions & 368 deletions

File tree

.github/workflows/branch.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ jobs:
4646
run: poetry install
4747
- name: Run ruff
4848
run: poetry run ruff check .
49-
- name: Run mypy
50-
run: poetry run mypy .
5149
- name: Run bandit
5250
run: poetry run bandit .
5351
- name: Run safety
5452
run: poetry run safety check -i 70612
5553
- name: Check for acceptable licenses
56-
run: poetry run pip-licenses --allow-only="MIT License;BSD License;Python Software Foundation License;Apache Software License;Mozilla Public License 2.0 (MPL 2.0);ISC License (ISCL);The Unlicense (Unlicense)"
54+
run: poetry run pip-licenses --allow-only="MIT License;BSD License;Python Software Foundation License;Apache Software License;Mozilla Public License 2.0 (MPL 2.0);ISC License (ISCL);The Unlicense (Unlicense);Historical Permission Notice and Disclaimer (HPND);Apache 2.0;BSD"

CHANGES.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
### Version 0.0.1a3
3+
4+
_2024-09-24_
5+
6+
ADD
7+
8+
- adding a examplestart for nadag api
9+
10+
### Version 0.0.1a2
11+
12+
_2024-09-19_
13+
14+
ADD
15+
16+
- adding structure and examples for NGM
17+
- POC for a usecase
18+
19+
### Version 0.0.1a1
20+
21+
_2024-09-16_
22+
23+
- first init

poetry.lock

Lines changed: 463 additions & 359 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[tool.poetry]
22
name = "field-manager-api"
3-
version = "0.0.1a1"
3+
version = "0.0.1a3"
44
description = "Field Manager API SDK"
55
license = "MIT"
6-
authors = ["Jostein Leira <9363084+josteinl@users.noreply.github.com>"]
6+
authors = ["Jostein Leira <9363084+josteinl@users.noreply.github.com>","Tellef Kydland <48522922+tellefk@users.noreply.github.com>"]
77
readme = "README.md"
88
homepage = "https://github.com/norwegian-geotechnical-institute/field-manager-api"
99
repository = "https://github.com/norwegian-geotechnical-institute/field-manager-api"
@@ -28,13 +28,13 @@ scipy = "^1.14.1"
2828
folium = "^0.17.0"
2929
selenium = "^4.24.0"
3030
webdriver-manager = "^4.0.2"
31-
docx = "^0.2.4"
3231
python-docx = "^1.1.2"
32+
shapely = "^2.0.6"
33+
pandas = "^2.2.3"
3334

3435
[tool.poetry.group.dev.dependencies]
3536
pytest = "*"
3637
pytest-cov = "*"
37-
mypy = "*"
3838
bandit = "*"
3939
safety = "*"
4040
pip-licenses = "*"

src/examples/example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33

44
fm = FieldManagerAPI()
5-
token = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJQZGRrU2pfVGpwWEpQTnVXNjlkaEFkQTRiNE0xLVlJU24yMVRMQ2NRd24wIn0.eyJleHAiOjE3MjcwODExNDEsImlhdCI6MTcyNzA3Mzk0MSwiYXV0aF90aW1lIjoxNzI3MDczOTQxLCJqdGkiOiI5YmFhOWM0OC1mMGYzLTRkOTQtOThlNS1iYTRiZjRmYjAwNmIiLCJpc3MiOiJodHRwczovL2tleWNsb2FrLnRlc3QubmdpYXBpLm5vL2F1dGgvcmVhbG1zL3RlbmFudC1nZW9odWItcHVibGljIiwiYXVkIjpbIm5naWxpdmUtbGthYi1ncmFmYW5hdjIiLCJnZW9odWItY2xpZW50IiwiY29waXQtb2F1dGgtcHJveHkiLCJuZ2lsaXZlLW5naS1ncmFmYW5hdjIiLCJhY2NvdW50Il0sInN1YiI6IjhhMDk4MjYwLTRlMzUtNDNkMC04MzYzLWRkOWFlZjc1ZTJkZiIsInR5cCI6IkJlYXJlciIsImF6cCI6ImZpZWx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2madR63lSds-R5QRBPdJ94BKU-_lPAMgOa_RtWwjAFAI8WJc1KO0nDDuKCSvvP3GKKr0yc0NuKFdnArflAhHprAc1HrNYuczUEEd13cezJnaj-q8Aq9JkCt1kHs5TehAvjnPOhoCsfG4tjCr7y8awt3hgZlA"
5+
# set token from https://app.test.fieldmanager.io/devloper
6+
token = "your_token"
67
fm.set_token(token)
78
fm.get_projects()
89
fm.set_project(
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from shapely.geometry import Polygon
2+
import requests
3+
import pandas as pd
4+
5+
NADAG_URL = "https://ogcapitest.ngu.no/rest/services/grunnundersokelser_utvidet"
6+
7+
8+
def get_nadag_geotekniskborehull():
9+
url = f"{NADAG_URL}/collections/geotekniskborehull/items"
10+
return url
11+
12+
13+
def _calculate_bbox_from_polygon(polygon: Polygon) -> str:
14+
"""
15+
Calculate the bounding box from a Polygon object.
16+
"""
17+
x_min, y_min, x_max, y_max = polygon.bounds
18+
return f"{x_min},{y_min},{x_max},{y_max}"
19+
20+
21+
def fetch_geotechnical_borehole_data(
22+
polygon_lon_lat: Polygon,
23+
bbox_crs="http://www.opengis.net/def/crs/OGC/1.3/CRS84",
24+
crs="http://www.opengis.net/def/crs/OGC/1.3/CRS84",
25+
filter_crs="http://www.opengis.net/def/crs/OGC/1.3/CRS84",
26+
filter_lang="cql2-text",
27+
limit=100,
28+
max_allowable_offset=0.05,
29+
offset=0,
30+
skip_geometry=False,
31+
):
32+
url = f"{NADAG_URL}/collections/geotekniskborehullunders/items"
33+
params = {
34+
"bbox": _calculate_bbox_from_polygon(polygon_lon_lat),
35+
"bbox-crs": bbox_crs,
36+
"crs": crs,
37+
"filter-crs": filter_crs,
38+
"filter-lang": filter_lang,
39+
"limit": limit,
40+
"maxAllowableOffset": max_allowable_offset,
41+
"offset": offset,
42+
"skipGeometry": str(skip_geometry).lower(),
43+
}
44+
45+
response = requests.get(url, params=params)
46+
response.raise_for_status()
47+
return response.json()
48+
49+
50+
url = f"{NADAG_URL}/collections/geotekniskborehullunders/items"
51+
bbox_crs = ("http://www.opengis.net/def/crs/OGC/1.3/CRS84",)
52+
crs = ("http://www.opengis.net/def/crs/OGC/1.3/CRS84",)
53+
filter_crs = ("http://www.opengis.net/def/crs/OGC/1.3/CRS84",)
54+
filter_lang = ("cql2-text",)
55+
limit = (100,)
56+
max_allowable_offset = (0.05,)
57+
offset = (0,)
58+
skip_geometry = False
59+
60+
61+
params = {
62+
"bbox": "10,59,10.02,59.2",
63+
"bbox-crs": bbox_crs,
64+
"crs": crs,
65+
"filter-crs": filter_crs,
66+
"filter-lang": filter_lang,
67+
"limit": limit,
68+
"maxAllowableOffset": max_allowable_offset,
69+
"offset": offset,
70+
"skipGeometry": str(skip_geometry).lower(),
71+
}
72+
73+
url_tolketlag = f"{NADAG_URL}/collections/geoteknisktolketlag/items"
74+
url_grunnvann = f"{NADAG_URL}/collections/grunnvanndata/items"
75+
# denne inneholder d meste av dataen
76+
url_geotekniskborehull = f"{NADAG_URL}/collections/geotekniskborehullunders/items"
77+
# url_geotekniskborehull= f"{NADAG_URL}/collections/geotekniskborehull/items"
78+
# mulig nederste er bedre her faktiks inneholder kvikkleirePåvisning, boretlengde etc
79+
# må sjekke om det er noe som mangler
80+
response = requests.get(url_geotekniskborehull, params=params)
81+
response.raise_for_status()
82+
data = response.json()
83+
features = data.get("features", [])
84+
data_geometry = features[0].get("geometry", {})
85+
data_prop = features[0].get("properties", {})
86+
method = data_prop.get("geotekniskMetode", None)
87+
methods = {"15": "metode-KombinasjonSondering"}
88+
method_data = data_prop[methods.get(method, "")]
89+
id = method_data[0]["title"]
90+
href = method_data[0]["href"]
91+
method_url = (
92+
f"{NADAG_URL}/collections/kombinasjonsonderingdata/items?kombinasjonSondering={id}"
93+
)
94+
r = requests.get(method_url)
95+
r.raise_for_status()
96+
97+
data_method = r.json()
98+
features_method = data_method.get("features", [])
99+
get_properties = [properties.get("properties", {}) for properties in features_method]
100+
dataframe = pd.DataFrame(get_properties)

src/field_manager_api/utils/automatic_datarapport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from selenium import webdriver
66
from selenium.webdriver.chrome.service import Service
77
from webdriver_manager.chrome import ChromeDriverManager
8-
from field_manager_api.methods.get_methods import get_methods, Method
8+
from field_manager_api.methods.get_methods import Method
99

1010

1111
class WordDocReport:

tests/test_fieldmanager_api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
from field_manager_api.field_manager import FieldManagerAPI
3+
4+
5+
def test_set_token_permission_error():
6+
fm = FieldManagerAPI()
7+
token = "your_invalid_token" # Use an invalid or expired token
8+
fm.set_token(token)
9+
10+
# Ensure that the PermissionError is raised when fm.get_projects is called
11+
with pytest.raises(
12+
PermissionError, match="Token authorization failed \(401 Unauthorized\)"
13+
):
14+
fm.get_projects()

0 commit comments

Comments
 (0)