stream_stats 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84b135a85d843c06875ca540fd2a492d932f1a7c
4
- data.tar.gz: 2c3747c578d13fa06f344cfa2a2079faa03bdc4f
3
+ metadata.gz: b87874d11a25095ba4079528dea15a7d170d64aa
4
+ data.tar.gz: b3cf2f2ec15a8b15b80e25cb6acaca3914e9e49a
5
5
  SHA512:
6
- metadata.gz: 3ca93d154216b3e4eebe987a214517d8cf9516c14513fed62102a7d0a91104336ae7dc2d20c96a01e606a8aded8be1314d044252f03f378f615e2b0c6d931c6d
7
- data.tar.gz: 39870beb67f6d297a944b4c6215f211f8f00a6f2f5a62edfbf794e49ad0555d8dd978f949325a5bace3218519fa51d3a1159c9fbd3c2a39d36993d9e52469082
6
+ metadata.gz: b96707654c75d9adfaf4819d4fea1aeb00dd86355ded1a347643924e5af51321aaca4429cd760e42b8db65e25ff749d084fcd1ad3c24e5287860337bb8e8e8e8
7
+ data.tar.gz: f6ba9f05d0b6576a65aa0082044e97cc4027d887f12c0fda95178f4233e757c101fba74de65df26fbfc478b5fe967c748762feeed602943c76cb8ca741cb377c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stream_stats (0.0.4)
4
+ stream_stats (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -11,6 +11,8 @@ Add to Gemfile or gem install and require
11
11
 
12
12
  == Usage
13
13
 
14
+ === Stream Quantile Processing
15
+
14
16
  Create stream and add values
15
17
 
16
18
  stream = StreamStats::Stream.new(0.001, [0.50, 0.90])
@@ -39,6 +41,29 @@ Get stream result whenever desired:
39
41
  sum - query sum of stream entries
40
42
  squared_sum - query squared sum of stream entries
41
43
 
44
+ === Stream Counting
45
+
46
+ Create counter and add values
47
+
48
+ counter = StreamStats::Counter.new
49
+
50
+ Populate counter with samples:
51
+
52
+ (0..20).each do |i|
53
+ counter << i
54
+ end
55
+
56
+ Get stream result whenever desired:
57
+
58
+ count - count of stream entries
59
+ min - query min value
60
+ max - query max value
61
+ mean - query mean
62
+ stddev - query standard deviation of stream entries
63
+ sum - query sum of stream entries
64
+ squared_sum - query squared sum of stream entries
65
+
66
+
42
67
  === Credit
43
68
 
44
69
  Complete credit goes to Armon Dadgar.
data/Rakefile CHANGED
@@ -35,6 +35,7 @@ CLEAN.include('ext/**/Makefile')
35
35
  CLEAN.include("lib/#{NAME}/#{NAME}.#{RbConfig::CONFIG['DLEXT']}")
36
36
  CLOBBER.include("lib/**/*.#{RbConfig::CONFIG['DLEXT']}")
37
37
 
38
+ task :build => [:clean]
38
39
 
39
40
  Rake::TestTask.new(:test) do |t|
40
41
  t.libs << 'lib'
@@ -1,3 +1,6 @@
1
1
  require 'mkmf'
2
2
 
3
+ $CFLAGS += ' ' unless $CFLAGS.empty?
4
+ $CFLAGS += '-std=c99'
5
+
3
6
  create_makefile('stream_stats/stream_stats')
@@ -11,12 +11,14 @@ static void strstat_timer_free(void *ptr) {
11
11
  }
12
12
 
13
13
  static VALUE strstat_timer_init(VALUE self, VALUE rb_eps, VALUE rb_quantiles) {
14
+ timer *i_timer;
15
+ VALUE data;
16
+ double eps, *quantiles;
17
+ uint32_t num_quantiles;
14
18
 
15
- timer *i_timer = (timer *) malloc(sizeof(timer));
19
+ i_timer = (timer *) malloc(sizeof(timer));
16
20
 
17
- double eps = NUM2DBL(rb_eps);
18
- double *quantiles;
19
- uint32_t num_quantiles;
21
+ eps = NUM2DBL(rb_eps);
20
22
 
21
23
  switch (TYPE(rb_quantiles)) {
22
24
  case T_ARRAY:
@@ -37,7 +39,7 @@ static VALUE strstat_timer_init(VALUE self, VALUE rb_eps, VALUE rb_quantiles) {
37
39
 
38
40
  init_timer(eps, quantiles, num_quantiles, i_timer);
39
41
 
40
- VALUE data = Data_Wrap_Struct(timer_class, NULL, strstat_timer_free, i_timer);
42
+ data = Data_Wrap_Struct(timer_class, NULL, strstat_timer_free, i_timer);
41
43
  rb_ivar_set(self, rb_intern("internal_struct"), data);
42
44
 
43
45
  return Qnil;
@@ -45,19 +47,23 @@ static VALUE strstat_timer_init(VALUE self, VALUE rb_eps, VALUE rb_quantiles) {
45
47
 
46
48
  static void *strstat_get_struct(VALUE self) {
47
49
  void *ptr;
50
+ VALUE data;
48
51
 
49
- VALUE data = rb_ivar_get(self, rb_intern("internal_struct"));
52
+ data = rb_ivar_get(self, rb_intern("internal_struct"));
50
53
  Data_Get_Struct(data, timer, ptr);
51
54
  return ptr;
52
55
  }
53
56
 
54
57
  static VALUE strstat_timer_add_sample(VALUE self, VALUE rb_sample) {
55
58
 
56
- double sample = NUM2DBL(rb_sample);
59
+ double sample;
60
+ timer *i_timer;
61
+ int returned;
57
62
 
58
- timer *i_timer = (timer*) strstat_get_struct(self);
63
+ sample = NUM2DBL(rb_sample);
64
+ i_timer = (timer*) strstat_get_struct(self);
59
65
 
60
- int returned = timer_add_sample(i_timer, sample);
66
+ returned = timer_add_sample(i_timer, sample);
61
67
  if (returned != 0) {
62
68
  rb_raise(rb_eRuntimeError, "add sample returned %d", returned);
63
69
  }
@@ -66,22 +72,29 @@ static VALUE strstat_timer_add_sample(VALUE self, VALUE rb_sample) {
66
72
  }
67
73
 
68
74
  static VALUE strstat_timer_count(VALUE self) {
69
- timer *i_timer = (timer*) strstat_get_struct(self);
75
+ timer *i_timer;
76
+
77
+ i_timer = (timer*) strstat_get_struct(self);
70
78
 
71
79
  return LONG2NUM(timer_count(i_timer));
72
80
  }
73
81
 
74
82
  static VALUE strstat_timer_query(VALUE self, VALUE rb_query) {
75
- double query = NUM2DBL(rb_query);
83
+ double query;
84
+ timer *i_timer;
85
+
86
+ query = NUM2DBL(rb_query);
76
87
  if (query < 0 || query > 1)
77
88
  rb_raise(rb_eRuntimeError, "invalid quantile");
78
89
 
79
- timer *i_timer = (timer*) strstat_get_struct(self);
90
+ i_timer = (timer*) strstat_get_struct(self);
80
91
  return DBL2NUM(timer_query(i_timer, query));
81
92
  }
82
93
 
83
94
  static VALUE strstat_timer_percentile(VALUE self, VALUE rb_percentile) {
84
- int percentile = NUM2INT(rb_percentile);
95
+ int percentile;
96
+
97
+ percentile = NUM2INT(rb_percentile);
85
98
  if (percentile < 0 || percentile > 100)
86
99
  rb_raise(rb_eRuntimeError, "invalid percentile");
87
100
 
@@ -89,7 +102,9 @@ static VALUE strstat_timer_percentile(VALUE self, VALUE rb_percentile) {
89
102
  }
90
103
 
91
104
  static VALUE strstat_timer_commoncall(VALUE self, double(*func)(timer*)) {
92
- timer *i_timer = (timer*) strstat_get_struct(self);
105
+ timer *i_timer;
106
+
107
+ i_timer = (timer*) strstat_get_struct(self);
93
108
  return DBL2NUM((*func)(i_timer));
94
109
  }
95
110
 
@@ -115,7 +130,9 @@ static VALUE strstat_timer_squared_sum(VALUE self) {
115
130
  extern void Init_stream_stats_counter(void);
116
131
 
117
132
  void Init_stream_stats(void) {
118
- VALUE module = rb_define_module("StreamStats");
133
+ VALUE module;
134
+
135
+ module = rb_define_module("StreamStats");
119
136
 
120
137
  timer_class = rb_define_class_under(module, "Stream", rb_cObject);
121
138
 
@@ -6,12 +6,14 @@
6
6
  VALUE counter_class;
7
7
 
8
8
  static VALUE strstat_counter_init(VALUE self) {
9
+ counter *i_counter;
10
+ VALUE data;
9
11
 
10
- counter *i_counter = (counter *) malloc(sizeof(counter));
12
+ i_counter = (counter *) malloc(sizeof(counter));
11
13
 
12
14
  init_counter(i_counter);
13
15
 
14
- VALUE data = Data_Wrap_Struct(counter_class, NULL, free, i_counter);
16
+ data = Data_Wrap_Struct(counter_class, NULL, free, i_counter);
15
17
  rb_ivar_set(self, rb_intern("internal_struct"), data);
16
18
 
17
19
  return Qnil;
@@ -19,19 +21,23 @@ static VALUE strstat_counter_init(VALUE self) {
19
21
 
20
22
  static void *strstat_get_struct(VALUE self) {
21
23
  void *ptr;
24
+ VALUE data;
22
25
 
23
- VALUE data = rb_ivar_get(self, rb_intern("internal_struct"));
26
+ data = rb_ivar_get(self, rb_intern("internal_struct"));
24
27
  Data_Get_Struct(data, counter, ptr);
25
28
  return ptr;
26
29
  }
27
30
 
28
31
  static VALUE strstat_counter_add_sample(VALUE self, VALUE rb_sample) {
32
+ double sample;
33
+ counter *i_counter;
34
+ int returned;
29
35
 
30
- double sample = NUM2DBL(rb_sample);
36
+ sample = NUM2DBL(rb_sample);
31
37
 
32
- counter *i_counter = (counter*) strstat_get_struct(self);
38
+ i_counter = (counter*) strstat_get_struct(self);
33
39
 
34
- int returned = counter_add_sample(i_counter, sample);
40
+ returned = counter_add_sample(i_counter, sample);
35
41
  if (returned != 0) {
36
42
  rb_raise(rb_eRuntimeError, "add sample returned %d", returned);
37
43
  }
@@ -40,13 +46,17 @@ static VALUE strstat_counter_add_sample(VALUE self, VALUE rb_sample) {
40
46
  }
41
47
 
42
48
  static VALUE strstat_counter_count(VALUE self) {
43
- counter *i_counter = (counter*) strstat_get_struct(self);
49
+ counter *i_counter;
50
+
51
+ i_counter = (counter*) strstat_get_struct(self);
44
52
 
45
53
  return LONG2NUM(counter_count(i_counter));
46
54
  }
47
55
 
48
56
  static VALUE strstat_counter_commoncall(VALUE self, double(*func)(counter*)) {
49
- counter *i_counter = (counter*) strstat_get_struct(self);
57
+ counter *i_counter;
58
+
59
+ i_counter = (counter*) strstat_get_struct(self);
50
60
  return DBL2NUM((*func)(i_counter));
51
61
  }
52
62
 
@@ -70,7 +80,9 @@ static VALUE strstat_counter_squared_sum(VALUE self) {
70
80
  }
71
81
 
72
82
  void Init_stream_stats_counter(void) {
73
- VALUE module = rb_define_module("StreamStats");
83
+ VALUE module;
84
+
85
+ module = rb_define_module("StreamStats");
74
86
 
75
87
  counter_class = rb_define_class_under(module, "Counter", rb_cObject);
76
88
 
@@ -1,3 +1,3 @@
1
1
  module StreamStats
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stream_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neville Kadwa