Class: Gonzui::StatisticsServlet

Inherits:
GonzuiAbstractServlet show all
Defined in:
lib/gonzui/webapp/stat.rb

Constant Summary collapse

RankingMax =
100

Constants included from URIMaker

URIMaker::ParamTable

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GonzuiAbstractServlet

#format_html, #get_media_type, #get_mime_type, #init_servlet, #initialize, #log, #make_path, #set_content_type_text_html

Methods included from HTMLMaker

#make_content_script_type, #make_css, #make_footer, #make_format_select, #make_h1, #make_html, #make_license_select, #make_meta, #make_meta_and_css, #make_navi, #make_property_select, #make_script, #make_search_form, #make_spacer, #make_status_line, #make_title

Methods included from URIMaker

#decompose_search_query, #escape_path, #get_default_query_value, #get_query_value, #get_short_name, #make_advanced_search_uri, #make_doc_uri, #make_google_uri, #make_lineno_uri, #make_markup_uri, #make_search_uri, #make_search_uri_partial, #make_source_uri, #make_stat_uri, #make_top_uri, #make_uri_general, #make_uri_with_options

Methods included from GetText

#gettext, #gettext_noop, #load_catalog, #set_catalog

Methods included from Util

assert, assert_equal, assert_equal_all, assert_non_nil, assert_not_reached, benchmark, command_exist?, commify, eprintf, format_bytes, program_name, protect_from_signals, require_command, set_verbosity, shell_escape, unix?, vprintf, windows?, wprintf

Constructor Details

This class inherits a constructor from Gonzui::GonzuiAbstractServlet

Class Method Details

.mount_pointObject



14
15
16
# File 'lib/gonzui/webapp/stat.rb', line 14

def self.mount_point
  "stat"
end

Instance Method Details

#choose_tr_class(i) ⇒ Object



20
21
22
# File 'lib/gonzui/webapp/stat.rb', line 20

def choose_tr_class(i)
  if (i + 1) % 2 == 0 then "even" else "odd" end
end

#do_GET(request, response) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/gonzui/webapp/stat.rb', line 114

def do_GET(request, response)
  init_servlet(request, response)
  log()

  @path = make_path
  title, status_line, content = make_top_page
  
  html = make_html
  head = [:head, title, make_script, *make_meta_and_css]
  body = [:body]
  body.push(make_h1)
  body.push(make_search_form)
  body.push(status_line)
  body.push(content)
  body.push(make_footer)
  html.push(head)
  html.push(body)
  set_content_type_text_html
  response.body = format_html(html)
end

#do_make_status_lineObject



40
41
42
# File 'lib/gonzui/webapp/stat.rb', line 40

def do_make_status_line
  []
end

#make_bar(freq, max) ⇒ Object



34
35
36
37
38
# File 'lib/gonzui/webapp/stat.rb', line 34

def make_bar(freq, max)
  percentage = freq * 100 / max
  style = "width: #{percentage}px;"
  bar = [:div, {:class => "bar", :style => style}, ""]
end

#make_format_tableObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gonzui/webapp/stat.rb', line 61

def make_format_table
  table = [:table, {:class => "fullwidth"}]
  heading = make_heading([_("Contents by Format"), "first", 3])
  table.push(heading)
  formats = []
  max = -1
  @dbm.each_format {|format_id, format_abbrev, format_name|
    ncontents = @dbm.get_ncontents_by_format_id(format_id)
    formats.push([format_id, format_abbrev, format_name, ncontents])
    max = [max, ncontents].max
  }
  return if formats.empty?
  formats = formats.sort_by {|id, abbr, name, ncontents| - ncontents}
  formats.each_with_index {|item, i|
    id, abbr, name, ncontents = item
    text = name
    tr = make_tr(text, ncontents, make_bar(ncontents, max))
    k = choose_tr_class(i)
    tr.insert(1, {:class => k})
    table.push(tr)
  }
  return table
end

#make_heading(*items) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/gonzui/webapp/stat.rb', line 24

def make_heading(*items)
  tr = [:tr, {:class => "heading"}]
  items.each {|string, klass, colspan|
    td = [:td, {:class => klass}, string]
    td[1][:colspan] = colspan if colspan
    tr.push(td)
  }
  return tr
end

#make_overview_tableObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/gonzui/webapp/stat.rb', line 85

def make_overview_table
  table = [:table, {:class => "fullwidth"}]
  heading = make_heading([_("Overview"), "first", 2])
  table.push(heading)
  trs = []
  trs << make_tr(_("Packages"),        @dbm.get_npackages)
  trs << make_tr(_("Contents"),           @dbm.get_ncontents)
  trs << make_tr(_("Indexed Contents"),   @dbm.get_ncontents_indexed)
  trs << make_tr(_("Binary Contents"),    @dbm.get_ncontents - @dbm.get_ncontents_indexed)
  trs << make_tr(_("Lines of Indexed Contents"),   @dbm.get_nlines_indexed)
  trs << make_tr(_("Indexed Keys"),    @dbm.get_nwords)
  trs << make_tr(_("Formats"),         @dbm.get_nformats)
  trs.each_with_index {|tr, i|
    k = choose_tr_class(i)
    tr.insert(1, {:class => k})
    table.push(tr)
  }
  return table
end

#make_top_pageObject



105
106
107
108
109
110
111
112
# File 'lib/gonzui/webapp/stat.rb', line 105

def make_top_page
  title = make_title( _("Statistics"))
  content = [:div]
  content.push(make_overview_table)
  content.push(make_format_table)
  status_line = make_status_line(_("Statistics"))
  return title, status_line, content
end

#make_tr(first, second, third = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gonzui/webapp/stat.rb', line 44

def make_tr(first, second, third = nil)
  tr = [:tr]
  td1 = [:td, {:class => "first", :width => "76%"}, first]
  if third
    td2 = [:td, {:class => "nonfirst-right", :width => "12%"}, 
      commify(second)]
    td3 = [:td, {:width => "12%"}, third]
  else
    td2 = [:td, {:class => "nonfirst-center", :width => "24%"}, 
      commify(second)]
  end
  tr.push(td1)
  tr.push(td2)
  tr.push(td3) if td3
  return tr
end