Class: Stats::PublishReport
- Inherits:
-
EventReport
- Object
- Report
- EventReport
- Stats::PublishReport
- Defined in:
- lib/stats/publish_report.rb
Constant Summary
Constants inherited from EventReport
EventReport::AMMAP_COUNTRIES, EventReport::MinimumMapBubbleSize, EventReport::PRECISION_DURATION, EventReport::PRECISION_GB, EventReport::SUPPRESSED_LABELS
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ PublishReport
constructor
A new instance of PublishReport.
- #to_json(options = {}) ⇒ Object
- #to_xml(options = {}) ⇒ Object
Methods inherited from EventReport
calculate_bubble_size, format_duration, format_float, format_gb, #get_start_date, get_url, make_title_value, #set_date, to_ammap_country_data, to_ammap_metro_data, #to_csv, zoom_levels
Methods inherited from Report
#==, #[], array_to_csv, array_to_xml, csv_labels, format_csv_value, pad_reports, set_attributes, set_numeric_attributes, strip_label, #the_csv_keys, #to_csv
Constructor Details
#initialize(options = {}) ⇒ PublishReport
Returns a new instance of PublishReport.
7 8 9 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 |
# File 'lib/stats/publish_report.rb', line 7 def initialize( = {}) @start_date = [:date] if 'day' == [:group] @date = [:date] else @end_date = [:date].advance([:advance_by] => 1).advance(:days => -1) end @label = [:label] @assets_uploaded = [:assets_uploaded].to_i @assets_encoded = [:assets_encoded].to_i @query_time = nil @bytes_uploaded = [:bytes_uploaded].to_i @bytes_uploaded_gb = self.class.format_gb([:bytes_uploaded].to_i / 1.gigabyte.to_f) @bytes_encoded = [:bytes_encoded].to_i @bytes_encoded_gb = self.class.format_gb([:bytes_encoded].to_i / 1.gigabyte.to_f) @duration_uploaded = self.class.format_duration([:duration_uploaded].to_f) @duration_uploaded_min = self.class.format_duration([:duration_uploaded].to_f / 60.seconds.to_f) @duration_encoded = self.class.format_duration([:duration_encoded].to_f) @duration_encoded_min = self.class.format_duration([:duration_encoded].to_f / 60.seconds.to_f) end |
Class Method Details
.csv_keys ⇒ Object
36 37 38 |
# File 'lib/stats/publish_report.rb', line 36 def self.csv_keys [ :assets_encoded, :assets_uploaded, :bytes_encoded, :bytes_uploaded, :duration_uploaded, :duration_encoded, :date, :start_date, :end_date ] end |
.to_amcharts(reports, show_date, show_date_range, options = {}) ⇒ Object
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/stats/publish_report.rb', line 72 def self.to_amcharts(reports, show_date, show_date_range, = {}) assets_encoded = [] assets_uploaded = [] bytes_encoded = [] bytes_uploaded = [] complete_labels = [] duration_encoded = [] duration_uploaded = [] guids = [] labels = [] urls = [] reports = reports.reverse if [:reverse] reports.each do |report| label = case [:group] when 'daily' ; "#{report.date.month}/#{report.date.day}" when 'weekly' ; "#{report.start_date.month}/#{report.start_date.day}-#{report.end_date.month}/#{report.end_date.day}" when 'monthly' ; "#{report.start_date.strftime("%b \'%y")}" else raise "invalid group: #{[:group]}" end complete_labels << label labels << label.previewize(([:max_label_length] || 15).to_i) assets_uploaded << report.assets_uploaded duration_uploaded << report.duration_uploaded_min bytes_uploaded << report.bytes_uploaded_gb assets_encoded << report.assets_encoded duration_encoded << report.duration_encoded_min bytes_encoded << report.bytes_encoded_gb guids << report.id end show_screenshots = reports.length <= 10 max_labels = 40 # frequency == 1 if we can display all labels, or a number greater # than 1 if we can't frequency = (show_date || show_date_range) ? 1 : (labels.length / max_labels.to_f).ceil xml = [:builder] ||= Builder::XmlMarkup.new(:indent => 2) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.chart do xml.series do labels.each_with_index do |value, index| # only display every nth value where n depends the total # number of labels and the max labels we are allowed to # display, otherwise clear out the value value = "" if index % frequency != 0 xml.value value, :xid => index end end xml.graphs do #the gid is used in the settings file to set different settings just for this graph unless [:show_uploads] == 'false' xml.graph :gid => 'assets_uploaded' do assets_uploaded.each_with_index do |value, index| if value != 0 || show_date || show_date_range xml.value value, :xid => index end end end end unless [:show_duration_uploaded] == 'false' xml.graph :gid => 'duration_uploaded' do duration_uploaded.each_with_index do |value, index| if value != 0 || show_date || show_date_range xml.value value, :xid => index end end end end unless [:show_encodes] == 'false' xml.graph :gid => 'assets_encoded' do assets_encoded.each_with_index do |value, index| if value != 0 || show_date || show_date_range xml.value value, :xid => index end end end end unless [:show_duration_encoded] == 'false' xml.graph :gid => 'duration_encoded' do duration_encoded.each_with_index do |value, index| if value != 0 || show_date || show_date_range xml.value value, :xid => index end end end end end end end |
Instance Method Details
#to_json(options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/stats/publish_report.rb', line 57 def to_json( = {}) report = HashWithIndifferentAccess.new report['assets_encoded'] = @assets_encoded report['assets_uploaded'] = @assets_uploaded report['bytes_encoded'] = @bytes_encoded report['bytes_uploaded'] = @bytes_uploaded report['date'] = pretty_time(@date) if @date report['duration_encoded'] = @duration_encoded report['duration_uploaded'] = @duration_uploaded report['end_date'] = pretty_time(@end_date) if @end_date report['start_date'] = pretty_time(@start_date) if @start_date report.to_json end |
#to_xml(options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/stats/publish_report.rb', line 40 def to_xml = {} xml = [:builder] ||= Builder::XmlMarkup.new(:indent => [:indent]) xml.instruct! unless [:skip_instruct] xml.__send__(@label) do xml.assets_encoded @assets_encoded xml.assets_uploaded @assets_uploaded xml.bytes_encoded @bytes_encoded xml.bytes_uploaded @bytes_uploaded xml.date(pretty_time(@date)) if @date xml.duration_encoded @duration_encoded xml.duration_uploaded @duration_uploaded xml.end_date(pretty_time(@end_date)) if @end_date xml.start_date(pretty_time(@start_date)) if @start_date end end |