Class: DWDSensor
- Inherits:
-
Object
- Object
- DWDSensor
- Defined in:
- lib/ollama_chat/tools/weather/dwd_sensor.rb
Overview
A sensor implementation that fetches real-time temperature data from the German Weather Service (DWD). This sensor connects to DWD’s open data API to retrieve the latest air temperature measurements for a specified weather station.
The sensor expects DWD data files in ZIP format containing CSV data with the following structure:
-
Files are named like: 10minutenwerte_TU_00433_now.zip
-
Data is stored in CSV format with semicolon separators
-
Temperature values are in the TT_10 column (in Celsius)
-
Timestamps are in MESS_DATUM column (format: YYYYMMDDHHMM)
Example usage:
sensor = DWDSensor.new(sensor_id: 'station_1', station_id: '00433')
temperature = sensor.measure
Constant Summary collapse
- DEFAULT_URL_TEMPLATE =
Template for the download URL
"https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/10_minutes/air_temperature/now/10minutenwerte_TU_%{station_id}_now.zip"
Instance Attribute Summary collapse
-
#sensor_id ⇒ Object
readonly
The sensor_id method provides read-only access to the identifier of the sensor.
Instance Method Summary collapse
-
#initialize(sensor_id:, station_id:, url_template: DEFAULT_URL_TEMPLATE, logger: Logger.new($stderr)) ⇒ DWDSensor
constructor
Initializes a new sensor reader instance with the specified parameters.
-
#measure ⇒ Array<Time, Float>?
The measure method reads temperature data from a sensor and returns timestamped measurements.
Constructor Details
#initialize(sensor_id:, station_id:, url_template: DEFAULT_URL_TEMPLATE, logger: Logger.new($stderr)) ⇒ DWDSensor
Initializes a new sensor reader instance with the specified parameters.
29 30 31 32 33 34 35 |
# File 'lib/ollama_chat/tools/weather/dwd_sensor.rb', line 29 def initialize(sensor_id:, station_id:, url_template: DEFAULT_URL_TEMPLATE, logger: Logger.new($stderr)) @sensor_id = sensor_id @station_id = station_id @url_template = url_template @last_modified = nil @logger = logger end |
Instance Attribute Details
#sensor_id ⇒ Object (readonly)
The sensor_id method provides read-only access to the identifier of the sensor.
instance
42 43 44 |
# File 'lib/ollama_chat/tools/weather/dwd_sensor.rb', line 42 def sensor_id @sensor_id end |
Instance Method Details
#measure ⇒ Array<Time, Float>?
The measure method reads temperature data from a sensor and returns timestamped measurements.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ollama_chat/tools/weather/dwd_sensor.rb', line 50 def measure @logger.info "Starting to read temperature from #{self.class} #{@sensor_id}…" time, temp = read_temperature if time && temp @logger.info "Read temperature from #{self.class} #{@sensor_id} at #{time.iso8601}: #{temp}℃ " [ time, temp ] else nil end end |