opensampl 0.2.0__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,165 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ .idea/
161
+ .idea/*
162
+ */.idea/*
163
+ .DS_Store
164
+
165
+ pypirc.cfg
@@ -0,0 +1,222 @@
1
+ Metadata-Version: 2.4
2
+ Name: opensampl
3
+ Version: 0.2.0
4
+ Summary: Python tools for adding clock data to a timescale db.
5
+ Author-email: Midgie MacFarland <macfarlandmj@ornl.gov>, Cory Watson <watsoncl1@ornl.gov>, Joshua Grant <grantjn@ornl.gov>
6
+ Requires-Python: <3.13,>=3.9
7
+ Requires-Dist: allantools
8
+ Requires-Dist: astor
9
+ Requires-Dist: click<9,>=8.0.0
10
+ Requires-Dist: geoalchemy2==0.16.0
11
+ Requires-Dist: jinja2==3.1.6
12
+ Requires-Dist: libcst
13
+ Requires-Dist: loguru<0.8,>=0.7.0
14
+ Requires-Dist: numpy<2,>=1.26.4
15
+ Requires-Dist: pandas<3,>=2.2.1
16
+ Requires-Dist: psycopg2-binary<3,>=2.9.0
17
+ Requires-Dist: pydantic<3,>=2.10.3
18
+ Requires-Dist: python-dotenv
19
+ Requires-Dist: python-multipart<0.0.21,>=0.0.20
20
+ Requires-Dist: pytz~=2024.1
21
+ Requires-Dist: pyyaml<7,>=6.0.0
22
+ Requires-Dist: requests<3,>=2.31.0
23
+ Requires-Dist: sqlalchemy<3,>=2.0.39
24
+ Requires-Dist: tqdm<5,>=4.66.2
25
+ Provides-Extra: server
26
+ Description-Content-Type: text/markdown
27
+
28
+ # OpenSAMPL
29
+
30
+ ### (**O**pen **S**ynchronization **A**nalytics and **M**onitoring **PL**atform)
31
+
32
+ python tools for adding clock data to a timescale db.
33
+
34
+ ## CLI TOOL
35
+
36
+ ### Installation
37
+
38
+ 1. Ensure you have Python 3.9 or higher installed
39
+ 2. Pip install the latest version of opensampl:
40
+ ```bash
41
+ pip install opensampl==0.2.0
42
+ ```
43
+
44
+ ### Environment Setup
45
+
46
+ The tool requires several environment variables. Create a `.env` file in your project root:
47
+
48
+ When routing through a backend:
49
+ ```bash
50
+ ROUTE_TO_BACKEND=true # Set to true if using backend service
51
+ BACKEND_URL=http://localhost:8000 # Only needed if ROUTE_TO_BACKEND is true
52
+
53
+ # Archive configuration
54
+ ARCHIVE_PATH=/path/to/archive # Where processed files are stored
55
+ ```
56
+ When directly accessing db:
57
+ ```bash
58
+ # Database connection
59
+ DATABASE_URL=postgresql://<user>:<password>@<host>:<port>/<database>
60
+
61
+ # Archive configuration
62
+ ARCHIVE_PATH=/path/to/archive # Where processed files are stored
63
+ ```
64
+
65
+ ### Basic Usage
66
+
67
+ The CLI tool provides several commands. You can use `opensampl --help` (or, any deeper `opensampl [command] --help`) to get details
68
+
69
+ #### Load Probe Data
70
+
71
+ Load data from ADVA probes:
72
+
73
+ ```bash
74
+ # Load single file
75
+ opensampl load probe adva path/to/file.txt.gz
76
+
77
+ # Load directory of files
78
+ opensampl load probe adva path/to/directory/
79
+ ```
80
+ ADVA probes have all their metadata and their time data in each file, so no need to use the `-m` or `-t` options, though if you want to skip loading one or the other it becomes useful!
81
+
82
+ options:
83
+ - `--metadata` (`-m`): Only load probe metadata
84
+ - `--time-data` (`-t`): Only load time series data
85
+ - `--no-archive` (`-n`): Don't archive processed files
86
+ - `--archive-path` (`-a`): Override default archive directory
87
+ - `--max-workers` (`-w`): Maximum number of worker threads (default: 4)
88
+ - `--chunk-size` (`-c`): Number of time data entries per batch (default: 10000)
89
+
90
+ #### Load Direct Table Data
91
+
92
+ Load data directly into a database table. Format can be yaml or json. Can be a list of dictionaries or a single dictionary.
93
+
94
+ you do not have to specify schema, is assumed to be castdb.
95
+
96
+ The --if-exists option controls how to handle conflicts:
97
+ - update: Only update fields that are provided and non-default (default)
98
+ - error: Raise an error if entry exists
99
+ - replace: Replace all non-primary-key fields with new values
100
+ - ignore: Skip if entry exists
101
+
102
+ ```bash
103
+ opensampl load table table_name path/to/data.yaml
104
+ ```
105
+
106
+ So, you can do things like the following
107
+ ```bash
108
+ opensampl load table locations --if-exists replace updated_location.yaml
109
+ ```
110
+ Where this is the updated_location
111
+ ```yaml
112
+ name: EPB Chattanooga
113
+ lat: 35.9311256
114
+ lon: -84.3292469
115
+ ```
116
+ And it will overwrite the existing entry for EPB Chattanooga, or create a new one if it doesn't exist yet.
117
+
118
+
119
+ ### View Configuration
120
+
121
+ Display current environment configuration:
122
+
123
+ ```bash
124
+ # Show all variables
125
+ poetry run opensampl config show
126
+
127
+ # Show with descriptions
128
+ poetry run opensampl config show --explain
129
+
130
+ # Show specific variable
131
+ poetry run opensampl config show --var DATABASE_URL
132
+ ```
133
+
134
+ ### Set Configuration
135
+
136
+ Update environment variables:
137
+
138
+ ```bash
139
+ poetry run opensampl config set VARIABLE_NAME value
140
+ ```
141
+
142
+ ## File Format Support
143
+
144
+ The tool currently supports ADVA probe data files with the following naming convention:
145
+ `<ip_address>CLOCK_PROBE-<probe_id>-YYYY-MM-DD-HH-MM-SS.txt.gz`
146
+
147
+ Example: `10.0.0.121CLOCK_PROBE-1-1-2024-01-02-18-24-56.txt.gz`
148
+
149
+ # CAST Database Schema Documentation
150
+
151
+ ## castdb.locations
152
+ Stores geographic locations with their coordinates and metadata. Supports both 2D and 3D point geometries.
153
+
154
+ ```yaml
155
+ name: "Lab A" # Unique name for the location
156
+ lat: 35.93 # Latitude coordinate
157
+ lon: -84.31 # Longitude coordinate
158
+ z: 100 # Optional elevation in meters
159
+ projection: 4326 # Optional SRID/projection (defaults to 4326/WGS84)
160
+ public: true # Optional boolean for public visibility
161
+ ```
162
+
163
+ ## castdb.test_metadata
164
+ Tracks testing periods and experiments with start and end timestamps.
165
+
166
+ ```yaml
167
+ name: "Holdover Test 1" # Unique name for the test
168
+ start_date: "2024-01-01T00:00:00" # Test start timestamp
169
+ end_date: "2024-01-07T00:00:00" # Test end timestamp
170
+ ```
171
+
172
+ ## castdb.probe_metadata
173
+ Contains information about timing probes, including their network location and associated metadata. Insertion handled by `opensampl load probe`.
174
+
175
+ ```yaml
176
+ probe_id: "1-1" # Probe identifier
177
+ ip_address: "10.0.0.121" # IP address of the probe
178
+ vendor: "ADVA" # Vendor type
179
+ model: "OSA 5422" # Model number
180
+ name: "GMC1" # Human-readable name
181
+ public: true # Optional boolean for public visibility
182
+ location_uiid: "123e4567-e89b-12d3-a456-426614174000" # Optional reference to location
183
+ test_uiid: "123e4567-e89b-12d3-a456-426614174001" # Optional reference to test
184
+ ```
185
+
186
+ ## castdb.probe_data
187
+ Time series data from probes, storing timestamps and measured values. Insertion handled by `opensampl load probe`.
188
+ ```yaml
189
+ time: "2024-01-01T00:00:00" # Timestamp of measurement
190
+ probe_uuid: "123e4567-e89b-12d3-a456-426614174000" # Reference to probe
191
+ value: 1.234e-09 # Measured value
192
+ ```
193
+
194
+ ## castdb.adva_metadata
195
+ ADVA-specific configuration and status information for probes. Insertion handled by `opensampl load probe`.
196
+
197
+ ```yaml
198
+ probe_uuid: "123e4567-e89b-12d3-a456-426614174000" # Reference to probe
199
+ type: "Phase" # Measurement type
200
+ start: "2024-01-01T00:00:00" # Start timestamp
201
+ frequency: 1 # Sampling frequency
202
+ timemultiplier: 1 # Time multiplier
203
+ multiplier: 1 # Value multiplier
204
+ title: "ClockProbe1" # Probe title
205
+ adva_probe: "ClockProbe" # Probe type
206
+ adva_reference: "GPS" # Reference source
207
+ adva_reference_expected_ql: "QL-NONE" # Expected quality level
208
+ adva_source: "TimeClock" # Source type
209
+ adva_direction: "NA" # Direction
210
+ adva_version: 1.0 # Version number
211
+ adva_status: "RUNNING" # Operating status
212
+ adva_mtie_mask: "G823-PDH" # MTIE mask type
213
+ adva_mask_margin: 0 # Mask margin
214
+ ```
215
+
216
+ ## Notes
217
+
218
+ - All tables use UUIDs as primary keys which are automatically generated.
219
+ - Table relationships are maintained through UUID references
220
+ - Geographic coordinates use WGS84 projection (SRID 4326) by default
221
+ - Boolean fields (public) are optional and can be null
222
+
@@ -0,0 +1,195 @@
1
+ # OpenSAMPL
2
+
3
+ ### (**O**pen **S**ynchronization **A**nalytics and **M**onitoring **PL**atform)
4
+
5
+ python tools for adding clock data to a timescale db.
6
+
7
+ ## CLI TOOL
8
+
9
+ ### Installation
10
+
11
+ 1. Ensure you have Python 3.9 or higher installed
12
+ 2. Pip install the latest version of opensampl:
13
+ ```bash
14
+ pip install opensampl==0.2.0
15
+ ```
16
+
17
+ ### Environment Setup
18
+
19
+ The tool requires several environment variables. Create a `.env` file in your project root:
20
+
21
+ When routing through a backend:
22
+ ```bash
23
+ ROUTE_TO_BACKEND=true # Set to true if using backend service
24
+ BACKEND_URL=http://localhost:8000 # Only needed if ROUTE_TO_BACKEND is true
25
+
26
+ # Archive configuration
27
+ ARCHIVE_PATH=/path/to/archive # Where processed files are stored
28
+ ```
29
+ When directly accessing db:
30
+ ```bash
31
+ # Database connection
32
+ DATABASE_URL=postgresql://<user>:<password>@<host>:<port>/<database>
33
+
34
+ # Archive configuration
35
+ ARCHIVE_PATH=/path/to/archive # Where processed files are stored
36
+ ```
37
+
38
+ ### Basic Usage
39
+
40
+ The CLI tool provides several commands. You can use `opensampl --help` (or, any deeper `opensampl [command] --help`) to get details
41
+
42
+ #### Load Probe Data
43
+
44
+ Load data from ADVA probes:
45
+
46
+ ```bash
47
+ # Load single file
48
+ opensampl load probe adva path/to/file.txt.gz
49
+
50
+ # Load directory of files
51
+ opensampl load probe adva path/to/directory/
52
+ ```
53
+ ADVA probes have all their metadata and their time data in each file, so no need to use the `-m` or `-t` options, though if you want to skip loading one or the other it becomes useful!
54
+
55
+ options:
56
+ - `--metadata` (`-m`): Only load probe metadata
57
+ - `--time-data` (`-t`): Only load time series data
58
+ - `--no-archive` (`-n`): Don't archive processed files
59
+ - `--archive-path` (`-a`): Override default archive directory
60
+ - `--max-workers` (`-w`): Maximum number of worker threads (default: 4)
61
+ - `--chunk-size` (`-c`): Number of time data entries per batch (default: 10000)
62
+
63
+ #### Load Direct Table Data
64
+
65
+ Load data directly into a database table. Format can be yaml or json. Can be a list of dictionaries or a single dictionary.
66
+
67
+ you do not have to specify schema, is assumed to be castdb.
68
+
69
+ The --if-exists option controls how to handle conflicts:
70
+ - update: Only update fields that are provided and non-default (default)
71
+ - error: Raise an error if entry exists
72
+ - replace: Replace all non-primary-key fields with new values
73
+ - ignore: Skip if entry exists
74
+
75
+ ```bash
76
+ opensampl load table table_name path/to/data.yaml
77
+ ```
78
+
79
+ So, you can do things like the following
80
+ ```bash
81
+ opensampl load table locations --if-exists replace updated_location.yaml
82
+ ```
83
+ Where this is the updated_location
84
+ ```yaml
85
+ name: EPB Chattanooga
86
+ lat: 35.9311256
87
+ lon: -84.3292469
88
+ ```
89
+ And it will overwrite the existing entry for EPB Chattanooga, or create a new one if it doesn't exist yet.
90
+
91
+
92
+ ### View Configuration
93
+
94
+ Display current environment configuration:
95
+
96
+ ```bash
97
+ # Show all variables
98
+ poetry run opensampl config show
99
+
100
+ # Show with descriptions
101
+ poetry run opensampl config show --explain
102
+
103
+ # Show specific variable
104
+ poetry run opensampl config show --var DATABASE_URL
105
+ ```
106
+
107
+ ### Set Configuration
108
+
109
+ Update environment variables:
110
+
111
+ ```bash
112
+ poetry run opensampl config set VARIABLE_NAME value
113
+ ```
114
+
115
+ ## File Format Support
116
+
117
+ The tool currently supports ADVA probe data files with the following naming convention:
118
+ `<ip_address>CLOCK_PROBE-<probe_id>-YYYY-MM-DD-HH-MM-SS.txt.gz`
119
+
120
+ Example: `10.0.0.121CLOCK_PROBE-1-1-2024-01-02-18-24-56.txt.gz`
121
+
122
+ # CAST Database Schema Documentation
123
+
124
+ ## castdb.locations
125
+ Stores geographic locations with their coordinates and metadata. Supports both 2D and 3D point geometries.
126
+
127
+ ```yaml
128
+ name: "Lab A" # Unique name for the location
129
+ lat: 35.93 # Latitude coordinate
130
+ lon: -84.31 # Longitude coordinate
131
+ z: 100 # Optional elevation in meters
132
+ projection: 4326 # Optional SRID/projection (defaults to 4326/WGS84)
133
+ public: true # Optional boolean for public visibility
134
+ ```
135
+
136
+ ## castdb.test_metadata
137
+ Tracks testing periods and experiments with start and end timestamps.
138
+
139
+ ```yaml
140
+ name: "Holdover Test 1" # Unique name for the test
141
+ start_date: "2024-01-01T00:00:00" # Test start timestamp
142
+ end_date: "2024-01-07T00:00:00" # Test end timestamp
143
+ ```
144
+
145
+ ## castdb.probe_metadata
146
+ Contains information about timing probes, including their network location and associated metadata. Insertion handled by `opensampl load probe`.
147
+
148
+ ```yaml
149
+ probe_id: "1-1" # Probe identifier
150
+ ip_address: "10.0.0.121" # IP address of the probe
151
+ vendor: "ADVA" # Vendor type
152
+ model: "OSA 5422" # Model number
153
+ name: "GMC1" # Human-readable name
154
+ public: true # Optional boolean for public visibility
155
+ location_uiid: "123e4567-e89b-12d3-a456-426614174000" # Optional reference to location
156
+ test_uiid: "123e4567-e89b-12d3-a456-426614174001" # Optional reference to test
157
+ ```
158
+
159
+ ## castdb.probe_data
160
+ Time series data from probes, storing timestamps and measured values. Insertion handled by `opensampl load probe`.
161
+ ```yaml
162
+ time: "2024-01-01T00:00:00" # Timestamp of measurement
163
+ probe_uuid: "123e4567-e89b-12d3-a456-426614174000" # Reference to probe
164
+ value: 1.234e-09 # Measured value
165
+ ```
166
+
167
+ ## castdb.adva_metadata
168
+ ADVA-specific configuration and status information for probes. Insertion handled by `opensampl load probe`.
169
+
170
+ ```yaml
171
+ probe_uuid: "123e4567-e89b-12d3-a456-426614174000" # Reference to probe
172
+ type: "Phase" # Measurement type
173
+ start: "2024-01-01T00:00:00" # Start timestamp
174
+ frequency: 1 # Sampling frequency
175
+ timemultiplier: 1 # Time multiplier
176
+ multiplier: 1 # Value multiplier
177
+ title: "ClockProbe1" # Probe title
178
+ adva_probe: "ClockProbe" # Probe type
179
+ adva_reference: "GPS" # Reference source
180
+ adva_reference_expected_ql: "QL-NONE" # Expected quality level
181
+ adva_source: "TimeClock" # Source type
182
+ adva_direction: "NA" # Direction
183
+ adva_version: 1.0 # Version number
184
+ adva_status: "RUNNING" # Operating status
185
+ adva_mtie_mask: "G823-PDH" # MTIE mask type
186
+ adva_mask_margin: 0 # Mask margin
187
+ ```
188
+
189
+ ## Notes
190
+
191
+ - All tables use UUIDs as primary keys which are automatically generated.
192
+ - Table relationships are maintained through UUID references
193
+ - Geographic coordinates use WGS84 projection (SRID 4326) by default
194
+ - Boolean fields (public) are optional and can be null
195
+
@@ -0,0 +1,4 @@
1
+ """
2
+ Adding this to ensure backwards compatibility with older versions of opensampl where orm import was:
3
+ from opensampl import orm
4
+ """