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_air_temperature_values ⇒ Object
private
abstract method to create the output hash for the temperature values.
-
#generate_apparent_temperature_values ⇒ Object
private
abstract method to create the output hash for the temperature values.
-
#generate_data_values ⇒ Hash
private
implementation of the abstract parent method to create valid json objects for the stored data values.
-
#generate_pressure_values ⇒ Object
private
abstract method to create the output hash for the temperature values.
-
#generate_rain_values ⇒ Object
private
abstract method to create the output hash for the precipitation values.
-
#generate_warnings ⇒ Array
private
method to create the output array for the warnings.
-
#generate_winddirection_values ⇒ Object
private
abstract method to create the output hash for the wind direction values.
-
#generate_windspeed_values ⇒ Object
private
abstract method to create the output hash for the wind speed 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
115 116 117 118 119 120 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 115 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_air_temperature_values ⇒ Object (private)
abstract method to create the output hash for the temperature values
66 67 68 69 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 66 def generate_air_temperature_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: #{__method__.to_s} from its base class".red end |
#generate_apparent_temperature_values ⇒ Object (private)
abstract method to create the output hash for the temperature values
59 60 61 62 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 59 def generate_apparent_temperature_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: #{__method__.to_s} from its base class".red 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 53 54 55 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 45 def generate_data_values measurands = Hash.new() measurands[:air_temperature] = generate_air_temperature_values measurands[:apparent_temperature] = generate_apparent_temperature_values measurands[:pressure] = generate_pressure_values measurands[:rain] = generate_rain_values measurands[:wind_speed] = generate_windspeed_values measurands[:wind_direction] = generate_winddirection_values measurands[:warnings] = generate_warnings measurands end |
#generate_pressure_values ⇒ Object (private)
abstract method to create the output hash for the temperature values
73 74 75 76 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 73 def generate_pressure_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: #{__method__.to_s} from its base class".red end |
#generate_rain_values ⇒ Object (private)
abstract method to create the output hash for the precipitation values
94 95 96 97 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 94 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_warnings ⇒ Array (private)
method to create the output array for the warnings
101 102 103 104 105 106 107 108 109 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 101 def generate_warnings values = Array.new() @warnings.each_value { |value| value.each { |element| values << element.warning_text } } values end |
#generate_winddirection_values ⇒ Object (private)
abstract method to create the output hash for the wind direction values
87 88 89 90 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 87 def generate_winddirection_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: #{__method__.to_s} from its base class".red end |
#generate_windspeed_values ⇒ Object (private)
abstract method to create the output hash for the wind speed values
80 81 82 83 |
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 80 def generate_windspeed_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: #{__method__.to_s} from its base class".red end |