statsrb 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. data/ext/statsrb/statsrb.c +54 -7
  2. data/lib/statsrb.rb +0 -32
  3. metadata +1 -1
@@ -4,7 +4,13 @@
4
4
  #include <stdlib.h>
5
5
 
6
6
  /**
7
- * Loads a file and filters on a specified namespace.
7
+ * Locates data from a specified file and loads into @data.
8
+ * @param filepath [String]
9
+ * @param namespace [String]
10
+ * @param limit [Number]
11
+ * @param start_time [Number]
12
+ * @param end_time [Number]
13
+ * @return [Statsrb] A reference to the object.
8
14
  */
9
15
  static VALUE statsrb_query(VALUE self, VALUE logfile, VALUE query_ns, VALUE query_limit, VALUE query_start, VALUE query_end) {
10
16
  FILE * file;
@@ -120,7 +126,8 @@ void time_sort(int left, int right, VALUE ary, VALUE statsrb_key_ts) {
120
126
  }
121
127
 
122
128
  /**
123
- * Sort the internal data using a quicksort algorithm based on the hash element's timestamp.
129
+ * Sorts @data using a quicksort algorithm based on the hash element's timestamp.
130
+ * @return [Hash] The sorted data
124
131
  */
125
132
  static VALUE statsrb_sort(VALUE self) {
126
133
  VALUE statsrb_data = rb_iv_get(self, "@data");
@@ -133,7 +140,10 @@ static VALUE statsrb_sort(VALUE self) {
133
140
  }
134
141
 
135
142
  /**
136
- * Write the in-memory data to a file.
143
+ * Writes the @data in memory to a specified file.
144
+ * @param filepath [String]
145
+ * @param filemode [String]
146
+ * @return [Statsrb] A reference to the object.
137
147
  */
138
148
  static VALUE statsrb_write(VALUE self, VALUE logfile, VALUE mode) {
139
149
  FILE * file;
@@ -173,8 +183,14 @@ static VALUE statsrb_write(VALUE self, VALUE logfile, VALUE mode) {
173
183
  }
174
184
 
175
185
  /**
176
- * A method to split unique namespaces from internal memory and write them to individual files.
177
- */
186
+ * Locates data from a specified file and loads into @data.
187
+ * @param filepath [String]
188
+ * @param namespace [String]
189
+ * @param limit [Number]
190
+ * @param start_time [Number]
191
+ * @param end_time [Number]
192
+ * @return [Statsrb] A reference to the object.
193
+ */
178
194
  static VALUE statsrb_split_write(VALUE self, VALUE logdir, VALUE mode) {
179
195
  VALUE statsrb_data = rb_iv_get(self, "@data");
180
196
  int len = RARRAY_LEN(statsrb_data);
@@ -248,8 +264,9 @@ static VALUE statsrb_parse_qs(char *qs) {
248
264
  }
249
265
 
250
266
  /**
251
- * A method that is compatible with the rack api.
252
- */
267
+ * Returns a rack-compatible response.
268
+ * @param env [Hash]
269
+ */
253
270
  static VALUE statsrb_rack_call(VALUE self, VALUE env) {
254
271
  VALUE response = rb_ary_new();
255
272
  VALUE headers = rb_hash_new();
@@ -410,6 +427,31 @@ static VALUE statsrb_rack_call(VALUE self, VALUE env) {
410
427
  return response;
411
428
  }
412
429
 
430
+ /**
431
+ * Pushes a stat onto the statsrb object.
432
+ * @param timestamp [Number]
433
+ * @param namespace [String]
434
+ * @param value [Number]
435
+ * @return [Statsrb] A reference to the object.
436
+ */
437
+ static VALUE statsrb_push(VALUE self, VALUE timestamp, VALUE namespace, VALUE value) {
438
+ VALUE statsrb_data = rb_iv_get(self, "@data");
439
+ VALUE statsrb_event = rb_hash_new();
440
+
441
+ // @data hash key symbols.
442
+ VALUE statsrb_key_ts = rb_iv_get(self, "@key_ts");
443
+ VALUE statsrb_key_ns = rb_iv_get(self, "@key_ns");
444
+ VALUE statsrb_key_v = rb_iv_get(self, "@key_v");
445
+
446
+ rb_hash_aset(statsrb_event, statsrb_key_ts, timestamp);
447
+ rb_hash_aset(statsrb_event, statsrb_key_ns, namespace);
448
+ rb_hash_aset(statsrb_event, statsrb_key_v, value);
449
+
450
+ rb_ary_push(statsrb_data, statsrb_event);
451
+
452
+ return self;
453
+ }
454
+
413
455
  /**
414
456
  * Class constructor, sets up an instance variable.
415
457
  */
@@ -434,6 +476,7 @@ static VALUE statsrb_constructor(VALUE self) {
434
476
  * Init the Statsrb class.
435
477
  */
436
478
  void Init_statsrb(void) {
479
+ // @author Kevin Hankens
437
480
  VALUE klass = rb_define_class("Statsrb", rb_cObject);
438
481
 
439
482
  // Instance methods and properties.
@@ -442,9 +485,13 @@ void Init_statsrb(void) {
442
485
  rb_define_method(klass, "sort", statsrb_sort, 0);
443
486
  rb_define_method(klass, "write", statsrb_write, 2);
444
487
  rb_define_method(klass, "split_write", statsrb_split_write, 2);
488
+ rb_define_method(klass, "push", statsrb_push, 3);
445
489
  rb_define_method(klass, "call", statsrb_rack_call, 1);
446
490
  // Define :attr_accessor (read/write instance var)
447
491
  // Note that this must correspond with a call to rb_iv_self() and it's string name must be @data.
492
+ // An array of hashes keyed with :ts(timestamp), :ns(namespace) and :v(value)
493
+ // e.g. [!{:ts => Time.now.to_i, :ns => "test", :v => 33}]
448
494
  rb_define_attr(klass, "data", 1, 1);
495
+ // The file directory to write when splitting namespaces. @see #split_write
449
496
  rb_define_attr(klass, "split_file_dir", 1, 1);
450
497
  }
data/lib/statsrb.rb CHANGED
@@ -2,36 +2,4 @@ require 'statsrb/statsrb'
2
2
 
3
3
  # @author Kevin Hankens
4
4
  class Statsrb
5
- # [!{:ts => Time.now.to_i, :ns => "test", :v => 33}]
6
- attr_accessor :data
7
-
8
- # Writes the @data in memory to a specified file.
9
- # @param filepath [String]
10
- # @param filemode [String]
11
- # @return Statsrb
12
- def write filepath, filemode
13
- end
14
-
15
- # Splits namespaces in @data in memory to a separate files.
16
- # @param filepath [String]
17
- # @param filemode [String]
18
- # @return Statsrb
19
- def split_write filepath, filemode
20
- end
21
-
22
- # Locates data from a specified file and loads into @data.
23
- # @param filepath [String]
24
- # @param namespace [String]
25
- # @param limit [Number]
26
- # @param start_time [Number]
27
- # @param end_time [Number]
28
- # @return Statsrb
29
- def query filepath, namespace, limit, start_time, end_time
30
- end
31
-
32
- # Returns a rack-compatable response.
33
- # @param env [Hash]
34
- def sort env
35
- end
36
-
37
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: