Skip to content

Commit

Permalink
Merge branch 'main' into feat/sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
k0rventen committed Dec 7, 2023
2 parents dd00a1e + 1db4f4d commit f6728c2
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 36 deletions.
24 changes: 2 additions & 22 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,7 @@ jobs:
name: Checkout
uses: actions/checkout@v3
-
name: build & start
name: run tests
run: |
cd tests
docker compose up -d influx
-
name: run init tests
run: |
cd tests
chmod a+x tests.sh
docker compose up --build test-ingester-std
docker compose cp tests.sh influx:/usr/local/bin/
docker compose exec influx "tests.sh"
-
name: run other tests
run: |
cd tests
docker compose up --build test-ingester-no-routes-uppercase
docker compose up --build test-ingester-malformed-xml
-
name: cleanup
run: |
cd tests
docker compose down
bash run.sh
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
grafana:
image: grafana/grafana:10.0.3
image: grafana/grafana:10.2.2
ports:
- 3000:3000
environment:
Expand All @@ -19,9 +19,9 @@ services:
- influx-data:/var/lib/influxdb
ingester:
image: k0rventen/apple-health-grafana-ingester
build: ./ingester
#build: ./ingester
volumes:
- <local_path_to_export.zip>:/export.zip

volumes:
influx-data:
influx-data:
2 changes: 1 addition & 1 deletion ingester/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ COPY requirements.txt .
RUN pip3 install -r requirements.txt

COPY *.py .
ENTRYPOINT python3 -uO app.py
ENTRYPOINT python3 -u app.py
2 changes: 1 addition & 1 deletion ingester/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def format_record(record: dict[str, Any]) -> dict[str, Any]:
return AppleStandHourFormatter(record)
if measurement == "SleepAnalysis":
return SleepAnalysisFormatter(record)

date = parse_date_as_timestamp(record.get("startDate", 0))
value = parse_float_with_try(record.get("value", 1))
unit = record.get("unit", "unit")
Expand Down
1 change: 1 addition & 0 deletions ingester/formatters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime as dt
from datetime import timedelta

from typing import Any, Union


Expand Down
2 changes: 1 addition & 1 deletion ingester/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
influxdb==5.3.1
gpxpy==1.5.0
gpxpy==1.6.2
lxml==4.9.3
6 changes: 6 additions & 0 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ services:
build: ../ingester
volumes:
- ./test-export3.zip:/export.zip

# test with another malformed export.xml
test-ingester-malformed-xml-2:
build: ../ingester
volumes:
- ./test-export4.zip:/export.zip
19 changes: 19 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# prep the test env
set -e

chmod a+x tests.sh
docker compose down
docker compose up -d influx
docker compose build
docker compose exec influx apt update
docker compose exec influx apt install jq -y
docker compose cp tests.sh influx:/usr/local/bin/

# for each compose service, run it, check for output, then reset influx
for service in test-ingester-std test-ingester-no-routes-uppercase test-ingester-malformed-xml test-ingester-malformed-xml-2
do
docker compose up --exit-code-from $service $service
docker compose exec influx tests.sh
done

docker compose down
Binary file added tests/test-export4.zip
Binary file not shown.
12 changes: 4 additions & 8 deletions tests/tests.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash
set -e
influx -database 'health' -format 'json' -execute 'SELECT COUNT(x) FROM (SELECT *,x::INTEGER FROM 'WalkingSpeed' FILL(0))' | jq -e '.results[0].series[0].values[0][1]|contains(400)'
influx -database 'health' -format 'json' -execute 'SELECT COUNT(x) FROM (SELECT *,x::INTEGER FROM 'StepCount' FILL(0))' | jq -e '.results[0].series[0].values[0][1]|contains(399)'

# Note that this should be executed within the influx container
# docker compose cp tests.sh influx:/usr/local/bin/
# docker compose exec influx "tests.sh"
measurements=$(influx -database 'health' -execute 'show measurements' | tail -n +4)
for m in $measurements
do
influx -database 'health' -execute 'select(value) from "'$m'" limit 3'
done
influx -format 'json' -execute 'DROP DATABASE health'

0 comments on commit f6728c2

Please sign in to comment.