Class: GdsApi::PerformancePlatform::DataOut

Inherits:
Base
  • Object
show all
Defined in:
lib/gds_api/performance_platform/data_out.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#client, #create_client, #get_list, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Instance Method Details

#page_views(slug, is_multipart) ⇒ Object


91
92
93
94
95
96
97
98
99
# File 'lib/gds_api/performance_platform/data_out.rb', line 91

def page_views(slug, is_multipart)
  options = {
      slug: slug,
      transaction: 'page-statistics',
      group_by: 'pagePath',
      collect: 'uniquePageviews:sum'
  }
  statistics(options, is_multipart)
end

#problem_reports(slug, is_multipart) ⇒ Object


101
102
103
104
105
106
107
108
109
# File 'lib/gds_api/performance_platform/data_out.rb', line 101

def problem_reports(slug, is_multipart)
  options = {
      slug: slug,
      transaction: 'page-contacts',
      group_by: 'pagePath',
      collect: 'total:sum'
  }
  statistics(options, is_multipart)
end

#search_terms(slug) ⇒ Object

Fetching statistics data from the performance platform for a given page slug

Makes a GET request.

statistics. or not:

  • simple: `/european-health-insurance-card`

  • multipart: `/european-health-insurance-card/123`

# @examples

1. Without multipart filtering:

performance_platform_data_out.search_terms('/european-health-insurance-card')

2. With multipart filtering:

performance_platform_data_out.searches('/european-health-insurance-card', true)
performance_platform_data_out.page_views('/european-health-insurance-card', true)
performance_platform_data_out.problem_reports('/european-health-insurance-card', true)

Parameters:

  • slug (String)

    Points to the page for which we are requesting

  • is_multipart (Boolean)

    Flag that marks whether the slug is multipart


71
72
73
74
75
76
77
78
79
# File 'lib/gds_api/performance_platform/data_out.rb', line 71

def search_terms(slug)
  options = {
      slug: slug,
      transaction: 'search-terms',
      group_by: 'searchKeyword',
      collect: 'searchUniques:sum'
  }
  statistics(options)
end

#searches(slug, is_multipart) ⇒ Object


81
82
83
84
85
86
87
88
89
# File 'lib/gds_api/performance_platform/data_out.rb', line 81

def searches(slug, is_multipart)
  options = {
      slug: slug,
      transaction: 'search-terms',
      group_by: 'pagePath',
      collect: 'searchUniques:sum'
  }
  statistics(options, is_multipart)
end

#service_feedback(transaction_page_slug) ⇒ Object

Fetch all service feedback from the performance platform for a given transaction page slug.

Makes a GET request.

The results are ordered date ascending.

needed.

# @example

performance_platform_data_out.service_feedback('register-to-vote')

#=> {
    "data": [
 {
   "_day_start_at": "2014-06-10T00:00:00+00:00",
   "_hour_start_at": "2014-06-10T00:00:00+00:00",
   "_id": "20140610_register-to-vote",
   "_month_start_at": "2014-06-01T00:00:00+00:00",
   "_quarter_start_at": "2014-04-01T00:00:00+00:00",
   "_timestamp": "2014-06-10T00:00:00+00:00",
   "_updated_at": "2014-06-11T00:30:50.901000+00:00",
   "_week_start_at": "2014-06-09T00:00:00+00:00",
   "comments": 217,
   "period": "day",
   "rating_1": 4,
   "rating_2": 6,
   "rating_3": 7,
   "rating_4": 74,
   "rating_5": 574,
   "slug": "register-to-vote",
   "total": 665
 },
 ...
}

Parameters:

  • transaction_page_slug (String)

    The slug for which service feedback is


43
44
45
# File 'lib/gds_api/performance_platform/data_out.rb', line 43

def service_feedback(transaction_page_slug)
  get_json("#{endpoint}/data/#{transaction_page_slug}/customer-satisfaction")
end

#statistics(options, is_multipart = false) ⇒ Object

This can be used as a free form call to the performance platform. The performance platform uses Backdrop and its query language for storing and querying data. Backdrop can be found here: github.com/alphagov/backdrop


115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/gds_api/performance_platform/data_out.rb', line 115

def statistics(options, is_multipart = false)
  params = {
      group_by: options[:group_by],
      collect: options[:collect],
      duration: 42,
      period: "day",
      end_at: Date.today.to_time.getutc.iso8601
  }

  filter_param = is_multipart ? :filter_by_prefix : :filter_by
  params[filter_param] = "pagePath:" + options[:slug]

  get_json("#{endpoint}/data/govuk-info/#{options[:transaction]}#{query_string(params)}")
end