Class: WrfForecast::JsonConverter::ForecastStationJsonConverter

Inherits:
WrfLibrary::JsonConverter::BaseStationJsonConverter
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, forecast, warnings) ⇒ ForecastStationJsonConverter

initialization

Parameters:

  • data (DataRepository)

    the complete data

  • forecast (ForecastRepository)

    the specific forecast data

  • warnings (Hash)

    the mapping of measurand and triggered thresholds for the current forecast



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

#forecastForecastRepository (readonly, private)

Returns the data repository with the forecast data.

Returns:



25
26
27
# File 'lib/wrf_forecast/json_converter/forecast_station_converter.rb', line 25

def forecast
  @forecast
end

#warningsHash (readonly, private)

Returns the mapping of measurand and triggered thresholds for the current forecast.

Returns:

  • (Hash)

    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_additionsHash (private)

implementation of the abstract parent method. Since there is no additional data the method returns an empty hash

Returns:

  • (Hash)

    the key-value hash for the json output



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

Parameters:

  • forecast_date (Time)

    the start date of the forecast

  • float_time (Float)

    the suntime hour as a float

Returns:

  • (Time)

    the suntime as a 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_valuesObject (private)

abstract method to create the output hash for the temperature values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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_valuesObject (private)

abstract method to create the output hash for the temperature values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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_valuesHash (private)

implementation of the abstract parent method to create valid json objects for the stored data values

Returns:

  • (Hash)

    the key-value hashes for the json output



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_valuesObject (private)

abstract method to create the output hash for the temperature values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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_valuesObject (private)

abstract method to create the output hash for the precipitation values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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_warningsArray (private)

method to create the output array for the warnings

Returns:

  • (Array)

    an array of Strings containing the warning texts



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_valuesObject (private)

abstract method to create the output hash for the wind direction values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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_valuesObject (private)

abstract method to create the output hash for the wind speed values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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