plantmap-sv 0.0.0-stage → 0.0.10
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.
- package/.github/workflows/test.yml +25 -0
- package/.prettierignore +9 -0
- package/LICENSE +5 -0
- package/README.md +75 -2
- package/assets/plantmap-sv-v0.0.08-maxson.png +0 -0
- package/bin/plantmap-sv.js +5 -0
- package/docs/CHANGELOG.md +119 -0
- package/docs/windows.md +15 -0
- package/emails/brower-daily.ps1 +107 -0
- package/emails/presson-daily.ps1 +107 -0
- package/emails/presson-daily.py +188 -0
- package/emails/presson-daily.sh +38 -0
- package/emails/t-weekly.sh +46 -0
- package/eslint.config.js +50 -0
- package/examples/email.sh +7 -0
- package/examples/geo.ts +22 -0
- package/package.json +88 -5
- package/prettier.config.js +12 -0
- package/pyproject.toml +16 -0
- package/queries/presson-daily-tags.txt +4 -0
- package/queries/t-weekly-biorem-tags.txt +1 -0
- package/queries/t-weekly-scan-tags.txt +1 -0
- package/queries/t-weekly-tags.txt +1 -0
- package/scripts/check-cesium-assets.mjs +30 -0
- package/scripts/copy-cesium.mjs +231 -0
- package/scripts/install-priveleged.cmd +24 -0
- package/scripts/setup-creds.cmd +12 -0
- package/scripts/setup-creds.js +49 -0
- package/scripts/setup.sh +10 -0
- package/scripts/start-plantmap.cmd +57 -0
- package/src/app.d.ts +17 -0
- package/src/app.html +12 -0
- package/src/env.ts +13 -0
- package/src/hooks.server.ts +13 -0
- package/src/lib/assets/favicon.svg +1 -0
- package/src/lib/cesium/layers.ts +100 -0
- package/src/lib/cesium/navigation.ts +111 -0
- package/src/lib/cesium/syncSensors.ts +86 -0
- package/src/lib/cli/config.ts +16 -0
- package/src/lib/cli/download.ts +255 -0
- package/src/lib/cli/email.ts +128 -0
- package/src/lib/cli/helpers/errors.ts +57 -0
- package/src/lib/cli/index.ts +84 -0
- package/src/lib/cli/plot.ts +202 -0
- package/src/lib/cli/report.ts +61 -0
- package/src/lib/cli/secret.ts +16 -0
- package/src/lib/cli/setup/site.ts +60 -0
- package/src/lib/cli/setup.ts +205 -0
- package/src/lib/cli/setup.ts.rising +23 -0
- package/src/lib/cli/start.ts +120 -0
- package/src/lib/cli/start.ts.bak +75 -0
- package/src/lib/cli/status.ts +53 -0
- package/src/lib/components/CesiumViewport.svelte +384 -0
- package/src/lib/components/HoverTooltip.svelte +25 -0
- package/src/lib/components/NavigationHUD.svelte +347 -0
- package/src/lib/components/NavigationHUD.svelte.bak +223 -0
- package/src/lib/components/PlotHUD.svelte +242 -0
- package/src/lib/components/TelemetryHUD.svelte +80 -0
- package/src/lib/components/TelemetryHUD.svelte.bak +76 -0
- package/src/lib/components/ViewportDebugger.svelte +48 -0
- package/src/lib/database/build.spec.ts +50 -0
- package/src/lib/database/build.ts +87 -0
- package/src/lib/database/context.ts +1 -0
- package/src/lib/database/crud.spec.ts +163 -0
- package/src/lib/database/crud.ts +159 -0
- package/src/lib/database/index.ts +13 -0
- package/src/lib/database/time.ts +34 -0
- package/src/lib/database/types.ts +43 -0
- package/src/lib/download/context.ts +16 -0
- package/src/lib/download/csv.ts +78 -0
- package/src/lib/download/json.ts +8 -0
- package/src/lib/download/prepare.ts +60 -0
- package/src/lib/download/service.ts +108 -0
- package/src/lib/download/svg.ts +60 -0
- package/src/lib/email/index.ts +146 -0
- package/src/lib/email/index.ts.bak +91 -0
- package/src/lib/email/secret.spec.ts +11 -0
- package/src/lib/email/send-attachment.py +158 -0
- package/src/lib/email/settings.ts +41 -0
- package/src/lib/email/types.ts +23 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/plantmap-sv/bootstrap.ts +28 -0
- package/src/lib/plantmap-sv/config.ts +81 -0
- package/src/lib/plantmap-sv/env.ts +1 -0
- package/src/lib/plantmap-sv/secret.ts +30 -0
- package/src/lib/plot/chart-options.ts +109 -0
- package/src/lib/plot/chart-options.ts.bak +87 -0
- package/src/lib/plot/context.ts +38 -0
- package/src/lib/plot/diagnostic.ts +247 -0
- package/src/lib/plot/prepare.ts +126 -0
- package/src/lib/plot/resolve-time.ts +31 -0
- package/src/lib/plot/sampling.ts +86 -0
- package/src/lib/plot/series.ts +23 -0
- package/src/lib/plot/time-range.ts +131 -0
- package/src/lib/plot/types.ts +36 -0
- package/src/lib/plot/units.ts +126 -0
- package/src/lib/plot/url.ts +183 -0
- package/src/lib/plot/validation.ts +1 -0
- package/src/lib/report/config.ts +135 -0
- package/src/lib/report/runner.ts +101 -0
- package/src/lib/report/types.ts +25 -0
- package/src/lib/server/config.ts +15 -0
- package/src/lib/server/eds/auth.ts +99 -0
- package/src/lib/server/eds/client.ts +93 -0
- package/src/lib/server/eds/example.txt +25 -0
- package/src/lib/server/eds/factory.ts +36 -0
- package/src/lib/server/eds/helpers.ts +9 -0
- package/src/lib/server/eds/parsers/common.ts +145 -0
- package/src/lib/server/eds/parsers/points.ts +52 -0
- package/src/lib/server/eds/parsers/tabular.ts +70 -0
- package/src/lib/server/eds/parsers/tags.ts +99 -0
- package/src/lib/server/eds/requests/points.ts +99 -0
- package/src/lib/server/eds/requests/tabular.ts +217 -0
- package/src/lib/server/eds/tag-registration-db/types.ts +1 -0
- package/src/lib/server/eds/types.ts +40 -0
- package/src/lib/server/telemetry/persistence.ts +68 -0
- package/src/lib/server/telemetry/service.ts +226 -0
- package/src/lib/status/probe.ts +82 -0
- package/src/lib/status/types.ts +20 -0
- package/src/lib/stores/telemetry-client.svelte.ts +69 -0
- package/src/lib/tags/parsers.ts +19 -0
- package/src/lib/telemetry/types.ts +21 -0
- package/src/lib/utils/launch.ts +43 -0
- package/src/lib/validation/port.ts +9 -0
- package/src/lib/vitest-examples/Welcome.svelte +8 -0
- package/src/lib/vitest-examples/Welcome.svelte.spec.ts +15 -0
- package/src/lib/vitest-examples/greet.spec.ts +8 -0
- package/src/lib/vitest-examples/greet.ts +3 -0
- package/src/routes/+layout.svelte +9 -0
- package/src/routes/+page.server.ts +10 -0
- package/src/routes/+page.svelte +27 -0
- package/src/routes/api/debug/tabular/+server.ts +124 -0
- package/src/routes/api/debug/test-eds/+server.ts +79 -0
- package/src/routes/api/download/+server.ts +183 -0
- package/src/routes/api/plot/+server.ts +64 -0
- package/src/routes/api/plot/+server.ts.bak +96 -0
- package/src/routes/api/status/+server.ts +40 -0
- package/src/routes/api/telemetry-history/+server.ts +51 -0
- package/src/routes/api/telemetry-live/+server.ts +11 -0
- package/src/routes/api/telemetry-live/stream/+server.ts +83 -0
- package/src/routes/layout.css +3 -0
- package/src/routes/plot/+page.svelte +591 -0
- package/src/routes/plot/plot.css +175 -0
- package/static/config/groups.json +21 -0
- package/static/config/sensors.json +871 -0
- package/static/config/sensors.json.do.bak +706 -0
- package/static/geojson/plant.geojson +9 -0
- package/static/geojson/plant.geojson.bak +9 -0
- package/static/robots.txt +3 -0
- package/tsconfig.json +10 -0
- package/vite.config.ts +68 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v5
|
|
13
|
+
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: 24
|
|
17
|
+
cache: npm
|
|
18
|
+
|
|
19
|
+
- run: npm ci
|
|
20
|
+
- run: npm run check
|
|
21
|
+
- run: npm run test
|
|
22
|
+
- run: npx playwright install --with-deps chromium
|
|
23
|
+
- run: npm run test:browser
|
|
24
|
+
- run: npm run lint
|
|
25
|
+
- run: npm run build
|
package/.prettierignore
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright 2026 George Clayton Bennett
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
+
|
|
5
|
+
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
-
#
|
|
1
|
+
# plantmap-sv
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Cesium-based Svelte map app for visualizing geolocated live data from the Emerson Ovation EDS SOAP API.
|
|
4
|
+
|
|
5
|
+
City of Memphis Wastewater is now self-hosting an instance of plantmap-sv, for T.E Maxson Wastewater Treatment Facility.
|
|
6
|
+
|
|
7
|
+
Instead of blocky, proprietary SCADA graphics that are limited to a few expensive workstations, we can now give operators something intuitive that they can see on their phones and laptops.
|
|
8
|
+
|
|
9
|
+
Emerson Ovation users, notice that the project is free, open-source, permissively licensed, and configurable.
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
Setup config and secret values via CLI prompt, using `memphis-config` and `memphis-secret` libraries.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/City-of-Memphis-Wastewater/plantmap-sv.git
|
|
17
|
+
cd plantmap-sv
|
|
18
|
+
npm install
|
|
19
|
+
npm link
|
|
20
|
+
npx plantmap-sv setup
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Plant Configuration
|
|
24
|
+
|
|
25
|
+
Edit the `static/config/sensors.json` file to reflect the sensor location and Ovation IDCS values for your plant.
|
|
26
|
+
|
|
27
|
+
Your Emerson Ovation EDS machine must expose the EDS SOAP API.
|
|
28
|
+
|
|
29
|
+
## Development
|
|
30
|
+
|
|
31
|
+
Run the SvelteKit development server:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm run dev
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Production
|
|
38
|
+
|
|
39
|
+
Build the application:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm run build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Start the production server:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
node build
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The production server listens on the port configured by the SvelteKit/Node adapter.
|
|
52
|
+
|
|
53
|
+
Bun may also be used as an alternative JavaScript runtime/package manager where available.
|
|
54
|
+
|
|
55
|
+
The application does not require Bun.
|
|
56
|
+
|
|
57
|
+
## Dependencies
|
|
58
|
+
|
|
59
|
+
- cesium
|
|
60
|
+
- memphis-settings: https://github.com/City-of-Memphis-Wastewater/memphis-settings
|
|
61
|
+
- three
|
|
62
|
+
- three-geo
|
|
63
|
+
- proj4
|
|
64
|
+
- zod
|
|
65
|
+
|
|
66
|
+
## Screenshot
|
|
67
|
+
|
|
68
|
+
Self-hosted and configured instance of `plantmap-sv` for T.E. Maxson Wastewater Treatment Plant in Memphis, Tennessee
|
|
69
|
+
|
|
70
|
+
<p align="center">
|
|
71
|
+
<img src="https://raw.githubusercontent.com/City-of-Memphis-Wastewater/plantmap-sv/main/assets/plantmap-sv-v0.0.08-maxson.png" width="900">
|
|
72
|
+
</p>
|
|
73
|
+
|
|
74
|
+
## Source
|
|
75
|
+
|
|
76
|
+
https://github.com/City-of-Memphis-Wastewater/plantmap-sv
|
|
Binary file
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is (read: strives to be) based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
- exploded view with traces
|
|
10
|
+
- bad quality, appended red B letter
|
|
11
|
+
- run boolean represented as color
|
|
12
|
+
- reporting
|
|
13
|
+
- 2D status in Nav HUD
|
|
14
|
+
- geojson
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## [0.0.10] – 2026-11-30
|
|
19
|
+
|
|
20
|
+
### Changed:
|
|
21
|
+
|
|
22
|
+
- private: false
|
|
23
|
+
- Remove bun uses, standardize to npm
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- start CLI command help and dev flag.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## [0.0.9] – 2026-11-29
|
|
32
|
+
|
|
33
|
+
### Changed:
|
|
34
|
+
|
|
35
|
+
- Zoom threshold improved with close and far regime.
|
|
36
|
+
- Telemetry HUD now includes units.
|
|
37
|
+
- Navigation HUD width decreased to accomodate phone screen with no overlap of Telemetry HUD.
|
|
38
|
+
- CSV and JSON exports improved to include units and description, and IDCS instead of IESS.
|
|
39
|
+
- Multiple axes scaling and normalization with shared unit representation.
|
|
40
|
+
|
|
41
|
+
### Added:
|
|
42
|
+
|
|
43
|
+
- Make map center and camera altitude configurable.
|
|
44
|
+
- Email process console feedback.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## [0.0.8] – 2026-11-19
|
|
49
|
+
|
|
50
|
+
### Changed:
|
|
51
|
+
|
|
52
|
+
- Svelte 2 -> Svelte 3
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## [0.0.7] – 2026-11-02
|
|
57
|
+
|
|
58
|
+
### Added:
|
|
59
|
+
|
|
60
|
+
- appServer.host is now configured, but the only use case is for the probe. Because whenyou set this thing up on a machine as self-hosted, it doesn't need to know it's own url. Ergo, the only use case is for 'npx plantmap-sv' CLI commands status, download, and plot, which use src/lib/status/probe.ts:discoverServer() to first check for sa local server and then for the configured appServer host.
|
|
61
|
+
- Email settings are now configured in the 'npx plantmap-sv setup' CLI experience, and retained in the relevant config and secret files.
|
|
62
|
+
- function getNowSecondsRoundedToTheMostRecentHalfHour() now used to assess now time of it is not provided.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## [0.0.6] – 2026-10-29
|
|
67
|
+
|
|
68
|
+
### Added:
|
|
69
|
+
|
|
70
|
+
- Plotting, download, cli, status, and tabular requests.
|
|
71
|
+
- Plotting Hover HUD, independent with pipeline-eds style CLI call, and in map view on hover.
|
|
72
|
+
- Hover telemetry calls data from cached database.
|
|
73
|
+
- Email functionality tested, ready to link to cli or curl call download for external transmission.
|
|
74
|
+
|
|
75
|
+
### Internal:
|
|
76
|
+
|
|
77
|
+
- Telemetry HUD needs a vertical scrollbar, and for the minimization key to possibly be lower and unmoving.
|
|
78
|
+
- We need text size adjustment, and possibly roll controls.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## [0.0.5] – 2026-10-15
|
|
83
|
+
|
|
84
|
+
### Changed:
|
|
85
|
+
|
|
86
|
+
- Increase memphis-settings to v0.0.8, to use MemphisEnv.requireValue()
|
|
87
|
+
- Copy cesium assets in run dev and run build calls, namely targeted at Windows pathing gaps. `node scripts/copy-cesium.mjs`.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## [0.0.4] – 2026-10-08
|
|
92
|
+
|
|
93
|
+
### Changed:
|
|
94
|
+
|
|
95
|
+
- Polling restructure to keep client instance and not log out for every call.
|
|
96
|
+
|
|
97
|
+
### Added:
|
|
98
|
+
|
|
99
|
+
- hook entry point
|
|
100
|
+
- bootstrappers for memphis-config, memphis-secret, and memphis-env
|
|
101
|
+
- memphis-secret machination, to replace memphis-env usage
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## [0.0.3] – 2026-10-07
|
|
106
|
+
|
|
107
|
+
### Changed:
|
|
108
|
+
|
|
109
|
+
- memphis-secret is now in service.
|
|
110
|
+
- plantmap-sv CLI now supports config and secret listing.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## [0.0.2] – 2026-10-06
|
|
115
|
+
|
|
116
|
+
### Changed:
|
|
117
|
+
|
|
118
|
+
- Linted successfully.
|
|
119
|
+
- Exposed plantmap-sv CLI entry
|
package/docs/windows.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## Cesium Assets
|
|
2
|
+
|
|
3
|
+
The Windows setup script copies the Cesium distribution into "static/cesium":
|
|
4
|
+
|
|
5
|
+
```pwsh
|
|
6
|
+
scripts/copy-cesium.ps1
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The privileged Windows setup script runs the complete setup sequence:
|
|
10
|
+
|
|
11
|
+
```pwsh
|
|
12
|
+
scripts/setup-priveleged.cmd
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This installs dependencies, copies the Cesium assets, and runs the application setup script.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
|
|
2
|
+
$ErrorActionPreference = "Stop"
|
|
3
|
+
|
|
4
|
+
$AppDir = Join-Path $HOME ".plantmap-sv"
|
|
5
|
+
$ExportDir = Join-Path $AppDir "export"
|
|
6
|
+
$RepoDir = Split-Path $PSScriptRoot -Parent
|
|
7
|
+
$QueryFile = Join-Path $RepoDir "queries/presson-daily-tags.txt"
|
|
8
|
+
|
|
9
|
+
New-Item -ItemType Directory -Force -Path $ExportDir | Out-Null
|
|
10
|
+
|
|
11
|
+
Set-Location $RepoDir
|
|
12
|
+
|
|
13
|
+
function Invoke-PlantMap {
|
|
14
|
+
param(
|
|
15
|
+
[Parameter(Mandatory)]
|
|
16
|
+
[string[]]$Arguments
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
& npx @Arguments
|
|
20
|
+
|
|
21
|
+
if ($LASTEXITCODE -ne 0) {
|
|
22
|
+
throw "PlantMap command failed with exit code $LASTEXITCODE"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Write-Host "Retrieving email recipients..."
|
|
27
|
+
|
|
28
|
+
$EmailList = & npx memphis-settings `
|
|
29
|
+
--app-dir $AppDir `
|
|
30
|
+
config get email-recipient list-4
|
|
31
|
+
|
|
32
|
+
if ($LASTEXITCODE -ne 0 -or !$EmailList) {
|
|
33
|
+
throw "Unable to retrieve email recipients."
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
$EmailList = ($EmailList | Out-String).Trim()
|
|
37
|
+
|
|
38
|
+
if (!(Test-Path $QueryFile)) {
|
|
39
|
+
throw "Query file not found: $QueryFile"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Write-Host "Downloading telemetry..."
|
|
43
|
+
|
|
44
|
+
# Capture existing files so we only attach this run's exports.
|
|
45
|
+
$Before = @{}
|
|
46
|
+
|
|
47
|
+
Get-ChildItem $ExportDir -File | ForEach-Object {
|
|
48
|
+
$Before[$_.FullName] = $_.LastWriteTimeUtc
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
$Started = [DateTime]::UtcNow
|
|
52
|
+
|
|
53
|
+
Invoke-PlantMap @(
|
|
54
|
+
"plantmap-sv",
|
|
55
|
+
"download",
|
|
56
|
+
$QueryFile,
|
|
57
|
+
"--days", "1",
|
|
58
|
+
"--format", "csv",
|
|
59
|
+
"--format", "json",
|
|
60
|
+
"--format", "svg",
|
|
61
|
+
"-o", $ExportDir,
|
|
62
|
+
"-sec", "900"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
$Attachments = @(
|
|
66
|
+
Get-ChildItem $ExportDir -File |
|
|
67
|
+
Where-Object {
|
|
68
|
+
$_.Extension -in ".csv", ".json", ".svg" -and
|
|
69
|
+
(
|
|
70
|
+
!$Before.ContainsKey($_.FullName) -or
|
|
71
|
+
$_.LastWriteTimeUtc -ge $Started
|
|
72
|
+
)
|
|
73
|
+
} |
|
|
74
|
+
Sort-Object Name |
|
|
75
|
+
ForEach-Object { $_.FullName }
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
if ($Attachments.Count -eq 0) {
|
|
79
|
+
throw "No export attachments were generated."
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
foreach ($Path in $Attachments) {
|
|
83
|
+
if (!(Test-Path $Path) -or (Get-Item $Path).Length -eq 0) {
|
|
84
|
+
throw "Missing or empty attachment: $Path"
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Write-Host "Attachment: $Path"
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Write-Host "Sending email ..."
|
|
91
|
+
|
|
92
|
+
$EmailArgs = @(
|
|
93
|
+
"plantmap-sv",
|
|
94
|
+
"email",
|
|
95
|
+
"--to", $EmailList,
|
|
96
|
+
"--subject", "Test - Weekly Maxson EDS Report",
|
|
97
|
+
"--body",
|
|
98
|
+
"Attached is the test data report in 15-minute increments. Open the SVG image file in your browser to view the graph. This report was generated using PlantMap-SV automated reporting tools. This email address will likely be flagged; this is because i use 'memphistn' in the gmail account for this purpose, to send email using SMTP. Gmail is much friendlier than Microsoft for this. This is a test, but I plan to send regular reports like this."
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
foreach ($Path in $Attachments) {
|
|
102
|
+
$EmailArgs += @("--attachment", $Path)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
Invoke-PlantMap $EmailArgs
|
|
106
|
+
|
|
107
|
+
Write-Host "Report sent successfully."
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
|
|
2
|
+
$ErrorActionPreference = "Stop"
|
|
3
|
+
|
|
4
|
+
$AppDir = Join-Path $HOME ".plantmap-sv"
|
|
5
|
+
$ExportDir = Join-Path $AppDir "export"
|
|
6
|
+
$RepoDir = Split-Path $PSScriptRoot -Parent
|
|
7
|
+
$QueryFile = Join-Path $RepoDir "queries/presson-daily-tags.txt"
|
|
8
|
+
|
|
9
|
+
New-Item -ItemType Directory -Force -Path $ExportDir | Out-Null
|
|
10
|
+
|
|
11
|
+
Set-Location $RepoDir
|
|
12
|
+
|
|
13
|
+
function Invoke-PlantMap {
|
|
14
|
+
param(
|
|
15
|
+
[Parameter(Mandatory)]
|
|
16
|
+
[string[]]$Arguments
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
& npx @Arguments
|
|
20
|
+
|
|
21
|
+
if ($LASTEXITCODE -ne 0) {
|
|
22
|
+
throw "PlantMap command failed with exit code $LASTEXITCODE"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Write-Host "Retrieving email recipients..."
|
|
27
|
+
|
|
28
|
+
$EmailList = & npx memphis-settings `
|
|
29
|
+
--app-dir $AppDir `
|
|
30
|
+
config get email-recipient list-3
|
|
31
|
+
|
|
32
|
+
if ($LASTEXITCODE -ne 0 -or !$EmailList) {
|
|
33
|
+
throw "Unable to retrieve email recipients."
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
$EmailList = ($EmailList | Out-String).Trim()
|
|
37
|
+
|
|
38
|
+
if (!(Test-Path $QueryFile)) {
|
|
39
|
+
throw "Query file not found: $QueryFile"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Write-Host "Downloading Presson telemetry..."
|
|
43
|
+
|
|
44
|
+
# Capture existing files so we only attach this run's exports.
|
|
45
|
+
$Before = @{}
|
|
46
|
+
|
|
47
|
+
Get-ChildItem $ExportDir -File | ForEach-Object {
|
|
48
|
+
$Before[$_.FullName] = $_.LastWriteTimeUtc
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
$Started = [DateTime]::UtcNow
|
|
52
|
+
|
|
53
|
+
Invoke-PlantMap @(
|
|
54
|
+
"plantmap-sv",
|
|
55
|
+
"download",
|
|
56
|
+
$QueryFile,
|
|
57
|
+
"--days", "1",
|
|
58
|
+
"--format", "csv",
|
|
59
|
+
"--format", "json",
|
|
60
|
+
"--format", "svg",
|
|
61
|
+
"-o", $ExportDir,
|
|
62
|
+
"-sec", "900"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
$Attachments = @(
|
|
66
|
+
Get-ChildItem $ExportDir -File |
|
|
67
|
+
Where-Object {
|
|
68
|
+
$_.Extension -in ".csv", ".json", ".svg" -and
|
|
69
|
+
(
|
|
70
|
+
!$Before.ContainsKey($_.FullName) -or
|
|
71
|
+
$_.LastWriteTimeUtc -ge $Started
|
|
72
|
+
)
|
|
73
|
+
} |
|
|
74
|
+
Sort-Object Name |
|
|
75
|
+
ForEach-Object { $_.FullName }
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
if ($Attachments.Count -eq 0) {
|
|
79
|
+
throw "No export attachments were generated."
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
foreach ($Path in $Attachments) {
|
|
83
|
+
if (!(Test-Path $Path) -or (Get-Item $Path).Length -eq 0) {
|
|
84
|
+
throw "Missing or empty attachment: $Path"
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Write-Host "Attachment: $Path"
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Write-Host "Sending Presson daily report..."
|
|
91
|
+
|
|
92
|
+
$EmailArgs = @(
|
|
93
|
+
"plantmap-sv",
|
|
94
|
+
"email",
|
|
95
|
+
"--to", $EmailList,
|
|
96
|
+
"--subject", "Daily Presson Report",
|
|
97
|
+
"--body",
|
|
98
|
+
"Attached is the daily Presson test data report in 15-minute increments. Open the SVG image file in your browser to view the graph. This report was generated using PlantMap-SV automated reporting tools."
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
foreach ($Path in $Attachments) {
|
|
102
|
+
$EmailArgs += @("--attachment", $Path)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
Invoke-PlantMap $EmailArgs
|
|
106
|
+
|
|
107
|
+
Write-Host "Presson daily report sent successfully."
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
|
|
2
|
+
#!/usr/bin/env python3
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import subprocess
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from datetime import datetime, timezone
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# --------------------------------------------------
|
|
12
|
+
# Configuration
|
|
13
|
+
# --------------------------------------------------
|
|
14
|
+
|
|
15
|
+
REPO_DIR = Path(__file__).resolve().parent.parent
|
|
16
|
+
|
|
17
|
+
APP_DIR = Path.home() / ".plantmap-sv"
|
|
18
|
+
EXPORT_DIR = APP_DIR / "export"
|
|
19
|
+
|
|
20
|
+
QUERY_FILE = REPO_DIR / "queries" / "presson-daily-tags.txt"
|
|
21
|
+
|
|
22
|
+
FORMATS = ("csv", "json", "svg")
|
|
23
|
+
INTERVAL_SECONDS = "900"
|
|
24
|
+
EMAIL_LIST_KEY = "list-3"
|
|
25
|
+
|
|
26
|
+
# --------------------------------------------------
|
|
27
|
+
# Command execution
|
|
28
|
+
# --------------------------------------------------
|
|
29
|
+
|
|
30
|
+
def run_command(args: list[str]) -> str:
|
|
31
|
+
"""Execute a command and return stdout."""
|
|
32
|
+
|
|
33
|
+
print(f"\n$ {' '.join(map(str, args))}")
|
|
34
|
+
|
|
35
|
+
if os.name == "nt":
|
|
36
|
+
# Windows requires shell handling for npx.cmd.
|
|
37
|
+
command = subprocess.list2cmdline(
|
|
38
|
+
[str(arg) for arg in args]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
result = subprocess.run(
|
|
42
|
+
command,
|
|
43
|
+
shell=True,
|
|
44
|
+
cwd=REPO_DIR,
|
|
45
|
+
text=True,
|
|
46
|
+
capture_output=True,
|
|
47
|
+
)
|
|
48
|
+
else:
|
|
49
|
+
result = subprocess.run(
|
|
50
|
+
[str(arg) for arg in args],
|
|
51
|
+
cwd=REPO_DIR,
|
|
52
|
+
text=True,
|
|
53
|
+
capture_output=True,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if result.stdout:
|
|
57
|
+
print(result.stdout, end="")
|
|
58
|
+
|
|
59
|
+
if result.stderr:
|
|
60
|
+
print(result.stderr, end="", file=sys.stderr)
|
|
61
|
+
|
|
62
|
+
if result.returncode != 0:
|
|
63
|
+
raise RuntimeError(
|
|
64
|
+
f"Command failed with exit code {result.returncode}"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
return result.stdout.strip()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# --------------------------------------------------
|
|
71
|
+
# Main workflow
|
|
72
|
+
# --------------------------------------------------
|
|
73
|
+
|
|
74
|
+
def main():
|
|
75
|
+
|
|
76
|
+
EXPORT_DIR.mkdir(parents=True, exist_ok=True)
|
|
77
|
+
|
|
78
|
+
if not QUERY_FILE.is_file():
|
|
79
|
+
raise FileNotFoundError(
|
|
80
|
+
f"Query file not found: {QUERY_FILE}"
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Retrieve recipients from the settings vault.
|
|
84
|
+
print("Retrieving email recipients...")
|
|
85
|
+
|
|
86
|
+
email_list = run_command([
|
|
87
|
+
"npx",
|
|
88
|
+
"memphis-settings",
|
|
89
|
+
"--app-dir", str(APP_DIR),
|
|
90
|
+
"config", "get",
|
|
91
|
+
"email-recipient", EMAIL_LIST_KEY,
|
|
92
|
+
])
|
|
93
|
+
|
|
94
|
+
if not email_list:
|
|
95
|
+
raise RuntimeError("No email recipients configured.")
|
|
96
|
+
|
|
97
|
+
# Snapshot existing exports.
|
|
98
|
+
before = {
|
|
99
|
+
path: path.stat().st_mtime_ns
|
|
100
|
+
for path in EXPORT_DIR.iterdir()
|
|
101
|
+
if path.is_file()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
started = datetime.now(timezone.utc).timestamp_ns() \
|
|
105
|
+
if hasattr(datetime.now(timezone.utc), "timestamp_ns") \
|
|
106
|
+
else int(datetime.now(timezone.utc).timestamp() * 1_000_000_000)
|
|
107
|
+
|
|
108
|
+
# Download telemetry.
|
|
109
|
+
print("\nDownloading Presson telemetry...")
|
|
110
|
+
|
|
111
|
+
run_command([
|
|
112
|
+
"npx",
|
|
113
|
+
"plantmap-sv",
|
|
114
|
+
"download",
|
|
115
|
+
str(QUERY_FILE),
|
|
116
|
+
"--days", "1",
|
|
117
|
+
"--format", "csv",
|
|
118
|
+
"--format", "json",
|
|
119
|
+
"--format", "svg",
|
|
120
|
+
"-o", str(EXPORT_DIR),
|
|
121
|
+
"-sec", INTERVAL_SECONDS,
|
|
122
|
+
])
|
|
123
|
+
|
|
124
|
+
# Collect files generated or updated by this run.
|
|
125
|
+
attachments = []
|
|
126
|
+
|
|
127
|
+
for path in sorted(EXPORT_DIR.iterdir()):
|
|
128
|
+
|
|
129
|
+
if not path.is_file():
|
|
130
|
+
continue
|
|
131
|
+
|
|
132
|
+
if path.suffix.lower() not in FORMATS:
|
|
133
|
+
continue
|
|
134
|
+
|
|
135
|
+
previous_mtime = before.get(path)
|
|
136
|
+
|
|
137
|
+
if previous_mtime is None or path.stat().st_mtime_ns >= started:
|
|
138
|
+
if path.stat().st_size == 0:
|
|
139
|
+
raise RuntimeError(
|
|
140
|
+
f"Empty attachment: {path}"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
attachments.append(path)
|
|
144
|
+
|
|
145
|
+
if not attachments:
|
|
146
|
+
raise RuntimeError("No export attachments were generated.")
|
|
147
|
+
|
|
148
|
+
print("\nAttachments:")
|
|
149
|
+
|
|
150
|
+
for path in attachments:
|
|
151
|
+
print(f" {path}")
|
|
152
|
+
|
|
153
|
+
# Send email.
|
|
154
|
+
print("\nSending Presson daily report...")
|
|
155
|
+
|
|
156
|
+
email_args = [
|
|
157
|
+
"npx",
|
|
158
|
+
"plantmap-sv",
|
|
159
|
+
"email",
|
|
160
|
+
"--to", email_list,
|
|
161
|
+
"--subject", "Daily Presson Report",
|
|
162
|
+
"--body",
|
|
163
|
+
(
|
|
164
|
+
"Attached is the daily Presson test data report "
|
|
165
|
+
"in 15-minute increments. Open the SVG image file "
|
|
166
|
+
"in your browser to view the graph. This report "
|
|
167
|
+
"was generated using PlantMap-SV automated "
|
|
168
|
+
"reporting tools."
|
|
169
|
+
),
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
for path in attachments:
|
|
173
|
+
email_args.extend([
|
|
174
|
+
"--attachment",
|
|
175
|
+
str(path),
|
|
176
|
+
])
|
|
177
|
+
|
|
178
|
+
run_command(email_args)
|
|
179
|
+
|
|
180
|
+
print("\nPresson daily report sent successfully.")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
if __name__ == "__main__":
|
|
184
|
+
try:
|
|
185
|
+
main()
|
|
186
|
+
except (RuntimeError, FileNotFoundError, OSError) as exc:
|
|
187
|
+
print(f"\nERROR: {exc}", file=sys.stderr)
|
|
188
|
+
sys.exit(1)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
APP_DIR="$HOME/.plantmap-sv"
|
|
5
|
+
EXPORT_DIR="$APP_DIR/export"
|
|
6
|
+
|
|
7
|
+
EMAIL_LIST=$(npx memphis-settings \
|
|
8
|
+
--app-dir "$APP_DIR" \
|
|
9
|
+
config get email-recipient list-3)
|
|
10
|
+
|
|
11
|
+
EXPORT_PATHS_BIOREM=$(npx plantmap-sv download \
|
|
12
|
+
queries/presson-daily-tags.txt \
|
|
13
|
+
--days 1 \
|
|
14
|
+
--format csv --format json --format svg \
|
|
15
|
+
-o "$EXPORT_DIR" \
|
|
16
|
+
-sec 900)
|
|
17
|
+
|
|
18
|
+
mapfile -t EX_PATHS <<< "$EXPORT_PATHS"
|
|
19
|
+
|
|
20
|
+
ATTACHMENTS=("${EX_PATHS[@]}")
|
|
21
|
+
for path in "${ATTACHMENTS[@]}"; do
|
|
22
|
+
[[ -s "$path" ]] || {
|
|
23
|
+
echo "Missing or empty attachment: $path" >&2
|
|
24
|
+
exit 1
|
|
25
|
+
}
|
|
26
|
+
done
|
|
27
|
+
|
|
28
|
+
EMAIL_ARGS=()
|
|
29
|
+
|
|
30
|
+
for path in "${ATTACHMENTS[@]}"; do
|
|
31
|
+
EMAIL_ARGS+=(--attachment "$path")
|
|
32
|
+
done
|
|
33
|
+
|
|
34
|
+
npx plantmap-sv email \
|
|
35
|
+
--to "$EMAIL_LIST" \
|
|
36
|
+
--subject "Daily Presson Report" \
|
|
37
|
+
--body "Attached is the daily test data report weekly, in 15 minute increments. Open the SVG image file in your browser to view the graph. This was sent from using PlantMap-SV automated reporting tools." \
|
|
38
|
+
"${EMAIL_ARGS[@]}"
|