snapstats 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 417ac8a47a89389f3cf4ab6802afc5b77bd14d3e
4
- data.tar.gz: ab877ec2ffe285e2aa47a57eb9a88120669853da
3
+ metadata.gz: 3b4173e26fe094b94b9915c2a66d8f25d2ac3cf2
4
+ data.tar.gz: f1781889c78345501c71d04262defa290a10c071
5
5
  SHA512:
6
- metadata.gz: 927e5b9f3052d5ac603aafe0b39e09d8b40faf64929877fccb9670ca0b016db6d1a39a59bf45446836f1e64b8ed4a30e45808f8ff35cb84557b5b6293c9f0f66
7
- data.tar.gz: 0794eb15edb0627e949c0d82d40bb08a05b129661f573804a33206764469afc4226b6c940ee98179a3934bfa3d9b5c873f61a612d5369d3918a017256edfd773
6
+ metadata.gz: 7fb4f552e6162053d20cb684502ac0ea029165b74ac81e6abd459d8de0fc2482d95e507cd18c65ac8b94d98426e14eac093f446fc07741ad464e4406e24a519a
7
+ data.tar.gz: e4dc7bf545a41829226db38f0a2b7dad3c28e636fa664eb0f1cadff292c471a6ba36cd3290a763e9725ab117fe7592d5eb1805697e2fa5304748b08d1b01fcb1
@@ -12,13 +12,18 @@ $(document).ready(function () {
12
12
  return false;
13
13
  }
14
14
 
15
+ self.run_autoupdate();
16
+ },
17
+
18
+ run_autoupdate : function () {
19
+ var self = this;
15
20
  self.draw_chart();
21
+ setInterval(function () { self.draw_chart() }, 5000);
16
22
  },
17
23
 
18
24
  draw_chart : function () {
19
25
  var self = this;
20
26
 
21
-
22
27
  $.getJSON(self.data_path, function (data) {
23
28
 
24
29
  for (var i = 0; i < data.length; i++) {
@@ -26,9 +31,10 @@ $(document).ready(function () {
26
31
  }
27
32
 
28
33
  MG.data_graphic({
29
- data: data,
30
34
 
35
+ data: data,
31
36
  full_width: true,
37
+
32
38
  height: self.torso.height * 3 / 2,
33
39
  right: self.torso.right,
34
40
 
@@ -37,9 +43,12 @@ $(document).ready(function () {
37
43
  x_accessor: "date",
38
44
  y_accessor: "value",
39
45
  interpolate: "linear",
40
- y_scale_type:'log',
46
+ // y_scale_type:'log'
41
47
  });
42
48
 
49
+ $('.loader').hide();
50
+ $('.chart').addClass('animated fadeIn');
51
+
43
52
  });
44
53
 
45
54
  }
@@ -1,8 +1,9 @@
1
1
  $(document).ready(function () {
2
2
  ({
3
3
 
4
- when_cat : "li.section-performance",
5
- data_path : ($(location).attr('pathname') + '/chart').replace('//', '/'),
4
+ when_cat : "li.section-performance",
5
+ data_path : ($(location).attr('pathname') + '/chart').replace('//', '/'),
6
+ flat_data_path : ($(location).attr('pathname') + '/flat_chart').replace('//', '/'),
6
7
 
7
8
  torso : { width : 375, height : 200, right : 20 },
8
9
 
@@ -13,7 +14,58 @@ $(document).ready(function () {
13
14
  return false;
14
15
  }
15
16
 
16
- self.draw_chart();
17
+ self.init_buttons();
18
+
19
+ // self.draw_chart();
20
+ self.draw_flat_chart();
21
+ },
22
+
23
+ init_buttons : function () {
24
+ var self = this;
25
+
26
+ $('.detail-chart').click(function () {
27
+ self.draw_chart();
28
+
29
+ $('.legend').show();
30
+ $(this).siblings().removeClass('active');
31
+ $(this).addClass('active');
32
+ });
33
+
34
+ $('.total-chart').click(function () {
35
+ self.draw_flat_chart();
36
+
37
+ $('.legend').hide();
38
+ $(this).siblings().removeClass('active');
39
+ $(this).addClass('active');
40
+ });
41
+ },
42
+
43
+ draw_flat_chart : function () {
44
+ var self = this;
45
+
46
+ $.getJSON(self.flat_data_path, function (data) {
47
+
48
+ for (var i = 0; i < data.length; i++) {
49
+ data[i].date = new Date(data[i].date*1000)
50
+ }
51
+
52
+ MG.data_graphic({
53
+
54
+ data: data,
55
+ full_width: true,
56
+
57
+ height: self.torso.height * 3 / 2,
58
+ right: self.torso.right,
59
+
60
+ target: ".chart-performance",
61
+ x_extended_ticks: true,
62
+ x_accessor: "date",
63
+ y_accessor: "value",
64
+ // y_scale_type:'log',
65
+ interpolate: "linear"
66
+ });
67
+ });
68
+
17
69
  },
18
70
 
19
71
  draw_chart : function () {
@@ -36,11 +88,16 @@ $(document).ready(function () {
36
88
  target: '.chart-performance',
37
89
  x_accessor: 'date',
38
90
  y_accessor: 'value',
39
- interpolate: "linear",
40
- y_scale_type:'log',
41
- // y_label: "milliseconds",
91
+ interpolate: "basic",
92
+ y_scale_type:'linear',
42
93
  legend: data.legend,
43
- legend_target: '.legend'
94
+ legend_target: '.legend',
95
+
96
+ // y_label: "milliseconds",
97
+ // y_extended_ticks: true,
98
+ // yax_format: d3.time.format('%B'),
99
+
100
+ // yax_units: 'ms '
44
101
  });
45
102
 
46
103
  });
@@ -12,10 +12,16 @@ $(document).ready(function () {
12
12
  return false;
13
13
  }
14
14
 
15
- self.user_chart();
15
+ self.run_autoupdate();
16
16
  },
17
17
 
18
- user_chart : function () {
18
+ run_autoupdate : function () {
19
+ var self = this;
20
+ self.draw_chart();
21
+ setInterval(function () { self.draw_chart() }, 5000);
22
+ },
23
+
24
+ draw_chart : function () {
19
25
  var self = this;
20
26
 
21
27
  if ( $('div.user-activity-chart').length <= 0 ){
@@ -43,6 +49,8 @@ $(document).ready(function () {
43
49
  interpolate: "linear"
44
50
  });
45
51
 
52
+ $('.loader').hide();
53
+
46
54
  });
47
55
 
48
56
  }
@@ -43,10 +43,6 @@ ul.menu li { display: inline; margin-right: 15px;}
43
43
  ul.menu li a { text-decoration: none; color: #767F73; }
44
44
  ul.menu li.active a, ul.menu li a:hover { color: white; }
45
45
 
46
- .chart{
47
- margin-top: 70px;
48
- }
49
-
50
46
  .panel-wgt {
51
47
  background: none;
52
48
  border: 1px solid #3A344A;
@@ -63,4 +59,48 @@ ul.menu li.active a, ul.menu li a:hover { color: white; }
63
59
  overflow: hidden;
64
60
  text-overflow: ellipsis;
65
61
  white-space: nowrap;
62
+ }
63
+
64
+ .btn-trigger {
65
+ font-size: 10px;
66
+
67
+ background: none;
68
+ border:0px solid #3A344A;
69
+
70
+ padding: 1px;
71
+ margin: 0px 3px;
72
+
73
+ color: #767F73;
74
+ }
75
+
76
+ .btn-trigger:hover {
77
+ border: 0px solid #4A445A;
78
+ color: #ccc;
79
+ }
80
+
81
+ .btn-trigger.active {
82
+ border-bottom: 1px dashed #ccc;
83
+ border-radius: 0;
84
+ color: #ccc;
85
+ }
86
+
87
+ .chart-corner-btns {
88
+ margin-top: -20px;
89
+ }
90
+
91
+ .loader
92
+ {
93
+ width:200px;
94
+ height:200px;
95
+ border-radius:100px;
96
+ font-size:14px;
97
+
98
+ color:#4A445A;
99
+
100
+ margin: 50px auto;
101
+
102
+ line-height:200px;
103
+ text-align:center;
104
+ /*background:#000;*/
105
+ border: 1px dashed #4A445A;
66
106
  }
@@ -14,5 +14,9 @@ module Snapstats
14
14
  render json: {data: data.values, legend: data.keys}
15
15
  end
16
16
 
17
+ def flat_chart
18
+ render json: Snapstats::EventReader::Activity.fetch_flat_chart
19
+ end
20
+
17
21
  end
18
22
  end
@@ -15,7 +15,7 @@ module Snapstats
15
15
  end
16
16
 
17
17
  def chart
18
- render json: EventReader::UserActivity.fetch_chart_for_user(params[:id])
18
+ render json: EventReader::UserActivity.fetch_chart_for_user(params[:id], 5)
19
19
  end
20
20
 
21
21
  end
@@ -5,9 +5,17 @@
5
5
  <div class="panel panel-wgt">
6
6
  <div class="panel-heading">
7
7
  <h3 class="panel-title">Activity</h3>
8
+
9
+ <!-- <div class="pull-right chart-corner-btns">
10
+ <a class="btn btn-trigger active total-chart">5 min</a>
11
+ <a class="btn btn-trigger total-chart">10 min</a>
12
+ <a class="btn btn-trigger total-chart">30 min</a>
13
+ </div> -->
14
+
8
15
  </div>
9
16
  <div class="panel-body">
10
- <div class="chart"></div>
17
+ <div class="loader center-block animated rotateIn">loading</div>
18
+ <div class="chart"></div>
11
19
  </div>
12
20
  </div>
13
21
 
@@ -3,17 +3,23 @@
3
3
  <div class="panel panel-wgt">
4
4
  <div class="panel-heading">
5
5
  <h3 class="panel-title">Load Average</h3>
6
+
7
+ <div class="pull-right chart-corner-btns">
8
+ <a class="btn btn-trigger active total-chart">Total</a>
9
+ <a class="btn btn-trigger detail-chart">Detail</a>
10
+ </div>
11
+
6
12
  </div>
7
13
  <div class="panel-body">
8
14
  <div class="chart-performance"></div>
9
- <div class="legend pull-right"></div>
15
+ <div class="legend pull-right">&nbsp;</div>
10
16
  </div>
17
+
11
18
  </div>
12
19
 
13
20
  </div>
14
21
 
15
22
 
16
-
17
23
  <div class="container animated fadeIn">
18
24
 
19
25
  <div class="page-header">
@@ -30,7 +30,7 @@
30
30
  <th>Browser</th>
31
31
  </tr>
32
32
 
33
- <% @activity.sort_by{ |i| i.date.to_i }.each do |i| %>
33
+ <% @activity.sort_by{ |i| -i.date.to_i }.each do |i| %>
34
34
 
35
35
  <tr>
36
36
  <td>
@@ -15,7 +15,7 @@
15
15
  <th>Path</th>
16
16
  </tr>
17
17
 
18
- <% @users.sort_by{ |i| i.date }.each do |i| %>
18
+ <% @users.sort_by{ |i| -i.date.to_i }.each do |i| %>
19
19
 
20
20
  <tr>
21
21
  <td> <%= link_to i.email, activity_user_path(i.user_id) %> </td>
data/config/routes.rb CHANGED
@@ -12,6 +12,7 @@ Snapstats::Engine.routes.draw do
12
12
  resource :performance do
13
13
  collection do
14
14
  get :chart
15
+ get :flat_chart
15
16
  end
16
17
  end
17
18
 
@@ -1,6 +1,7 @@
1
1
  module Snapstats
2
2
  module EventReader
3
-
3
+ require "event_reader/event_reader_helpers"
4
+
4
5
  class Activity
5
6
  include Virtus.model
6
7
 
@@ -50,6 +51,10 @@ module Snapstats
50
51
 
51
52
  end
52
53
 
54
+ def self.fetch_flat_chart
55
+ fetch(Time.now.beginning_of_day).map{ |i| { date: i.date.to_i, value: i.render_time } }
56
+ end
57
+
53
58
  end
54
59
 
55
60
  class Performance
@@ -97,7 +102,7 @@ module Snapstats
97
102
 
98
103
  class Cpm
99
104
  include Virtus.model
100
-
105
+ extend EventReaderHelpers
101
106
 
102
107
  def self.fetch_all
103
108
  Snapstats.redis.hgetall(Snapstats.mday("cpm"))
@@ -115,14 +120,15 @@ module Snapstats
115
120
  { cpm: cpm, cph: 0, cpd: cpd }
116
121
  end
117
122
 
118
- def self.fetch_all_chart
119
- fetch_all.map{ |k, v| { date: k, value: v } }
123
+ def self.fetch_all_chart aprx=10
124
+ fetch_all.group_by{|k, v| floor_time(k.to_i, aprx.minutes) }.reduce({}){ |sum, (k,v)| sum[k] = v.reduce(0){|s, i| s += i.last.to_i }; sum }.map{ |k, v| { date: k, value: v } }
120
125
  end
121
126
 
122
127
  end
123
128
 
124
129
  class UserActivity
125
130
  include Virtus.model
131
+ extend EventReaderHelpers
126
132
 
127
133
  attribute :email, String
128
134
  attribute :date, Time
@@ -158,8 +164,8 @@ module Snapstats
158
164
  JSON.parse(data, :symbolize_names => true)[:email] if data
159
165
  end
160
166
 
161
- def self.fetch_chart_for_user user_id
162
- fetch_for_user(user_id).group_by{ |i| i.date.beginning_of_minute }.map{ |k, v| { date: k.to_i, value: v.count } }
167
+ def self.fetch_chart_for_user user_id, aprx=10
168
+ fetch_for_user(user_id).group_by{ |i| floor_time(i.date.to_i, aprx.minutes) }.map{ |k, v| { date: k.to_i, value: v.count } }
163
169
  end
164
170
 
165
171
  end
@@ -0,0 +1,7 @@
1
+ module EventReaderHelpers
2
+
3
+ def floor_time sec, fsec
4
+ (Time.at(sec).to_f/fsec).floor*fsec
5
+ end
6
+
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Snapstats
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapstats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - s3k
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -109,6 +109,7 @@ files:
109
109
  - lib/event_logger/event_logger_static.rb
110
110
  - lib/event_logger/event_logger_store.rb
111
111
  - lib/event_reader/event_reader.rb
112
+ - lib/event_reader/event_reader_helpers.rb
112
113
  - lib/ext/redis.rb
113
114
  - lib/snapstats.rb
114
115
  - lib/snapstats/engine.rb