static void acc_mean_emit(void* pvstate, char* value_field_name, char* acc_name, lrec_t* poutrec) { acc_mean_state_t* pstate = pvstate; double quot = pstate->sum / pstate->count; char* key = mlr_paste_3_strings(value_field_name, "_", acc_name); char* val = mlr_alloc_string_from_double(quot, MLR_GLOBALS.ofmt); lrec_put(poutrec, key, val, LREC_FREE_ENTRY_KEY|LREC_FREE_ENTRY_VALUE); }
// ---------------------------------------------------------------- static char * test_paste() { mu_assert("error: paste 2", streq(mlr_paste_2_strings("ab", "cd"), "abcd")); mu_assert("error: paste 3", streq(mlr_paste_3_strings("ab", "cd", "ef"), "abcdef")); mu_assert("error: paste 4", streq(mlr_paste_4_strings("ab", "cd", "ef", "gh"), "abcdefgh")); mu_assert("error: paste 5", streq(mlr_paste_5_strings("ab", "cd", "ef", "gh", "ij"), "abcdefghij")); return 0; }
static void acc_percentile_emit(void* pvstate, char* value_field_name, char* acc_name, lrec_t* poutrec) { acc_percentile_state_t* pstate = pvstate; char* key = mlr_paste_3_strings(value_field_name, "_", acc_name); double p; (void)sscanf(acc_name, "p%lf", &p); // Assuming this was range-checked earlier on to be in [0,100]. double v = percentile_keeper_emit(pstate->ppercentile_keeper, p); char* s = mlr_alloc_string_from_double(v, MLR_GLOBALS.ofmt); lrec_put(poutrec, key, s, LREC_FREE_ENTRY_KEY|LREC_FREE_ENTRY_VALUE); }
static void acc_max_emit(void* pvstate, char* value_field_name, char* acc_name, lrec_t* poutrec) { acc_max_state_t* pstate = pvstate; char* key = mlr_paste_3_strings(value_field_name, "_", acc_name); if (pstate->have_max) { char* val = mlr_alloc_string_from_double(pstate->max, MLR_GLOBALS.ofmt); lrec_put(poutrec, key, val, LREC_FREE_ENTRY_KEY|LREC_FREE_ENTRY_VALUE); } else { lrec_put(poutrec, key, "", LREC_FREE_ENTRY_KEY); } }
static void acc_mode_emit(void* pvstate, char* value_field_name, char* acc_name, lrec_t* poutrec) { acc_mode_state_t* pstate = pvstate; int max_count = 0; char* max_key = ""; for (lhmsie_t* pe = pstate->pcounts_for_value->phead; pe != NULL; pe = pe->pnext) { int count = pe->value; if (count > max_count) { max_key = pe->key; max_count = count; } } char* key = mlr_paste_3_strings(value_field_name, "_", acc_name); lrec_put(poutrec, key, max_key, LREC_FREE_ENTRY_KEY); }
stats1_acc_t* stats1_max_alloc(char* value_field_name, char* stats1_acc_name, int allow_int_float) { stats1_acc_t* pstats1_acc = mlr_malloc_or_die(sizeof(stats1_acc_t)); stats1_max_state_t* pstate = mlr_malloc_or_die(sizeof(stats1_max_state_t)); pstate->max = mv_from_null(); pstate->output_field_name = mlr_paste_3_strings(value_field_name, "_", stats1_acc_name); pstats1_acc->pvstate = (void*)pstate; pstats1_acc->pdingest_func = NULL; pstats1_acc->pningest_func = stats1_max_ningest; pstats1_acc->psingest_func = NULL; pstats1_acc->pemit_func = stats1_max_emit; pstats1_acc->pfree_func = stats1_max_free; return pstats1_acc; }
stats1_acc_t* stats1_mode_alloc(char* value_field_name, char* stats1_acc_name, int allow_int_float) { stats1_acc_t* pstats1_acc = mlr_malloc_or_die(sizeof(stats1_acc_t)); stats1_mode_state_t* pstate = mlr_malloc_or_die(sizeof(stats1_mode_state_t)); pstate->pcounts_for_value = lhmsi_alloc(); pstate->output_field_name = mlr_paste_3_strings(value_field_name, "_", stats1_acc_name); pstats1_acc->pvstate = (void*)pstate; pstats1_acc->pdingest_func = NULL; pstats1_acc->pningest_func = NULL; pstats1_acc->psingest_func = stats1_mode_singest; pstats1_acc->pemit_func = stats1_mode_emit; pstats1_acc->pfree_func = stats1_mode_free; return pstats1_acc; }
// xxx recast all of these in terms of providable outputs static void acc_stddev_var_meaneb_emit(void* pvstate, char* value_field_name, char* acc_name, lrec_t* poutrec) { acc_stddev_var_meaneb_state_t* pstate = pvstate; char* key = mlr_paste_3_strings(value_field_name, "_", acc_name); if (pstate->count < 2LL) { lrec_put(poutrec, key, "", LREC_FREE_ENTRY_KEY); } else { double output = mlr_get_var(pstate->count, pstate->sumx, pstate->sumx2); if (pstate->do_which == DO_STDDEV) output = sqrt(output); else if (pstate->do_which == DO_MEANEB) output = sqrt(output / pstate->count); char* val = mlr_alloc_string_from_double(output, MLR_GLOBALS.ofmt); lrec_put(poutrec, key, val, LREC_FREE_ENTRY_KEY|LREC_FREE_ENTRY_VALUE); } }
stats1_acc_t* stats1_sum_alloc(char* value_field_name, char* stats1_acc_name, int allow_int_float) { stats1_acc_t* pstats1_acc = mlr_malloc_or_die(sizeof(stats1_acc_t)); stats1_sum_state_t* pstate = mlr_malloc_or_die(sizeof(stats1_sum_state_t)); pstate->allow_int_float = allow_int_float; pstate->sum = pstate->allow_int_float ? mv_from_int(0LL) : mv_from_float(0.0); pstate->output_field_name = mlr_paste_3_strings(value_field_name, "_", stats1_acc_name); pstats1_acc->pvstate = (void*)pstate; pstats1_acc->pdingest_func = NULL; pstats1_acc->pningest_func = stats1_sum_ningest; pstats1_acc->psingest_func = NULL; pstats1_acc->pemit_func = stats1_sum_emit; pstats1_acc->pfree_func = stats1_sum_free; return pstats1_acc; }
static void stats1_percentile_emit(void* pvstate, char* value_field_name, char* stats1_acc_name, int copy_data, lrec_t* poutrec) { stats1_percentile_state_t* pstate = pvstate; double p; (void)sscanf(stats1_acc_name, "p%lf", &p); // Assuming this was range-checked earlier on to be in [0,100]. mv_t v = percentile_keeper_emit(pstate->ppercentile_keeper, p); char* s = mv_alloc_format_val(&v); // For this type, one accumulator tracks many stats1_names, but a single value_field_name. char* output_field_name = lhmss_get(pstate->poutput_field_names, stats1_acc_name); if (output_field_name == NULL) { output_field_name = mlr_paste_3_strings(value_field_name, "_", stats1_acc_name); lhmss_put(pstate->poutput_field_names, mlr_strdup_or_die(stats1_acc_name), output_field_name, FREE_ENTRY_KEY|FREE_ENTRY_VALUE); } lrec_put(poutrec, mlr_strdup_or_die(output_field_name), s, FREE_ENTRY_KEY|FREE_ENTRY_VALUE); }
stats1_acc_t* stats1_kurtosis_alloc(char* value_field_name, char* stats1_acc_name, int allow_int_float) { stats1_acc_t* pstats1_acc = mlr_malloc_or_die(sizeof(stats1_acc_t)); stats1_kurtosis_state_t* pstate = mlr_malloc_or_die(sizeof(stats1_kurtosis_state_t)); pstate->count = 0LL; pstate->sumx = 0.0; pstate->sumx2 = 0.0; pstate->sumx3 = 0.0; pstate->output_field_name = mlr_paste_3_strings(value_field_name, "_", stats1_acc_name); pstats1_acc->pvstate = (void*)pstate; pstats1_acc->pdingest_func = stats1_kurtosis_dingest; pstats1_acc->pningest_func = NULL; pstats1_acc->psingest_func = NULL; pstats1_acc->pemit_func = stats1_kurtosis_emit; pstats1_acc->pfree_func = stats1_kurtosis_free; return pstats1_acc; }
stats1_acc_t* stats1_stddev_var_meaneb_alloc(char* value_field_name, char* stats1_acc_name, int do_which) { stats1_acc_t* pstats1_acc = mlr_malloc_or_die(sizeof(stats1_acc_t)); stats1_stddev_var_meaneb_state_t* pstate = mlr_malloc_or_die(sizeof(stats1_stddev_var_meaneb_state_t)); pstate->count = 0LL; pstate->sumx = 0.0; pstate->sumx2 = 0.0; pstate->do_which = do_which; pstate->output_field_name = mlr_paste_3_strings(value_field_name, "_", stats1_acc_name); pstats1_acc->pvstate = (void*)pstate; pstats1_acc->pdingest_func = stats1_stddev_var_meaneb_dingest; pstats1_acc->pningest_func = NULL; pstats1_acc->psingest_func = NULL; pstats1_acc->pemit_func = stats1_stddev_var_meaneb_emit; pstats1_acc->pfree_func = stats1_stddev_var_meaneb_free; return pstats1_acc; }
static void acc_count_emit(void* pvstate, char* value_field_name, char* acc_name, lrec_t* poutrec) { acc_count_state_t* pstate = pvstate; char* key = mlr_paste_3_strings(value_field_name, "_", acc_name); char* val = mlr_alloc_string_from_ull(pstate->count); lrec_put(poutrec, key, val, LREC_FREE_ENTRY_KEY|LREC_FREE_ENTRY_VALUE); }