Class: QaServer::TimePeriodService

Inherits:
Object
  • Object
show all
Defined in:
app/services/qa_server/time_period_service.rb

Class Method Summary collapse

Class Method Details

.where_clause_for_last_12_months(auth_name: nil, auth_table: nil, dt_table: nil, dt_column: :dt_stamp) ⇒ Hash

Construct a hash to pass to ActiveRecord where method limiting to last 12 months and optionally an authority.

Examples:

returned where for join

{ scenario_run_registry: { dt_stamp: start_month..end_month },
  scenario_run_history: { authority: 'LOC_DIRECT' } }

returned where for join with no authority

{ scenario_run_registry: { dt_stamp: start_month..end_month } }

returned where for same table

{ dt_stamp: start_month..end_month, authority: 'LOC_DIRECT' }

returned where when no authority

{ dt_stamp: start_month..end_month }

Parameters:

  • auth_name (String) (defaults to: nil)

    authority name if limiting to an authority; otherwise, nil

  • auth_table (Symbol) (defaults to: nil)

    name of the table holding the authority name; or nil if in same table

  • dt_table (Symbol) (defaults to: nil)

    name of the table holding the date-time stamp; or nil if in same table

Returns:

  • (Hash)

    a where clause for the last 12 months for an authority



60
61
62
63
64
# File 'app/services/qa_server/time_period_service.rb', line 60

def where_clause_for_last_12_months(auth_name: nil, auth_table: nil, dt_table: nil, dt_column: :dt_stamp)
  validate_params(auth_name, auth_table, dt_table)
  where_clause = where_for_dt_stamp(dt_table, dt_column, 1.year)
  where_with_authority(where_clause, auth_name, auth_table)
end

.where_clause_for_last_24_hours(auth_name: nil, auth_table: nil, dt_table: nil, dt_column: :dt_stamp) ⇒ Hash

Construct a hash to pass to ActiveRecord where method limiting to last 24 hours and optionally an authority.

Examples:

returned where for join

{ scenario_run_registry: { dt_stamp: start_hour..end_hour },
  scenario_run_history: { authority: 'LOC_DIRECT' } }

returned where for join with no authority

{ scenario_run_registry: { dt_stamp: start_hour..end_hour } }

returned where for same table

{ dt_stamp: start_hour..end_hour, authority: 'LOC_DIRECT' }

returned where when no authority

{ dt_stamp: start_hour..end_hour }

Parameters:

  • auth_name (String) (defaults to: nil)

    authority name if limiting to an authority; otherwise, nil

  • auth_table (Symbol) (defaults to: nil)

    name of the table holding the authority name; or nil if in same table

  • dt_table (Symbol) (defaults to: nil)

    name of the table holding the date-time stamp; or nil if in same table

Returns:

  • (Hash)

    a where clause for the last 24 hours for an authority



20
21
22
23
24
# File 'app/services/qa_server/time_period_service.rb', line 20

def where_clause_for_last_24_hours(auth_name: nil, auth_table: nil, dt_table: nil, dt_column: :dt_stamp)
  validate_params(auth_name, auth_table, dt_table)
  where_clause = where_for_dt_stamp(dt_table, dt_column, 1.day)
  where_with_authority(where_clause, auth_name, auth_table)
end

.where_clause_for_last_30_days(auth_name: nil, auth_table: nil, dt_table: nil, dt_column: :dt_stamp) ⇒ Hash

Construct a hash to pass to ActiveRecord where method limiting to last 30 days and optionally an authority.

Examples:

returned where for join

{ scenario_run_registry: { dt_stamp: start_day..end_day },
  scenario_run_history: { authority: 'LOC_DIRECT' } }

returned where for join with no authority

{ scenario_run_registry: { dt_stamp: start_day..end_day } }

returned where for same table

{ dt_stamp: start_day..end_day, authority: 'LOC_DIRECT' }

returned where when no authority

{ dt_stamp: start_day..end_day }

Parameters:

  • auth_name (String) (defaults to: nil)

    authority name if limiting to an authority; otherwise, nil

  • auth_table (Symbol) (defaults to: nil)

    name of the table holding the authority name; or nil if in same table

  • dt_table (Symbol) (defaults to: nil)

    name of the table holding the date-time stamp; or nil if in same table

Returns:

  • (Hash)

    a where clause for the last 30 days for an authority



40
41
42
43
44
# File 'app/services/qa_server/time_period_service.rb', line 40

def where_clause_for_last_30_days(auth_name: nil, auth_table: nil, dt_table: nil, dt_column: :dt_stamp)
  validate_params(auth_name, auth_table, dt_table)
  where_clause = where_for_dt_stamp(dt_table, dt_column, 1.month)
  where_with_authority(where_clause, auth_name, auth_table)
end