diff --git a/src/gmp.c b/src/gmp.c index 161850bb8..68902bb48 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -10313,6 +10313,167 @@ buffer_aggregate_subgroup_value (gchar *key, return FALSE; } +/** + * @brief Buffer XML for an aggregate. + * + * @param[in] xml Buffer into which to buffer aggregate. + * @param[in] type The aggregated type. + * @param[in] group_column Column the data are grouped by. + * @param[in] group_column_type Type of the group_column. + * @param[in] subgroup_column Column the data are further grouped by. + * @param[in] subgroup_column_type + * @param[in] data_columns Columns statistics are calculated for. + * @param[in] data_column_types Types of the data_columns. + * @param[in] text_columns Columns used for labels. + * @param[in] text_column_types Types of the text_columns. + */ +static void +buffer_aggregate_column_info (GString *xml, const gchar *type, + const char *group_column, const char *group_column_type, + const char *subgroup_column, + const char *subgroup_column_type, + GArray *data_columns, GArray *data_column_types, + GArray *text_columns, GArray *text_column_types) +{ + int index; + + g_string_append (xml, ""); + + if (group_column) + g_string_append_printf (xml, + "" + "value" + "value" + "%s" + "%s" + "%s" + "", + type, + group_column, + group_column_type); + + if (subgroup_column) + g_string_append_printf (xml, + "" + "subgroup_value" + "value" + "%s" + "%s" + "%s" + "", + type, + subgroup_column, + subgroup_column_type); + + g_string_append_printf (xml, + "" + "count" + "count" + "%s" + "" + "integer" + "", + type); + + g_string_append_printf (xml, + "" + "c_count" + "c_count" + "%s" + "" + "integer" + "", + type); + + for (index = 0; index < data_columns->len; index++) + { + gchar *column_name, *column_type; + column_name = g_array_index (data_columns, gchar*, index); + column_type = g_array_index (data_column_types, gchar*, index); + g_string_append_printf (xml, + "" + "%s_min" + "min" + "%s" + "%s" + "%s" + "", + column_name, + type, + column_name, + column_type); + g_string_append_printf (xml, + "" + "%s_max" + "max" + "%s" + "%s" + "%s" + "", + column_name, + type, + column_name, + column_type); + g_string_append_printf (xml, + "" + "%s_mean" + "mean" + "%s" + "%s" + "%s" + "", + column_name, + type, + column_name, + column_type); + g_string_append_printf (xml, + "" + "%s_sum" + "sum" + "%s" + "%s" + "%s" + "", + column_name, + type, + column_name, + column_type); + g_string_append_printf (xml, + "" + "%s_c_sum" + "c_sum" + "%s" + "%s" + "%s" + "", + column_name, + type, + column_name, + column_type); + } + + for (index = 0; index < text_columns->len; index++) + { + gchar *column_name, *column_type; + column_name = g_array_index (text_columns, gchar*, index); + column_type = g_array_index (text_column_types, gchar*, index); + g_string_append_printf (xml, + "" + "%s" + "text" + "%s" + "%s" + "%s" + "", + column_name, + type, + column_name, + column_type); + } + + g_string_append (xml, ""); +} + /** * @brief Buffer XML for an aggregate. * @@ -10763,141 +10924,11 @@ buffer_aggregate_xml (GString *xml, iterator_t* aggregate, const gchar* type, ""); } - g_string_append (xml, ""); - - if (group_column) - g_string_append_printf (xml, - "" - "value" - "value" - "%s" - "%s" - "%s" - "", - type, - group_column, - group_column_type); - - if (subgroup_column) - g_string_append_printf (xml, - "" - "subgroup_value" - "value" - "%s" - "%s" - "%s" - "", - type, - subgroup_column, - subgroup_column_type); - - g_string_append_printf (xml, - "" - "count" - "count" - "%s" - "" - "integer" - "", - type); - - g_string_append_printf (xml, - "" - "c_count" - "c_count" - "%s" - "" - "integer" - "", - type); - - for (index = 0; index < data_columns->len; index++) - { - gchar *column_name, *column_type; - column_name = g_array_index (data_columns, gchar*, index); - column_type = g_array_index (data_column_types, gchar*, index); - g_string_append_printf (xml, - "" - "%s_min" - "min" - "%s" - "%s" - "%s" - "", - column_name, - type, - column_name, - column_type); - g_string_append_printf (xml, - "" - "%s_max" - "max" - "%s" - "%s" - "%s" - "", - column_name, - type, - column_name, - column_type); - g_string_append_printf (xml, - "" - "%s_mean" - "mean" - "%s" - "%s" - "%s" - "", - column_name, - type, - column_name, - column_type); - g_string_append_printf (xml, - "" - "%s_sum" - "sum" - "%s" - "%s" - "%s" - "", - column_name, - type, - column_name, - column_type); - g_string_append_printf (xml, - "" - "%s_c_sum" - "c_sum" - "%s" - "%s" - "%s" - "", - column_name, - type, - column_name, - column_type); - } - - for (index = 0; index < text_columns->len; index++) - { - gchar *column_name, *column_type; - column_name = g_array_index (text_columns, gchar*, index); - column_type = g_array_index (text_column_types, gchar*, index); - g_string_append_printf (xml, - "" - "%s" - "text" - "%s" - "%s" - "%s" - "", - column_name, - type, - column_name, - column_type); - } - - g_string_append (xml, ""); + buffer_aggregate_column_info (xml, type, + group_column, group_column_type, + subgroup_column, subgroup_column_type, + data_columns, data_column_types, + text_columns, text_column_types); g_string_append (xml, "");