-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2793b79
commit 0de7d11
Showing
7 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import datetime | ||
|
||
import influxdb_client | ||
from influxdb_client.client.write_api import SYNCHRONOUS | ||
|
||
|
||
from pyobs_cloudcover.cloud_coverage_info import CloudCoverageInfo | ||
from pyobs_cloudcover.measurement_log.measurement_log import MeasurementLog | ||
|
||
|
||
class Influx(MeasurementLog): | ||
def __init__(self, url: str, bucket: str, org: str, token: str) -> None: | ||
self._client = influxdb_client.InfluxDBClient( | ||
url=url, | ||
token=token, | ||
org=org | ||
) | ||
self._bucket = bucket | ||
self._org = org | ||
|
||
def __call__(self, measurement: CloudCoverageInfo, obs_time: datetime.datetime) -> None: | ||
data = influxdb_client.Point("measurement") | ||
|
||
data.time(obs_time) | ||
|
||
data.field("total-cover", measurement.total_cover) | ||
data.field("zenith-cover", measurement.zenith_cover) | ||
data.field("change", measurement.change) | ||
|
||
with self._client.write_api(write_options=SYNCHRONOUS) as write_api: | ||
write_api.write(bucket=self._bucket, org=self._org, record=data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import abc | ||
import datetime | ||
|
||
from pyobs_cloudcover.cloud_coverage_info import CloudCoverageInfo | ||
|
||
|
||
class MeasurementLog(object, metaclass=abc.ABCMeta): | ||
@abc.abstractmethod | ||
def __call__(self, measurement: CloudCoverageInfo, obs_time: datetime.datetime) -> None: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import datetime | ||
from unittest.mock import Mock | ||
|
||
import influxdb_client | ||
import numpy as np | ||
|
||
from pyobs_cloudcover.cloud_coverage_info import CloudCoverageInfo | ||
from pyobs_cloudcover.measurement_log.influx import Influx | ||
|
||
from influxdb_client.client.write_api import WriteApi | ||
|
||
|
||
def test_call(): | ||
influxdb_client.client.write_api.WriteApi.write = Mock() | ||
|
||
measurement = CloudCoverageInfo(np.array([]), 0, 1, 2) | ||
obs_time = datetime.datetime(2020, 1, 1, 0, 0, 0) | ||
|
||
measurement_log = Influx("", "bucket", "org", "token") | ||
|
||
measurement_log(measurement, obs_time) | ||
|
||
call_args = influxdb_client.client.write_api.WriteApi.write.call_args_list | ||
|
||
kwargs = call_args[0].kwargs | ||
assert kwargs["bucket"] == "bucket" | ||
assert kwargs["org"] == "org" | ||
|
||
data: influxdb_client.Point = kwargs["record"] | ||
assert data._time == obs_time | ||
assert data._fields["total-cover"] == 0 | ||
assert data._fields["zenith-cover"] == 1 | ||
assert data._fields["change"] == 2 | ||
|