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



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

abstract method to create the output hash for the precipitation values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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

abstract method to create the output hash for the temperature values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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

abstract method to create the output hash for the wind values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



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