rail_stat_generator 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,111 +1,126 @@
1
- require_dependency 'path_tracker'
2
-
3
- class RailStatController < ApplicationController
4
- include PathTracker
5
-
6
- before_filter :extract_subdomain
7
-
8
- def path
9
- @ordered_resources, @orarr = RailStat.get_ordered40resources(@subdomain)
10
-
11
- @number_hits = (@params['nh'] or not @params['nh'].nil?) ? @params['nh'].to_i : 50
12
- @include_search_engines = ((@params['ise'] == '' or @params['ise'] == "1") ? 1 : 0)
13
-
14
- @paths = RailStat.find_all_by_flag(@include_search_engines == 0, @number_hits, @subdomain)
15
- end
16
-
17
- def index
18
- redirect_to(:action=>'path')
19
- end
20
-
21
- def hits
22
- @lastweek = RailStat.get_last_week_stats(@subdomain)
23
- @first_hit = RailStat.find_first_hit(@subdomain)
24
- @total_hits = RailStat.total_count(@subdomain)
25
- @unique_hits = RailStat.unique_count(@subdomain)
26
- n = Time.now
27
- d = Date.new(n.year, n.month, n.day)
28
- @today_total = RailStat.total_day_count(@subdomain, d)
29
- @today_unique = RailStat.unique_day_count(@subdomain, d)
30
- if @first_hit.nil?
31
- render_text "No hits"
32
- end
33
- end
34
-
35
- def platform
36
- hits = RailStat.total_count(@subdomain)
37
- @platforms = RailStat.platform_stats(@subdomain, hits)
38
- @browsers = RailStat.browser_stats(@subdomain, hits)
39
- end
40
-
41
- def lang
42
- hits = RailStat.total_count(@subdomain)
43
- @languages = RailStat.language_stats(@subdomain, hits)
44
- @countries = RailStat.country_stats(@subdomain, hits)
45
- end
46
-
47
- def refs
48
- @refs = RailStat.domain_stats(@subdomain)
49
- @searchterms = SearchTerm.find_grouped(@subdomain)
50
- end
51
-
52
- def other
53
- hits = RailStat.total_count(@subdomain)
54
- @flashes = RailStat.stats_dyn("flash", @subdomain, hits)
55
- @jes = RailStat.stats_dyn("java_enabled", @subdomain, hits)
56
- @javas = RailStat.stats_dyn("java", @subdomain, hits)
57
- @widths = RailStat.stats_dyn("screen_size", @subdomain, hits)
58
- @colors = RailStat.stats_dyn("colors", @subdomain, hits)
59
- end
60
-
61
- def tracker_js
62
- if @request.env['HTTP_REFERER'] and @request.env['HTTP_REFERER'].include?(@request.env['HTTP_HOST'])
63
- str = <<-JSDATA
64
- c=0;
65
- s=0;
66
- n=navigator;
67
- d=document;
68
- plugin=(n.mimeTypes&&n.mimeTypes["application/x-shockwave-flash"])?n.mimeTypes["application/x-shockwave-flash"].enabledPlugin:0;
69
- if(plugin) {
70
- w=n.plugins["Shockwave Flash"].description.split("");
71
- for(i=0;i<w.length;++i) { if(!isNaN(parseInt(w[i]))) { f=w[i];break; } }
72
- } else if(n.userAgent&&n.userAgent.indexOf("MSIE")>=0&&(n.appVersion.indexOf("Win")!=-1)) {
73
- d.write('<script language="VBScript">On Error Resume Next\\nFor f=10 To 1 Step-1\\nv=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash."&f))\\nIf v Then Exit For\\nNext\\n</script>');
74
- } if(typeof(top.document)=="object"){
75
- t=top.document;
76
- rf=escape(t.referrer);
77
- pd=escape(t.URL);
78
- } else {
79
- x=window;
80
- for(i=0;i<20&&typeof(x.document)=="object";i++) { rf=escape(x.document.referrer); x=x.parent; }
81
- pd=0;
82
- }
83
- d.write('<script language="JavaScript1.2">c=screen.colorDepth;s=screen.width;</script>');
84
- if(typeof(f)=='undefined') f=0;
85
- d.write('<a href="/" target="_blank"><img src="/rail_stat/track?size='+s+'&colors='+c+'&referer='+rf+'&java=1&je='+(n.javaEnabled()?1:0)+'&doc='+escape(d.URL)+'&flash='+f+'" border="0" width="1" height="1"></a><br>');
86
- JSDATA
87
- else
88
- str = ""
89
- end
90
- render_text(str)
91
- end
92
-
93
- def track
94
- track_path
95
- @response.headers['Pragma'] = ' '
96
- @response.headers['Cache-Control'] = ' '
97
- @response.headers['Content-Length'] = 68
98
- @response.headers['Accept-Ranges'] = 'bytes'
99
- @response.headers['Content-type'] = 'image/gif'
100
- @response.headers['Content-Disposition'] = 'inline'
101
- File.open("#{RAILS_ROOT}/public/images/railstat/1pxtr.gif", 'rb') { |file| render :text => file.read }
102
- end
103
-
104
-
105
- private
106
- def extract_subdomain
107
- @subdomain = ((@request.subdomains and @request.subdomains.first) ? @request.subdomains.first : nil)
108
- end
109
-
110
- end
111
-
1
+ require_dependency 'path_tracker'
2
+
3
+ class RailStatController < ApplicationController
4
+ include PathTracker
5
+
6
+ before_filter :extract_subdomain
7
+
8
+ def index
9
+ redirect_to(:action=>'path')
10
+ end
11
+
12
+ def path
13
+ @ordered_resources, @orarr = RailStat.get_ordered40resources(@subdomain)
14
+
15
+ @number_hits = (@params['nh'] or not @params['nh'].nil?) ? @params['nh'].to_i : 50
16
+ @include_search_engines = ((@params['ise'] == '' or @params['ise'] == "1") ? 1 : 0)
17
+
18
+ @count_totals = RailStat.resource_count_totals
19
+ @paths = RailStat.find_all_by_flag(@include_search_engines == 0, @number_hits, @subdomain)
20
+
21
+ # Experiments:
22
+ @total_hits = RailStat.count_hits(:subdomain => @subdomain)
23
+ @unique_hits = RailStat.count_hits(:unique, :subdomain => @subdomain)
24
+ end
25
+
26
+ def hits
27
+ @lastweek = RailStat.find_by_days(:subdomain=>@subdomain, :days => 7)
28
+ @first_hit = RailStat.find_first_hit(:subdomain=>@subdomain)
29
+ @total_hits = RailStat.count_hits(:subdomain => @subdomain)
30
+ @unique_hits = RailStat.count_hits(:unique, :subdomain => @subdomain)
31
+ n = Time.now
32
+ d = Date.new(n.year, n.month, n.day)
33
+ @today_total = RailStat.count_hits(:subdomain => @subdomain, :date => d)
34
+ @today_unique = RailStat.count_hits(:unique, :subdomain => @subdomain, :date => d)
35
+ @past_7_total = RailStat.count_hits(:subdomain => @subdomain, :past_days => 7)
36
+ @past_7_unique = RailStat.count_hits(:unique, :subdomain => @subdomain, :past_days => 7)
37
+ end
38
+
39
+ def platform
40
+ @total_hits = RailStat.count_hits(:subdomain => @subdomain)
41
+ @platforms = RailStat.find_by_platform(:subdomain => @subdomain)
42
+ @browsers = RailStat.find_by_browser(:subdomain => @subdomain)
43
+ end
44
+
45
+ def lang
46
+ @total_hits = RailStat.count_hits(:subdomain => @subdomain)
47
+ @languages = RailStat.find_by_language(:subdomain => @subdomain)
48
+ @countries = RailStat.find_by_country(:subdomain => @subdomain)
49
+ end
50
+
51
+ def refs
52
+ @refs = RailStat.find_by_domain(:subdomain => @subdomain)
53
+ @searchterms = SearchTerm.find_grouped(:subdomain => @subdomain)
54
+ end
55
+
56
+ def other
57
+ #hits = RailStat.count_hits(:subdomain => @subdomain)
58
+ #@total_hits = RailStat.count_hits()
59
+
60
+ @flash_clients = RailStat.find_by_client(:type => "flash", :subdomain => @subdomain)
61
+ @flash_clients_total = @flash_clients.inject(0) {|sum, result| sum + result.total.to_i}
62
+
63
+ @java_clients = RailStat.find_by_client(:type => "java_enabled", :subdomain => @subdomain)
64
+ @java_clients_total = @java_clients.inject(0) {|sum, result| sum + result.total.to_i}
65
+
66
+ @javascript_clients = RailStat.find_by_client(:type => "java", :subdomain => @subdomain)
67
+ @javascript_clients_total = @javascript_clients.inject(0) {|sum, result| sum + result.total.to_i}
68
+
69
+ @width_of_clients = RailStat.find_by_client(:type => "screen_size", :subdomain => @subdomain)
70
+ @width_of_clients_total = @width_of_clients.inject(0) {|sum, result| sum + result.total.to_i}
71
+
72
+ @colors_of_clients = RailStat.find_by_client(:type => "colors", :subdomain => @subdomain)
73
+ @colors_of_clients_total = @colors_of_clients.inject(0) {|sum, result| sum + result.total.to_i}
74
+ end
75
+
76
+ def tracker_js
77
+ if @request.env['HTTP_REFERER'] and @request.env['HTTP_REFERER'].include?(@request.env['HTTP_HOST'])
78
+ str = <<-JSDATA
79
+ c=0;
80
+ s=0;
81
+ n=navigator;
82
+ d=document;
83
+ plugin=(n.mimeTypes&&n.mimeTypes["application/x-shockwave-flash"])?n.mimeTypes["application/x-shockwave-flash"].enabledPlugin:0;
84
+ if(plugin) {
85
+ w=n.plugins["Shockwave Flash"].description.split("");
86
+ for(i=0;i<w.length;++i) { if(!isNaN(parseInt(w[i]))) { f=w[i];break; } }
87
+ } else if(n.userAgent&&n.userAgent.indexOf("MSIE")>=0&&(n.appVersion.indexOf("Win")!=-1)) {
88
+ d.write('<script language="VBScript">On Error Resume Next\\nFor f=10 To 1 Step-1\\nv=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash."&f))\\nIf v Then Exit For\\nNext\\n</script>');
89
+ } if(typeof(top.document)=="object"){
90
+ t=top.document;
91
+ rf=escape(t.referrer);
92
+ pd=escape(t.URL);
93
+ } else {
94
+ x=window;
95
+ for(i=0;i<20&&typeof(x.document)=="object";i++) { rf=escape(x.document.referrer); x=x.parent; }
96
+ pd=0;
97
+ }
98
+ d.write('<script language="JavaScript1.2">c=screen.colorDepth;s=screen.width;</script>');
99
+ if(typeof(f)=='undefined') f=0;
100
+ d.write('<a href="/" target="_blank"><img src="/rail_stat/track?size='+s+'&colors='+c+'&referer='+rf+'&java=1&je='+(n.javaEnabled()?1:0)+'&doc='+escape(d.URL)+'&flash='+f+'" border="0" width="1" height="1"></a><br>');
101
+ JSDATA
102
+ else
103
+ str = ""
104
+ end
105
+ render_text(str)
106
+ end
107
+
108
+ def track
109
+ track_path
110
+ @response.headers['Pragma'] = ' '
111
+ @response.headers['Cache-Control'] = ' '
112
+ @response.headers['Content-Length'] = 68
113
+ @response.headers['Accept-Ranges'] = 'bytes'
114
+ @response.headers['Content-type'] = 'image/gif'
115
+ @response.headers['Content-Disposition'] = 'inline'
116
+ File.open("#{RAILS_ROOT}/public/images/railstat/1pxtr.gif", 'rb') { |file| render :text => file.read }
117
+ end
118
+
119
+
120
+ private
121
+ def extract_subdomain
122
+ @subdomain = ((@request.subdomains and @request.subdomains.first) ? @request.subdomains.first : nil)
123
+ end
124
+
125
+ end
126
+
@@ -115,19 +115,18 @@ module RailStatHelper
115
115
  "ji" => "Yiddish",
116
116
  "zu" => "Zulu"}
117
117
 
118
- def initListClass
119
- @itClass = 1
120
- end
121
-
122
- def popListClass
123
- ret = getListClass
124
- @itClass = @itClass + 1
125
- return ret
126
- end
127
-
128
- def getListClass
129
- return "even" if @itClass%2 == 0
130
- return "odd" if @itClass%2 == 1
118
+ def alternator
119
+ if @alternator.nil?
120
+ @alternator = 1
121
+ end
122
+
123
+ @alternator = -@alternator
124
+
125
+ if @alternator == -1
126
+ return "even"
127
+ else
128
+ return "odd"
129
+ end
131
130
  end
132
131
 
133
132
  def get_path_image(path, ors)
@@ -175,7 +174,7 @@ module RailStatHelper
175
174
  end
176
175
 
177
176
  def path_version_data(value)
178
- return 'Unkown' if value.nil?
177
+ return 'Unknown' if value.nil?
179
178
  return 'Unsupported' if value == "0"
180
179
  return 'Supports' if value == "1"
181
180
  return value
@@ -1,5 +1,7 @@
1
+ require 'ipaddr'
1
2
  class Iptoc < ActiveRecord::Base
2
3
  def self.find_by_ip_address(ip_address)
3
- find (:first, :conditions => ["IP_FROM <= inet_aton(?) AND IP_TO >= inet_aton(?)", ip_address, ip_address])
4
+ ip = IPAddr.new(ip_address)
5
+ find(:first, :conditions => ["IP_FROM <= ? AND IP_TO >= ?", ip.to_i, ip.to_i])
4
6
  end
5
7
  end