Class: WrfForecast::JsonConverter::ForecastStationJsonConverter
- Inherits:
-
WrfLibrary::JsonConverter::BaseStationJsonConverter
- Object
- WrfLibrary::JsonConverter::BaseStationJsonConverter
- WrfForecast::JsonConverter::ForecastStationJsonConverter
- Defined in:
- lib/wrf_forecast/json_converter/forecast_station_converter.rb
Overview
Abstract class to generate valid json output for the result data of a given wrf meteogram result already stored in a data repository with abstract implementations for the aggregation of the measurand data
Direct Known Subclasses
Instance Attribute Summary collapse
-
#forecast ⇒ ForecastRepository
readonly
private
The data repository with the forecast data.
-
#warnings ⇒ Hash
readonly
private
The mapping of measurand and triggered thresholds for the current forecast.
Instance Method Summary collapse
-
#add_additions ⇒ Hash
private
implementation of the abstract parent method.
-
#convert_suntime(forecast_date, float_time) ⇒ Time
private
method to convert a float hourstamp to a valid time object.
-
#generate_data_values ⇒ Hash
private
implementation of the abstract parent method to create valid json objects for the stored data values.
-
#generate_rain_values ⇒ Object
private
abstract method to create the output hash for the precipitation values.
-
#generate_temperature_values ⇒ Object
private
abstract method to create the output hash for the temperature values.
-
#generate_warnings ⇒ Object
private
method to create the output array for the warnings.
-
#generate_wind_values ⇒ Object
private
abstract method to create the output hash for the wind values.
-
#initialize(data, forecast, warnings) ⇒ ForecastStationJsonConverter
constructor
initialization.
Constructor Details
#initialize(data, forecast, warnings) ⇒ ForecastStationJsonConverter
initialization
16 17 18 19 20 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 16 def initialize(data, forecast, warnings) @forecast = forecast @warnings = warnings super(data) end |
Instance Attribute Details
#forecast ⇒ ForecastRepository (readonly, private)
Returns the data repository with the forecast data.
25 26 27 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 25 def forecast @forecast end |
#warnings ⇒ Hash (readonly, private)
Returns the mapping of measurand and triggered thresholds for the current forecast.
28 29 30 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 28 def warnings @warnings end |
Instance Method Details
#add_additions ⇒ Hash (private)
implementation of the abstract parent method. Since there is no additional data the method returns an empty hash
33 34 35 36 37 38 39 40 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 33 def add_additions date = @data..start_date coordinate = @data..station.coordinate sunrise = WrfLibrary::SunEquation.calculate_sunrise_time(date, coordinate.x, coordinate.y) sunset = WrfLibrary::SunEquation.calculate_sunset_time(date, coordinate.x, coordinate.y) { :suntime => { :sunrise => convert_suntime(date, sunrise), :sunset => convert_suntime(date, sunset) } } end |
#convert_suntime(forecast_date, float_time) ⇒ Time (private)
method to convert a float hourstamp to a valid time object
90 91 92 93 94 95 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 90 def convert_suntime(forecast_date, float_time) hours = float_time.floor minutes = (float_time.round(2) % 1 * 60).round(0) Time.new(forecast_date.year, forecast_date.month, forecast_date.day, hours, minutes, 00, forecast_date.strftime("%:z")) end |
#generate_data_values ⇒ Hash (private)
implementation of the abstract parent method to create valid json objects for the stored data values
45 46 47 48 49 50 51 52 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 45 def generate_data_values measurands = Hash.new() measurands[:temperature] = generate_temperature_values measurands[:wind_speed] = generate_wind_values measurands[:rain] = generate_rain_values measurands[:warnings] = generate_warnings return measurands end |
#generate_rain_values ⇒ Object (private)
abstract method to create the output hash for the precipitation values
70 71 72 73 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 70 def generate_rain_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: #{__method__.to_s} from its base class".red end |
#generate_temperature_values ⇒ Object (private)
abstract method to create the output hash for the temperature values
56 57 58 59 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 56 def generate_temperature_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: #{__method__.to_s} from its base class".red end |
#generate_warnings ⇒ Object (private)
method to create the output array for the warnings
76 77 78 79 80 81 82 83 84 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 76 def generate_warnings values = Array.new() @warnings.each_value { |value| value.each { |element| values << element.warning_text } } return values end |
#generate_wind_values ⇒ Object (private)
abstract method to create the output hash for the wind values
63 64 65 66 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 63 def generate_wind_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: #{__method__.to_s} from its base class".red end |