Module: VisualizeHelper
- Defined in:
- lib/visualize_helper/version.rb,
ext/visualize_helper/visualize_helper.c
Constant Summary collapse
- VERSION =
"0.0.10.35"
Class Method Summary collapse
-
.generate_boxes_and_links(aggr, boxes, links, dict, type_agroupment, value) ⇒ Object
Function to generate the boxes and links of each trajectory.
-
.iterate_over_trajectories(trajectories, min, max, hash, key_v, key_t, intervals, dict, agrupamento, boxes, links) ⇒ Object
Register the method that iterates for each trajectory.
-
.join_teste(strings) ⇒ Object
Register the method sort.
-
.min_max_period(min, max, hash, intervals, aggr) ⇒ Object
Return: [ min, max, period].
- .sort_uniq() ⇒ Object
Class Method Details
.generate_boxes_and_links(aggr, boxes, links, dict, type_agroupment, value) ⇒ Object
Function to generate the boxes and links of each trajectory
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'ext/visualize_helper/visualize_helper.c', line 241
static VALUE generate_boxes_and_links(VALUE self, VALUE aggr, VALUE boxes, VALUE links, VALUE dict, VALUE type_agroupment, VALUE value)
{
char* seq_key_result;
char* prox_key_result;
// Initial Variables
int length_seq_sorted;
int length_prox_sorted;
VALUE result_final;
VALUE boxes_period_value;
VALUE links_period_value;
VALUE seq_key;
VALUE prox_key;
VALUE seq;
VALUE aggr_prox;
int seq_size;
int aggr_prox_size;
int prox;
int aggr_size = RARRAY_LEN(aggr);
char* link_key = (char*) malloc(1000);
char* period_s;
char* prox_s;
int period,i;
//FILE *f = fopen("/tmp/file.txt", "a");
for(period = 0; period < aggr_size; period++ ){
seq_key = rb_ary_new();
if (period < aggr_size - 1) {
prox_key = rb_ary_new();
}
seq = rb_ary_entry(aggr,period);
seq_size = (int) RARRAY_LEN(seq);
// Translate sequences with dict
if (seq_size == 0) {
rb_ary_push(seq_key,rb_hash_aref(dict, rb_str_new2("M-2")));
}else{
for(i = 0; i < seq_size; i++ ) {
rb_ary_push(seq_key,rb_hash_aref(dict,rb_ary_entry(seq,i)));
}
}
// agroup by unique or not
if ( strcmp(StringValuePtr(type_agroupment),"n") == 0 ) {
//sort with uniq
seq_key = sort_uniq(seq_key,1);
}else{
//sort without uniq
seq_key = sort_uniq(seq_key,0);
}
// if there is "no-event" and other one selected, remove the "no-event"
length_seq_sorted = (strcmp(StringValuePtr(type_agroupment),"s") == 0 ) ? RARRAY_LEN(seq_key) : RARRAY_LEN(uniq(seq_key)) ;
if (length_seq_sorted != 1) {
seq_key = remove_entry_from_array(seq_key,"M-3");
}
// Generate the key
seq_key_result = join(seq_key);
//
boxes_period_value = rb_hash_aref(rb_ary_entry(boxes,period),rb_str_new2(seq_key_result));
if (boxes_period_value == Qnil) {
rb_hash_aset(rb_ary_entry(boxes,period),rb_str_new2(seq_key_result), value);
}else {
rb_hash_aset(rb_ary_entry(boxes,period),rb_str_new2(seq_key_result),INT2FIX(FIX2INT(boxes_period_value) + FIX2INT(value)));
}
prox = period +1;
if (prox < aggr_size ) {
aggr_prox = rb_ary_entry(aggr,prox);
aggr_prox_size = (int) RARRAY_LEN(aggr_prox);
if ( aggr_prox_size == 0) {
rb_ary_push(prox_key,rb_hash_aref(dict, rb_str_new2("M-2")));
}else{
for( i = 0; i < aggr_prox_size ; i++ ) {
rb_ary_push(prox_key,rb_hash_aref(dict,rb_ary_entry(aggr_prox,i)));
}
}
// agroup by unique or not
if ( strcmp(StringValuePtr(type_agroupment),"n") == 0 ) {
//sort with uniq
prox_key = sort_uniq(prox_key,1);
}
//else{
// //sort without uniq
// prox_key = prox_key;
//}
//
// if there is "no-event" and other one selected, remove the "no-event"
length_prox_sorted = (strcmp(StringValuePtr(type_agroupment),"n") == 0 ) ? RARRAY_LEN(prox_key) : RARRAY_LEN(sort_uniq(prox_key,1)) ;
if (length_prox_sorted != 1) {
prox_key = remove_entry_from_array(prox_key,"M-3");
}
// Generate the key
prox_key_result = join(prox_key);
// generate a key link
period_s = ( period == 0 ) ? (char*) malloc(1) : (char*) malloc(floor(log10(abs(period))) + 1);
prox_s = ( prox == 0 ) ? (char*) malloc(1) : (char*) malloc(floor(log10(abs(prox))) + 1);
sprintf(period_s,"%d",period);
sprintf(prox_s,"%d",prox);
//link_key = (char*) malloc( strlen(period_s) + strlen(seq_key_result) + strlen(prox_s) + strlen(prox_key_result) + 3);
sprintf(link_key,"%s_%s;%s_%s", period_s,seq_key_result,prox_s,prox_key_result);
RemoveSpaces(link_key);
//fprintf(f,"Composicao key:\n");
//fprintf(f,"period_s: %s\n",period_s);
//fprintf(f,"seq_key: %s\n",seq_key_result);
//fprintf(f,"prox_s : %s\n",prox_s);
//fprintf(f,"prox_key_result: %s\n",prox_key_result);
//fprintf(f,"chave final : %s\n",link_key);
links_period_value = rb_hash_aref(rb_ary_entry(links,period),rb_str_new2(link_key));
if (links_period_value == Qnil) {
rb_hash_aset(rb_ary_entry(links,period),rb_str_new2(link_key),value);
}else {
rb_hash_aset(rb_ary_entry(links,period),rb_str_new2(link_key), INT2FIX(FIX2INT(links_period_value) + FIX2INT(value)));
}
}//end prox < aggr_size
}// end for
free(period_s);
free(prox_s);
free(link_key);
//fclose(f);
//return result_final;
return Qnil;
}
|
.iterate_over_trajectories(trajectories, min, max, hash, key_v, key_t, intervals, dict, agrupamento, boxes, links) ⇒ Object
Register the method that iterates for each trajectory
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/visualize_helper/visualize_helper.c', line 388
static VALUE iterate_over_trajectories(VALUE self, VALUE trajectories, VALUE min, VALUE max, VALUE hash, VALUE key_v, VALUE key_t, VALUE intervals, VALUE dict, VALUE agrupamento, VALUE boxes, VALUE links) {
VALUE trajectory;
VALUE aggr;
VALUE value;
VALUE result;
VALUE min_max_aggr;
int i,j;
// iterate over each trajectory
for (i = 0; i < RARRAY_LEN(trajectories); i++ ){
trajectory = rb_ary_entry(trajectories,i);
aggr = rb_ary_new();
for (j = 0; j < RARRAY_LEN(intervals) + 2; j++){
rb_ary_push(aggr,rb_ary_new());
}
value = rb_hash_aref(hash,key_v);
VALUE temp = rb_hash_aref(hash,key_t);
min_max_aggr = min_max_period(self,min,max,rb_hash_aref(temp,trajectory),intervals,aggr);
aggr = rb_ary_entry(min_max_aggr,4);
min = rb_ary_entry(min_max_aggr,0);
max = rb_ary_entry(min_max_aggr,1);
generate_boxes_and_links(self,aggr,boxes,links,dict,agrupamento,value);
}
result = rb_ary_new();
rb_ary_push(result,boxes);
rb_ary_push(result,links);
return result;
}
|
.join_teste(strings) ⇒ Object
Register the method sort
382 383 384 385 |
# File 'ext/visualize_helper/visualize_helper.c', line 382
static VALUE join_teste(VALUE self, VALUE strings){
return rb_str_new2(join(strings));
}
|
.min_max_period(min, max, hash, intervals, aggr) ⇒ Object
Return: [ min, max, period]
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'ext/visualize_helper/visualize_helper.c', line 197
static VALUE min_max_period(VALUE self, VALUE min, VALUE max, VALUE hash, VALUE intervals, VALUE aggr)
{
int period = Qnil;
// Create Ruby array that will be the result
VALUE array = rb_ary_new();
// Push initial values of the result
rb_ary_push(array,min);
rb_ary_push(array,max);
rb_ary_push(array,period);
rb_ary_push(array,intervals);
rb_ary_push(array,aggr);
// iterate on hash calling "encontra_min_max_period" for each
rb_hash_foreach(hash,encontra_min_max_period,array);
// Return results
return array;
}
|
.sort_uniq() ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'ext/visualize_helper/visualize_helper.c', line 99
static VALUE sort_uniq(VALUE strings, int unique)
{
int strings_size = RARRAY_LEN(strings);
const char *input[strings_size];
for (int i = 0; i< strings_size; i++){
VALUE string = rb_ary_entry(strings,i);
input[i] = StringValuePtr(string);
}
int stringLen = sizeof(input) / sizeof(char *);
qsort(input, stringLen, sizeof(char *), myCompare);
// Transform the result input into a ruby array
VALUE resultado = rb_ary_new();
for (int i=0; i<stringLen; ++i) {
rb_ary_push(resultado,rb_str_new2(input[i]));
}
return (unique == 0 ) ? resultado : uniq(resultado);
}
|