sgf-parser 0.0.1a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Norwegian Geotechnical Institute (NGI)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,111 @@
1
+ Metadata-Version: 2.1
2
+ Name: sgf-parser
3
+ Version: 0.0.1a1
4
+ Summary: Parser for the Swedish Geotechnical Society / Svenska Geotekniska Föreningen (SGF) data format
5
+ Home-page: https://github.com/norwegian-geotechnical-institute/sgf-parser
6
+ License: MIT
7
+ Author: Jostein Leira
8
+ Author-email: jostein@leira.net
9
+ Maintainer: Jostein Leira
10
+ Maintainer-email: jostein@leira.net
11
+ Requires-Python: >=3.11,<4
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: GIS
19
+ Requires-Dist: pint (>=0.23,<0.24)
20
+ Requires-Dist: pydantic (>=2.6.3,<3.0.0)
21
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
22
+ Requires-Dist: types-python-dateutil (>=2.8.19.20240311,<3.0.0.0)
23
+ Project-URL: Repository, https://github.com/norwegian-geotechnical-institute/sgf-parser
24
+ Description-Content-Type: text/markdown
25
+
26
+ # sgf-parser
27
+
28
+ Parser for data from geotechnical field investigations in the data format
29
+ specified in Report 3:2012E from the Swedish Geotechnical Society /
30
+ [Svenska Geotekniska Föreningen](http://sgf.net/) (SGF).
31
+
32
+ This package is inspired by the [libsgfdata](https://github.com/emerald-geomodelling/libsgfdata)
33
+ package by [EMerald Geomodelling](https://www.emerald-geomodelling.com/).
34
+
35
+ Latest releases see [CHANGES.md](CHANGES.md)
36
+
37
+ # Installation (end user)
38
+
39
+ ```bash
40
+ pip install sgf-parser
41
+ ```
42
+
43
+ ## Basic usage
44
+
45
+ ```python
46
+ from sgf_parser import Parser
47
+
48
+ with open("c:/dev/sgf-parser/tests/data/cpt-test-3.cpt", "rt") as file:
49
+ # The test file only contains one method
50
+ [method] = Parser().parse(file)
51
+
52
+ print(repr(method))
53
+ # <MethodCPT CPT method_data=[<MethodCPTData 1.000>, <MethodCPTData 1.020>, <MethodCPTData 1.040>,
54
+ # <MethodCPTData 1.060>, <MethodCPTData 1.080>, <MethodCPTData 1.100>, <MethodCPTData 1.120>, ...,
55
+ # <MethodCPTData 24.940>, <MethodCPTData 24.960>, <MethodCPTData 24.980>]>
56
+
57
+
58
+ method.model_dump(exclude={'method_data'}, exclude_defaults=True)
59
+ # {'location_name': 'Test', 'project_number': '1234', 'method_type_string': '107A',
60
+ # 'conducted_at': datetime.datetime(2019, 9, 5, 11, 5), 'predrilling_depth': Decimal('1.00'),
61
+ # 'cone_reference': '5349', 'cone_area_ratio': Decimal('0.844'), 'sleeve_area_ratio': Decimal('0'),
62
+ # 'application_class_depth': <ApplicationClass.ONE: 1>, 'application_class_resistance': <ApplicationClass.ONE: 1>,
63
+ # 'application_class_friction': <ApplicationClass.ONE: 1>, 'application_class_pressure': <ApplicationClass.ONE: 1>,
64
+ # 'depth_top': Decimal('1.000'), 'depth_base': Decimal('24.980'), 'stopcode': 90}
65
+
66
+ method.stopcode
67
+ # 90
68
+
69
+ len(method.method_data)
70
+ # 1200
71
+
72
+ ```
73
+
74
+ # Getting Started developing
75
+
76
+ 1. Software dependencies
77
+
78
+ - Python 3.11 or higher
79
+ - Poetry
80
+ - ruff code formatter
81
+
82
+ 2. Clone this repository
83
+
84
+ 3. Install
85
+
86
+ `poetry install`
87
+
88
+
89
+ # Build and Test
90
+
91
+ Run in the project root folder:
92
+
93
+ poetry shell pytest
94
+
95
+ Build the package wheel:
96
+
97
+ poetry build
98
+
99
+ # Publish
100
+
101
+ # TODOs
102
+
103
+ - [ ] Implement everything
104
+ - [ ] Do the rest
105
+
106
+
107
+ # Contribute
108
+
109
+ Please start by adding an issue before submitting any pull requests.
110
+
111
+
@@ -0,0 +1,85 @@
1
+ # sgf-parser
2
+
3
+ Parser for data from geotechnical field investigations in the data format
4
+ specified in Report 3:2012E from the Swedish Geotechnical Society /
5
+ [Svenska Geotekniska Föreningen](http://sgf.net/) (SGF).
6
+
7
+ This package is inspired by the [libsgfdata](https://github.com/emerald-geomodelling/libsgfdata)
8
+ package by [EMerald Geomodelling](https://www.emerald-geomodelling.com/).
9
+
10
+ Latest releases see [CHANGES.md](CHANGES.md)
11
+
12
+ # Installation (end user)
13
+
14
+ ```bash
15
+ pip install sgf-parser
16
+ ```
17
+
18
+ ## Basic usage
19
+
20
+ ```python
21
+ from sgf_parser import Parser
22
+
23
+ with open("c:/dev/sgf-parser/tests/data/cpt-test-3.cpt", "rt") as file:
24
+ # The test file only contains one method
25
+ [method] = Parser().parse(file)
26
+
27
+ print(repr(method))
28
+ # <MethodCPT CPT method_data=[<MethodCPTData 1.000>, <MethodCPTData 1.020>, <MethodCPTData 1.040>,
29
+ # <MethodCPTData 1.060>, <MethodCPTData 1.080>, <MethodCPTData 1.100>, <MethodCPTData 1.120>, ...,
30
+ # <MethodCPTData 24.940>, <MethodCPTData 24.960>, <MethodCPTData 24.980>]>
31
+
32
+
33
+ method.model_dump(exclude={'method_data'}, exclude_defaults=True)
34
+ # {'location_name': 'Test', 'project_number': '1234', 'method_type_string': '107A',
35
+ # 'conducted_at': datetime.datetime(2019, 9, 5, 11, 5), 'predrilling_depth': Decimal('1.00'),
36
+ # 'cone_reference': '5349', 'cone_area_ratio': Decimal('0.844'), 'sleeve_area_ratio': Decimal('0'),
37
+ # 'application_class_depth': <ApplicationClass.ONE: 1>, 'application_class_resistance': <ApplicationClass.ONE: 1>,
38
+ # 'application_class_friction': <ApplicationClass.ONE: 1>, 'application_class_pressure': <ApplicationClass.ONE: 1>,
39
+ # 'depth_top': Decimal('1.000'), 'depth_base': Decimal('24.980'), 'stopcode': 90}
40
+
41
+ method.stopcode
42
+ # 90
43
+
44
+ len(method.method_data)
45
+ # 1200
46
+
47
+ ```
48
+
49
+ # Getting Started developing
50
+
51
+ 1. Software dependencies
52
+
53
+ - Python 3.11 or higher
54
+ - Poetry
55
+ - ruff code formatter
56
+
57
+ 2. Clone this repository
58
+
59
+ 3. Install
60
+
61
+ `poetry install`
62
+
63
+
64
+ # Build and Test
65
+
66
+ Run in the project root folder:
67
+
68
+ poetry shell pytest
69
+
70
+ Build the package wheel:
71
+
72
+ poetry build
73
+
74
+ # Publish
75
+
76
+ # TODOs
77
+
78
+ - [ ] Implement everything
79
+ - [ ] Do the rest
80
+
81
+
82
+ # Contribute
83
+
84
+ Please start by adding an issue before submitting any pull requests.
85
+
@@ -0,0 +1,78 @@
1
+ [tool.black]
2
+ line-length = 120
3
+ exclude = '''
4
+ /(
5
+ \.git
6
+ | venv
7
+ | \.venv
8
+ | env
9
+ | \.env
10
+ | _build
11
+ | build
12
+ | dist
13
+ )/
14
+ '''
15
+
16
+ [tool.poetry]
17
+ name = "sgf-parser"
18
+ version = "0.0.1a1"
19
+ description = "Parser for the Swedish Geotechnical Society / Svenska Geotekniska Föreningen (SGF) data format"
20
+ license = "MIT"
21
+ authors = ["Jostein Leira <jostein@leira.net>"]
22
+ maintainers = ["Jostein Leira <jostein@leira.net>"]
23
+ readme = "README.md"
24
+ homepage = "https://github.com/norwegian-geotechnical-institute/sgf-parser"
25
+ repository = "https://github.com/norwegian-geotechnical-institute/sgf-parser"
26
+ classifiers = [
27
+ # "Development Status :: 5 - Production/Stable",
28
+ # "Development Status :: 4 - Beta",
29
+ "Development Status :: 3 - Alpha",
30
+ "Operating System :: OS Independent",
31
+ "Programming Language :: Python :: 3",
32
+ "Topic :: Scientific/Engineering :: GIS",
33
+ ]
34
+ packages = [
35
+ { include = "sgf_parser", from="src" },
36
+ ]
37
+
38
+
39
+ [tool.ruff]
40
+ line-length = 120
41
+ src = ["src", "tests"]
42
+
43
+ [tool.ruff.lint.per-file-ignores]
44
+ "__init__.py" = ["F401"]
45
+
46
+ [tool.mypy]
47
+ plugins = [
48
+ "pydantic.mypy"
49
+ ]
50
+
51
+ follow_imports = "skip"
52
+ warn_redundant_casts = true
53
+ warn_unused_ignores = true
54
+ disallow_any_generics = true
55
+ check_untyped_defs = true
56
+ no_implicit_reexport = false
57
+
58
+
59
+ [tool.poetry.dependencies]
60
+ python = ">=3.11,<4"
61
+ pydantic = "^2.6.3"
62
+ python-dateutil = "^2.9.0.post0"
63
+ types-python-dateutil = "^2.8.19.20240311"
64
+ pint = "^0.23"
65
+
66
+
67
+ [tool.poetry.group.dev.dependencies]
68
+ pytest = "*"
69
+ pytest-cov = "*"
70
+ mypy = "*"
71
+ bandit = "*"
72
+ safety = "*"
73
+ pip-licenses = "*"
74
+ ruff = "*"
75
+
76
+ [build-system]
77
+ requires = ["poetry-core>=1.0.0"]
78
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1 @@
1
+ from sgf_parser.parser import Parser
@@ -0,0 +1,44 @@
1
+ """
2
+ Datetime utilities for converting to and from datetime.datetime, json, naive and time zone aware
3
+ """
4
+
5
+ from datetime import datetime, time
6
+
7
+ import dateutil.parser
8
+
9
+
10
+ def convert_str_to_datetime(date_string: str | None) -> datetime | None:
11
+ """
12
+ Guess what datetime is in the string
13
+ """
14
+ if not date_string or not isinstance(date_string, str):
15
+ return None
16
+
17
+ try:
18
+ # The ISO 8601 format specifies that the time portion is separated from the date portion by a `T` character.
19
+ if len(date_string) > 8 and "T" in date_string or len(date_string) == 8:
20
+ return dateutil.parser.isoparse(date_string)
21
+ except ValueError:
22
+ pass
23
+
24
+ try:
25
+ return dateutil.parser.parse(date_string, parserinfo=dateutil.parser.parserinfo(yearfirst=True, dayfirst=True))
26
+ except ValueError:
27
+ pass
28
+
29
+ return None
30
+
31
+
32
+ def convert_str_to_time(time_string: str | None) -> time | None:
33
+ """
34
+ Guess what time is in the string
35
+ """
36
+ if not time_string:
37
+ return None
38
+
39
+ try:
40
+ return dateutil.parser.parse(f"1970-01-01 {time_string}").time()
41
+ except ValueError:
42
+ pass
43
+
44
+ return None
@@ -0,0 +1,9 @@
1
+ from sgf_parser.models.method_type import MethodType
2
+
3
+ from sgf_parser.models.types import StopCode, ParseState
4
+ from sgf_parser.models.method import Method, MethodData
5
+ from sgf_parser.models.method_cpt import MethodCPT, MethodCPTData
6
+ from sgf_parser.models.method_rp import MethodRP, MethodRPData
7
+ from sgf_parser.models.method_srs import MethodSRS, MethodSRSData
8
+ from sgf_parser.models.method_svt import MethodSVT, MethodSVTData
9
+ from sgf_parser.models.method_tot import MethodTOT, MethodTOTData