visualize_helper 0.0.10.27 → 0.0.10.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/visualize_helper/visualize_helper.c +251 -11
- 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: b4100947c618bdc4518f2f89923495306bfbecfb
|
4
|
+
data.tar.gz: 04e6517f9f601470538a1f11fc706df5fa593752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a86285f6896472865180c8ce1e303eb2d4752698aad4a0e55744bd1ebcf5058409294c8852f576b82581903471dcbd8b74414a57cc44277951ac179c1831c9cc
|
7
|
+
data.tar.gz: 7d534c2c3bf23c1d72b329a39ec105124a02feb129dee77adee43969f2e73a9011c8df3266070d0fd0c5d87350ca9781e1d3f92858abe2e7588b7d0b024312c1
|
@@ -1,11 +1,105 @@
|
|
1
1
|
#include <ruby.h>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <string.h>
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <math.h>
|
2
6
|
|
3
|
-
|
4
|
-
|
7
|
+
|
8
|
+
int myCompare (const void * a, const void * b ) {
|
9
|
+
const char *pa = *(const char**)a;
|
10
|
+
const char *pb = *(const char**)b;
|
11
|
+
|
12
|
+
return strcmp(pa,pb);
|
13
|
+
}
|
14
|
+
|
15
|
+
// recive a sorted array of strings and return a sorted array with only the unique elements
|
16
|
+
static VALUE uniq(VALUE sorted_array){
|
17
|
+
|
18
|
+
//initialize return variable in ruby
|
19
|
+
VALUE uniq_array = rb_ary_new();
|
20
|
+
|
21
|
+
//initialize variables for compare
|
22
|
+
char* previous;
|
23
|
+
char* current;
|
24
|
+
|
25
|
+
for( int i = 0; i < RARRAY_LEN(sorted_array); i++){
|
26
|
+
VALUE current_temp = rb_ary_entry(sorted_array,i);
|
27
|
+
current = StringValuePtr(current_temp);
|
28
|
+
// initial case, when there is no previous
|
29
|
+
if ( i == 0 ){
|
30
|
+
VALUE previous_temp = rb_ary_entry(sorted_array,i);
|
31
|
+
previous = StringValuePtr(previous_temp);
|
32
|
+
rb_ary_push(uniq_array,rb_ary_entry(sorted_array,i));
|
33
|
+
} else {
|
34
|
+
if (strcmp(previous,current) != 0 ){
|
35
|
+
rb_ary_push(uniq_array,rb_ary_entry(sorted_array,i));
|
36
|
+
VALUE previous_temp = rb_ary_entry(sorted_array,i);
|
37
|
+
previous = StringValuePtr(previous_temp);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
return uniq_array;
|
43
|
+
}
|
44
|
+
|
45
|
+
//static VALUE join(VALUE self, VALUE strings){
|
46
|
+
static VALUE join(VALUE strings){
|
47
|
+
|
48
|
+
// initial variables
|
49
|
+
char* joined;
|
50
|
+
int strings_size = RARRAY_LEN(strings);
|
51
|
+
int string_size;
|
52
|
+
VALUE string_temp;
|
53
|
+
VALUE result;
|
54
|
+
|
55
|
+
string_temp = rb_ary_entry(strings,0);
|
56
|
+
string_size = strlen(StringValuePtr(string_temp));
|
57
|
+
joined = (char*) malloc(strings_size + 1);
|
58
|
+
sprintf(joined,"%s", StringValuePtr(string_temp));
|
59
|
+
|
60
|
+
for (int i = 1 ; i < strings_size; i++) {
|
61
|
+
|
62
|
+
string_temp = rb_ary_entry(strings,i);
|
63
|
+
string_size = strlen(StringValuePtr(string_temp));
|
64
|
+
|
65
|
+
joined = (char*) realloc(joined, string_size + strlen(joined) + 1);
|
66
|
+
sprintf(joined,"%s,%s", joined, StringValuePtr(string_temp));
|
67
|
+
|
68
|
+
}
|
69
|
+
result = rb_str_new2(joined);
|
70
|
+
free(joined);
|
71
|
+
return result;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
// Receive an array of unsorted strings with repeated strings and return a single a sorted array with unique elementes or with all
|
77
|
+
// strings = array of strings
|
78
|
+
// unique = 0 or 1 if want to call unique or not
|
79
|
+
static VALUE sort_uniq(VALUE self, VALUE strings, int unique)
|
5
80
|
{
|
6
|
-
|
81
|
+
int strings_size = RARRAY_LEN(strings);
|
82
|
+
const char *input[strings_size];
|
83
|
+
|
84
|
+
for (int i = 0; i< strings_size; i++){
|
85
|
+
VALUE string = rb_ary_entry(strings,i);
|
86
|
+
input[i] = StringValuePtr(string);
|
87
|
+
}
|
88
|
+
|
89
|
+
int stringLen = sizeof(input) / sizeof(char *);
|
90
|
+
qsort(input, stringLen, sizeof(char *), myCompare);
|
91
|
+
|
92
|
+
|
93
|
+
// Transform the result input into a ruby array
|
94
|
+
VALUE resultado = rb_ary_new();
|
95
|
+
for (int i=0; i<stringLen; ++i) {
|
96
|
+
rb_ary_push(resultado,rb_str_new2(input[i]));
|
97
|
+
}
|
98
|
+
|
99
|
+
return (unique == 0 ) ? resultado : uniq(resultado);
|
7
100
|
}
|
8
101
|
|
102
|
+
|
9
103
|
// Find the index of the target value inside array
|
10
104
|
int findIndex(VALUE intervals, size_t size, int target)
|
11
105
|
{
|
@@ -108,25 +202,171 @@ static VALUE min_max_period(VALUE self, VALUE min, VALUE max, VALUE hash, VALUE
|
|
108
202
|
}
|
109
203
|
|
110
204
|
|
205
|
+
//function to remove element from a array of strings
|
206
|
+
static VALUE remove_entry_from_array (VALUE strings, char* element){
|
207
|
+
|
208
|
+
//initial variables
|
209
|
+
VALUE result = rb_ary_new();
|
210
|
+
char* current_value;
|
211
|
+
VALUE current_value_temp;
|
212
|
+
|
213
|
+
for(int i = 0; i < RARRAY_LEN(strings); i++){
|
214
|
+
current_value_temp = rb_ary_entry(strings,i);
|
215
|
+
current_value = StringValuePtr(current_value_temp);
|
216
|
+
if (strcmp(current_value, element) != 0) {
|
217
|
+
rb_ary_push(result,rb_ary_entry(strings,i));
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
return result;
|
222
|
+
}
|
223
|
+
|
224
|
+
// Function to generate the boxes and links of each trajectory
|
225
|
+
static VALUE generate_boxes_and_links(VALUE self, VALUE min, VALUE max, VALUE aggr, VALUE boxes, VALUE links, VALUE dict, VALUE type_agroupment, VALUE value)
|
226
|
+
{
|
227
|
+
|
228
|
+
VALUE seq_key_result;
|
229
|
+
VALUE prox_key_result;
|
230
|
+
// Initial Variables
|
231
|
+
int length_seq_sorted;
|
232
|
+
int length_prox_sorted;
|
233
|
+
VALUE result_final;
|
234
|
+
VALUE boxes_period_value;
|
235
|
+
VALUE links_period_value;
|
236
|
+
VALUE seq_key;
|
237
|
+
VALUE prox_key;
|
238
|
+
VALUE seq;
|
239
|
+
VALUE aggr_prox;
|
240
|
+
int seq_size;
|
241
|
+
int aggr_prox_size;
|
242
|
+
int prox;
|
243
|
+
int aggr_size = RARRAY_LEN(aggr);
|
244
|
+
char* link_key;
|
245
|
+
char* period_s;
|
246
|
+
char* prox_s;
|
247
|
+
|
248
|
+
for(int period = 0; period < aggr_size; period++ ){
|
249
|
+
seq_key = rb_ary_new();
|
250
|
+
|
251
|
+
if (period < aggr_size - 1) {
|
252
|
+
prox_key = rb_ary_new();
|
253
|
+
}
|
254
|
+
seq = rb_ary_entry(aggr,period);
|
255
|
+
seq_size = (int) RARRAY_LEN(seq);
|
256
|
+
|
257
|
+
// Translate sequences with dict
|
258
|
+
if (seq_size == 0) {
|
259
|
+
rb_ary_push(seq_key,rb_hash_aref(dict, rb_str_new2("M-2")));
|
260
|
+
}else{
|
261
|
+
|
262
|
+
for(int i = 0; i < seq_size; i++ ) {
|
263
|
+
rb_ary_push(seq_key,rb_hash_aref(dict,rb_ary_entry(seq,i)));
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
// agroup by unique or not
|
268
|
+
if ( strcmp(StringValuePtr(type_agroupment),"s") == 0 ) {
|
269
|
+
//sort with uniq
|
270
|
+
seq_key = sort_uniq(self,seq_key,1);
|
271
|
+
}else{
|
272
|
+
//sort without uniq
|
273
|
+
seq_key = sort_uniq(self,seq_key,0);
|
274
|
+
}
|
275
|
+
|
276
|
+
// if there is "no-event" and other one selected, remove the "no-event"
|
277
|
+
length_seq_sorted = (strcmp(StringValuePtr(type_agroupment),"s") == 0 ) ? RARRAY_LEN(seq_key) : RARRAY_LEN(uniq(seq_key)) ;
|
278
|
+
if (length_seq_sorted != 1) {
|
279
|
+
seq_key = remove_entry_from_array(seq_key,"M-3");
|
280
|
+
}
|
281
|
+
|
282
|
+
// Generate the key
|
283
|
+
seq_key_result = join(seq_key);
|
284
|
+
|
285
|
+
//
|
286
|
+
boxes_period_value = rb_hash_aref(rb_ary_entry(boxes,period),seq_key_result);
|
287
|
+
if (boxes_period_value == Qnil) {
|
288
|
+
rb_hash_aset(rb_ary_entry(boxes,period),seq_key_result, value);
|
289
|
+
}else {
|
290
|
+
rb_hash_aset(rb_ary_entry(boxes,period),seq_key_result,INT2FIX(FIX2INT(boxes_period_value) + FIX2INT(value)));
|
291
|
+
}
|
292
|
+
|
293
|
+
prox = period +1;
|
294
|
+
|
295
|
+
if (prox < aggr_size ) {
|
296
|
+
aggr_prox = rb_ary_entry(aggr,prox);
|
297
|
+
aggr_prox_size = (int) RARRAY_LEN(aggr_prox);
|
298
|
+
if ( aggr_prox_size == 0) {
|
299
|
+
rb_ary_push(prox_key,rb_hash_aref(dict, rb_str_new2("M-2")));
|
300
|
+
}else{
|
301
|
+
for(int i = 0; i < aggr_prox_size ; i++ ) {
|
302
|
+
rb_ary_push(prox_key,rb_hash_aref(dict,rb_ary_entry(aggr_prox,i)));
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
// agroup by unique or not
|
307
|
+
if ( strcmp(StringValuePtr(type_agroupment),"n") == 0 ) {
|
308
|
+
//sort with uniq
|
309
|
+
prox_key = sort_uniq(self,prox_key,1);
|
310
|
+
}else{
|
311
|
+
//sort without uniq
|
312
|
+
prox_key = prox_key;
|
313
|
+
}
|
314
|
+
|
315
|
+
//
|
316
|
+
// if there is "no-event" and other one selected, remove the "no-event"
|
317
|
+
length_prox_sorted = (strcmp(StringValuePtr(type_agroupment),"n") == 0 ) ? RARRAY_LEN(prox_key) : RARRAY_LEN(sort_uniq(self,prox_key,1)) ;
|
318
|
+
if (length_prox_sorted != 1) {
|
319
|
+
prox_key = remove_entry_from_array(prox_key,"M-3");
|
320
|
+
}
|
321
|
+
|
322
|
+
// Generate the key
|
323
|
+
prox_key_result = join(prox_key);
|
324
|
+
|
325
|
+
// generate a key link
|
326
|
+
period_s = ( period == 0 ) ? (char*) malloc(1) : (char*) malloc(floor(log10(abs(period))) + 1);
|
327
|
+
prox_s = ( prox == 0 ) ? (char*) malloc(1) : (char*) malloc(floor(log10(abs(prox))) + 1);
|
328
|
+
sprintf(period_s,"%d",period);
|
329
|
+
sprintf(prox_s,"%d",prox);
|
330
|
+
link_key = (char*) malloc( strlen(period_s) + strlen(StringValuePtr(seq_key_result)) + strlen(prox_s) + strlen(StringValuePtr(prox_key_result)) + 3);
|
331
|
+
sprintf(link_key,"%s_%s;%s_%s", period_s,StringValuePtr(seq_key_result),prox_s,StringValuePtr(prox_key_result));
|
332
|
+
|
333
|
+
links_period_value = rb_hash_aref(rb_ary_entry(links,period),rb_str_new2(link_key));
|
334
|
+
if (links_period_value == Qnil) {
|
335
|
+
rb_hash_aset(rb_ary_entry(links,period),rb_str_new2(link_key),value);
|
336
|
+
}else {
|
337
|
+
rb_hash_aset(rb_ary_entry(links,period),rb_str_new2(link_key), INT2FIX(FIX2INT(links_period_value) + FIX2INT(value)));
|
338
|
+
}
|
111
339
|
|
112
|
-
static VALUE test(VALUE self, VALUE param){
|
113
340
|
|
114
|
-
|
115
|
-
|
341
|
+
|
342
|
+
}//end prox < aggr_size
|
343
|
+
|
344
|
+
}// end for
|
345
|
+
|
346
|
+
VALUE ab = rb_ary_new();
|
347
|
+
rb_ary_push(ab,1);
|
348
|
+
rb_ary_push(ab,2);
|
349
|
+
//return result_final;
|
350
|
+
return Qnil;
|
116
351
|
}
|
117
352
|
|
353
|
+
|
354
|
+
|
118
355
|
// Main function called when the gem is loaded
|
119
356
|
void Init_visualize_helper(void) {
|
120
357
|
|
121
358
|
// Register the VisualizeHelper module
|
122
359
|
VALUE mVisualizeHelper = rb_define_module("VisualizeHelper");
|
123
360
|
|
124
|
-
// Register the method Hello World without parameters
|
125
|
-
rb_define_singleton_method(mVisualizeHelper, "hello_world", hello_world, 0);
|
126
|
-
|
127
361
|
// Register the method min_max_period
|
128
362
|
rb_define_singleton_method(mVisualizeHelper, "min_max_period", min_max_period, 5);
|
129
363
|
|
130
|
-
// Register the method
|
131
|
-
rb_define_singleton_method(mVisualizeHelper, "
|
364
|
+
// Register the method generate_boxes_and_links
|
365
|
+
rb_define_singleton_method(mVisualizeHelper, "generate_boxes_and_links", generate_boxes_and_links, 8);
|
366
|
+
|
367
|
+
// Register the method sort
|
368
|
+
rb_define_singleton_method(mVisualizeHelper, "sort_uniq", sort_uniq, 2 );
|
369
|
+
|
370
|
+
// Register the method sort
|
371
|
+
rb_define_singleton_method(mVisualizeHelper, "join", join, 1 );
|
132
372
|
}
|
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.28
|
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-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|