visualize_helper 0.0.10.25 → 0.0.10.26
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 +4 -4
- data/ext/visualize_helper/visualize_helper.c +97 -23
- data/lib/visualize_helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 903c04a29bd20e7c659c5a397b62d211b5e4ae3f
|
4
|
+
data.tar.gz: b7619b2bc026d47d6064e1a7661f299b6f5db5a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca2f511e73820ff749c7d63cea0a2b7bb8e6bbc170cf39a1ebb1a63144243d7c2c5f89bdb7e10b52471c51874ac80a827d6b680644f8f4282abdfa99a68078b5
|
7
|
+
data.tar.gz: d921e8513e7d0f8704e13dbd10bd888aa387c4ae7b47f511e309a010caa8f277127719504f869eb64fbfb148ae2d82fe57f0bd45ea504a85c7e79a9984f339e0
|
@@ -6,51 +6,125 @@ static VALUE hello_world()
|
|
6
6
|
return rb_str_new_cstr("hello world");
|
7
7
|
}
|
8
8
|
|
9
|
+
// Find the index of the target value inside array
|
10
|
+
int findIndex(VALUE intervals, size_t size, int target)
|
11
|
+
{
|
12
|
+
int i=0;
|
13
|
+
while((i<size) && (FIX2INT(rb_ary_entry(intervals,i)) != target)) i++;
|
14
|
+
|
15
|
+
return (i<size) ? (i) : (-1);
|
16
|
+
}
|
9
17
|
|
10
18
|
|
11
|
-
|
19
|
+
// Function callback to iterate in hash
|
20
|
+
// Params:
|
21
|
+
// days: hash key (VALUE)
|
22
|
+
// traj: hash value (VALUE)
|
23
|
+
// array: [min (int) ,max (int) ,period (Qnil/int), intervals (C array), intervals_size(int), aggr (VALUE)]
|
24
|
+
static int encontra_min_max_period(VALUE days, VALUE traj, VALUE array){
|
12
25
|
|
13
|
-
|
14
|
-
|
26
|
+
// Convert every variable need to C value
|
27
|
+
VALUE intervals = rb_ary_entry(array,3);
|
28
|
+
VALUE aggr = rb_ary_entry(array,4);
|
29
|
+
int intervals_size = RARRAY_LEN(array);
|
30
|
+
int aggr_size = RARRAY_LEN(aggr);
|
31
|
+
VALUE first_interval = rb_ary_entry(intervals,0);
|
32
|
+
VALUE last_interval = rb_ary_entry(intervals,intervals_size - 1);
|
33
|
+
int first_interval_c = FIX2INT(first_interval);
|
34
|
+
int last_interval_c = FIX2INT(last_interval);
|
35
|
+
int days_c = atoi(StringValuePtr(days));
|
36
|
+
int min_c = FIX2INT(rb_ary_entry(array,0));
|
37
|
+
int max_c = FIX2INT(rb_ary_entry(array,1));
|
38
|
+
int period;
|
39
|
+
|
40
|
+
if (days_c < first_interval_c) {
|
41
|
+
if (min_c > days_c) {
|
42
|
+
min_c = days_c;
|
43
|
+
//rb_ary_store(array,0,days);
|
44
|
+
}
|
45
|
+
period = 0;
|
46
|
+
//rb_ary_store(array,2,INT2FIX(0));
|
47
|
+
}else if (days_c == 0) {
|
48
|
+
period = findIndex(intervals,intervals_size,0)+1;
|
49
|
+
//rb_ary_store(array,2,INT2FIX(index+1));
|
50
|
+
|
51
|
+
}else if (days_c > last_interval_c ) {
|
52
|
+
if (max_c < days_c) {
|
53
|
+
max_c = days_c;
|
54
|
+
//rb_ary_store(array,1,days);
|
55
|
+
}
|
56
|
+
//rb_ary_store(array,2,INT2FIX(aggr_size -1));
|
57
|
+
period = aggr_size -1;
|
58
|
+
}else {
|
59
|
+
for ( int index = 0 ; index < intervals_size ; index++){
|
60
|
+
if( index < (intervals_size - 1) ){
|
61
|
+
int intervals_index_plus_1 = FIX2INT(rb_ary_entry(intervals,index+1));
|
62
|
+
if ( intervals_index_plus_1 <= 0 ){
|
63
|
+
if (( days_c >= rb_ary_entry(intervals,index)) && (days_c < intervals_index_plus_1)) {
|
64
|
+
period = index +1;
|
65
|
+
//rb_ary_store(array,2,INT2FIX(i+1));
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
}else if ( (days_c > rb_ary_entry(intervals,index) ) && (days_c <= intervals_index_plus_1) ) {
|
69
|
+
period = index + 2;
|
70
|
+
//rb_ary_store(array,2,INT2FIX(i+2));
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
rb_ary_push(rb_ary_entry(aggr,period),rb_ary_entry(traj,0));
|
15
77
|
|
16
78
|
return ST_CONTINUE;
|
17
79
|
}
|
18
80
|
|
19
|
-
//
|
20
|
-
|
81
|
+
// Function to find min, max and the period of the HashMapValue of trajectories in Visualize app
|
82
|
+
// Return: [ min, max, period]
|
83
|
+
static VALUE min_max_period(VALUE self, VALUE min, VALUE max, VALUE hash, VALUE intervals, VALUE aggr)
|
21
84
|
{
|
85
|
+
int period = Qnil;
|
22
86
|
|
23
|
-
|
24
|
-
int max_c = FIX2INT(max);
|
25
|
-
int period = Qnil;
|
87
|
+
// Create Ruby array that will be the result
|
26
88
|
VALUE array = rb_ary_new();
|
27
89
|
|
28
|
-
|
90
|
+
// Push initial values of the result
|
91
|
+
rb_ary_push(array,min);
|
92
|
+
rb_ary_push(array,max);
|
93
|
+
rb_ary_push(array,period);
|
94
|
+
rb_ary_push(array,intervals);
|
95
|
+
rb_ary_push(array,aggr);
|
96
|
+
|
97
|
+
|
98
|
+
// iterate on hash calling "encontra_min_max_period" for each
|
99
|
+
rb_hash_foreach(hash,encontra_min_max_period,array);
|
29
100
|
|
30
|
-
//
|
31
|
-
|
32
|
-
|
33
|
-
//VALUE str1 = INT2FIX(min_c);
|
34
|
-
//VALUE str2 = INT2FIX(max_c);
|
35
|
-
//
|
36
|
-
//rb_ary_push(array,str1);
|
37
|
-
//rb_ary_push(array,str2);
|
101
|
+
// flatten on aggr
|
102
|
+
|
38
103
|
|
39
|
-
|
104
|
+
// Return results
|
105
|
+
return aggr;
|
40
106
|
}
|
41
107
|
|
108
|
+
|
109
|
+
|
110
|
+
static VALUE test(VALUE self, VALUE param){
|
111
|
+
|
112
|
+
int a = INT2FIX(param);
|
113
|
+
return FIX2INT(a);
|
114
|
+
}
|
115
|
+
|
42
116
|
// Main function called when the gem is loaded
|
43
117
|
void Init_visualize_helper(void) {
|
44
118
|
|
45
119
|
// Register the VisualizeHelper module
|
46
120
|
VALUE mVisualizeHelper = rb_define_module("VisualizeHelper");
|
47
121
|
|
48
|
-
// Register the
|
122
|
+
// Register the method Hello World without parameters
|
49
123
|
rb_define_singleton_method(mVisualizeHelper, "hello_world", hello_world, 0);
|
50
124
|
|
51
|
-
// Register the
|
52
|
-
rb_define_singleton_method(mVisualizeHelper, "
|
125
|
+
// Register the method min_max_period
|
126
|
+
rb_define_singleton_method(mVisualizeHelper, "min_max_period", min_max_period, 5);
|
53
127
|
|
54
|
-
// Register the
|
55
|
-
|
128
|
+
// Register the method for development testing
|
129
|
+
rb_define_singleton_method(mVisualizeHelper, "test", test, 1 );
|
56
130
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visualize_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.10.
|
4
|
+
version: 0.0.10.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphael Ottoni Santiago Machado de Faria
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|