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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.rdoc +25 -0
- data/Rakefile +1 -0
- data/ext/stream_stats/extconf.rb +3 -0
- data/ext/stream_stats/stream_stats.c +32 -15
- data/ext/stream_stats/stream_stats_counter.c +21 -9
- data/lib/stream_stats/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b87874d11a25095ba4079528dea15a7d170d64aa
|
4
|
+
data.tar.gz: b3cf2f2ec15a8b15b80e25cb6acaca3914e9e49a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b96707654c75d9adfaf4819d4fea1aeb00dd86355ded1a347643924e5af51321aaca4429cd760e42b8db65e25ff749d084fcd1ad3c24e5287860337bb8e8e8e8
|
7
|
+
data.tar.gz: f6ba9f05d0b6576a65aa0082044e97cc4027d887f12c0fda95178f4233e757c101fba74de65df26fbfc478b5fe967c748762feeed602943c76cb8ca741cb377c
|
data/Gemfile.lock
CHANGED
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
data/ext/stream_stats/extconf.rb
CHANGED
@@ -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
|
-
|
19
|
+
i_timer = (timer *) malloc(sizeof(timer));
|
16
20
|
|
17
|
-
|
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
|
-
|
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
|
-
|
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
|
59
|
+
double sample;
|
60
|
+
timer *i_timer;
|
61
|
+
int returned;
|
57
62
|
|
58
|
-
|
63
|
+
sample = NUM2DBL(rb_sample);
|
64
|
+
i_timer = (timer*) strstat_get_struct(self);
|
59
65
|
|
60
|
-
|
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
|
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
|
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
|
-
|
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
|
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
|
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
|
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
|
-
|
12
|
+
i_counter = (counter *) malloc(sizeof(counter));
|
11
13
|
|
12
14
|
init_counter(i_counter);
|
13
15
|
|
14
|
-
|
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
|
-
|
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
|
-
|
36
|
+
sample = NUM2DBL(rb_sample);
|
31
37
|
|
32
|
-
|
38
|
+
i_counter = (counter*) strstat_get_struct(self);
|
33
39
|
|
34
|
-
|
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
|
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
|
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
|
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
|
|
data/lib/stream_stats/version.rb
CHANGED