Class: DashboardController

Inherits:
ApplicationController show all
Defined in:
lib/nexmo_developer/app/controllers/dashboard_controller.rb

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::CONFIG

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin!, #not_found, #redirect_vonage_domain

Methods included from ApplicationHelper

#active_sidenav_item, #canonical_base, #canonical_base_from_config, #canonical_path, #canonical_url, #dashboard_cookie, #search_enabled?, #set_utm_cookie, #theme

Instance Method Details

#coverageObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/nexmo_developer/app/controllers/dashboard_controller.rb', line 38

def coverage
  @supported_languages = %w[
    curl
    csharp
    java
    node
    php
    python
    ruby
    json
    xml
  ]
  @product = product

  @complete_coverage = {}

  coverage_from_yaml if ['all', 'yaml'].include?(only)
  coverage_from_files if ['all', 'file'].include?(only)
  coverage_from_unsupported

  ignore_languages.each do |lang|
    @supported_languages.delete(lang)
  end

  if hide_response
    @supported_languages.delete('json')
    @supported_languages.delete('xml')
  end

  @toplevel_summary = {}
  @complete_coverage.each do |toplevel, blocks|
    @toplevel_summary[toplevel] = { 'blocks' => 0, 'langs' => {} } unless @toplevel_summary[toplevel]
    blocks.each do |_section, entries|
      entries.each do |_name, languages|
        @toplevel_summary[toplevel]['blocks'] += 1
        @supported_languages.each do |lang|
          @toplevel_summary[toplevel]['langs'][lang] = 0 unless @toplevel_summary[toplevel]['langs'][lang]
          @toplevel_summary[toplevel]['langs'][lang] += 1 if languages[lang]
        end
      end
    end
  end

  # Remove non-GA features
  if params[:show_ga_only]
    params[:ignore_products] = 'conversation,messages,dispatch,audit,vonage-business-cloud'
  end
  params[:ignore_products]&.split(',')&.each do |key|
    @complete_coverage.delete(key)
    @toplevel_summary.delete(key)
  end

  # Calculate the overall summary
  @overall_summary = { 'blocks' => 0, 'langs' => {} }
  @supported_languages.each do |lang|
    @overall_summary['langs'][lang] = 0
  end

  @toplevel_summary.each do |_title, summary|
    @overall_summary['blocks'] += summary['blocks']
    summary['langs'].each do |lang, value|
      @overall_summary['langs'][lang] += value
    end
  end
end

#statsObject



4
5
6
7
8
# File 'lib/nexmo_developer/app/controllers/dashboard_controller.rb', line 4

def stats
  @feedbacks = Feedback::Feedback.created_between(created_after, created_before)

  @feedbacks = @feedbacks.joins(:resource).where(feedback_resources: { product: product }) if product
end

#stats_summaryObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nexmo_developer/app/controllers/dashboard_controller.rb', line 10

def stats_summary
  return unless created_after || created_before

  @feedbacks = Feedback::Feedback.created_between(created_after, created_before).joins(:resource)

  grouped_results = @feedbacks.group(["DATE_TRUNC('month', feedback_feedbacks.created_at)", 'feedback_resources.product', 'feedback_feedbacks.sentiment']).count(:id)

  # Reformat in to something usable
  @summary = {}
  grouped_results.each do |meta, count|
    month = meta[0]
    prod = meta[1] # Can't call it product due to the method defined in this class
    sentiment = meta[2]
    next unless prod # We have some feedback from non-product pages. Let's ignore that for now

    @summary[prod] = @summary[prod] || {}
    @summary[prod][month] = @summary[prod][month] || {}
    @summary[prod][month][sentiment] = count
  end

  # Sort by product, then by month
  @summary = @summary.sort.to_h

  @summary.each do |product, data|
    @summary[product] = data.sort.to_h
  end
end