# # # # query_fields_util.cfv # Utilities to create the query fields for profiles_cache and Reports Editor # # # # query_fields_util_get_table_field_type() # query_fields_util_get_table_bar_graph_single_hex_color() # # query_fields_util_create_query_fields() # # include "templates.util.colors"; include "templates.util.profile_validation"; include "templates.util.get_is_hierarchical_db_field"; # # # # query_fields_util_get_table_field_type() # # # subroutine(query_fields_util_get_table_field_type( string origin_type, bool use_custom_itemnum), ( string table_field_type; if (origin_type eq "int" or origin_type eq "unique") then ( table_field_type = "int"; ) else if (origin_type eq "float") then ( table_field_type = "float"; ) else ( # This is a string. Though we have to distinguish between database_itemnum & custom_itemnum. # custom_itemnum is used in all cases where no database field exists. if (!use_custom_itemnum) then ( table_field_type = "database_itemnum"; ) else ( table_field_type = "custom_itemnum"; ); ); table_field_type; )); # # # # query_fields_util_get_table_bar_graph_single_hex_color() # # # subroutine(query_fields_util_get_table_bar_graph_single_hex_color( node graph_colors), ( node rgb = graph_colors{"single"}{"table_bar_graph"}; string hex_color = rgb_to_hex_color(@rgb{"red"}, @rgb{"green"}, @rgb{"blue"}); hex_color; )); # # # # query_fields_get_is_date_time_in_epoc() # # # # # KHP 24/Oct/2011 - disabled because is_date_time_in_epoc # doesn't help really much since it is possible to define # a display_format_type which converts epoc to date_time, # which is the recommended method anyway. #* subroutine(query_fields_get_is_date_time_in_epoc( node db_fields, node db_field_item, string query_field_type, string category), ( # This returns is_date_time_in_epoc bool is_date_time_in_epoc = false; if (query_field_type eq "int") then ( if (category eq "date_time") then ( is_date_time_in_epoc = true; ) else if (db_field_item?{"source_database_field"} and db_field_item?{"aggregation_method"} and (@db_field_item{"aggregation_method"} eq "min" or @db_field_item{"aggregation_method"} eq "max")) then ( # Check if this is a session_begin or session_end database field # which is based on a date_time field. string source_db_field_name = @db_field_item{"source_database_field"}; if (db_fields?{source_db_field_name}) then ( node source_db_field = db_fields{source_db_field_name}; if (source_db_field?{"category"} and @source_db_field{"category"} eq "date_time") then ( is_date_time_in_epoc = true; ); ); ); ); # Return is_date_time_in_epoc; )); *# # # # # query_fields_util_create_query_fields() # # # subroutine(query_fields_util_create_query_fields( node profile), ( debug_message("\n#### query_fields_util_create_query_fields() \n"); # # # Creates/returns a query_fields node for further processing # # delete_node("v.temp_query_fields"); v.temp_query_fields = ""; node query_fields = "v.temp_query_fields"; node query_field_item; node report_fields_node = profile . ".statistics.report_fields"; # KHP 16/Aug/2010 - Get validated database fields node db_fields = get_validated_database_fields(profile); node log_fields = profile . (".log.fields"); node db_field_item; string db_field_name; string db_field_type; bool is_hierarchical_db_field; node db_field_numbers = new_node(); int db_field_count = 0; foreach db_field_item db_fields ( @db_field_numbers{node_name(db_field_item)} = db_field_count; db_field_count++; ); # KHP 15/Jan/2010 - log.field_options is no longer available # node log_field_options_node = if (?(profile . ".log.field_options")) then (profile . ".log.field_options") else (""); node report_field_item; string report_field_name; string report_field_label; string column_label; string column_info; string category; string display_format_type; string query_field_type; string sort_type; string table_field_type; int integer_bits; string aggregation_method; string average_denominator_field; string query_fields_path; # string derivation_method; KHP 25/Nov/2011 - disabled because derivation_method is ambiguous bool is_expression; bool is_average_denominator_field; bool is_aggregating_field; # bool is_date_time_in_epoc; node graph_colors = "graph_colors"; node numerical_colors = graph_colors{"numerical"}; node random_numerical_colors = graph_colors{"random_numerical"}; node rgb_color; int number_of_random_colors = num_subnodes(random_numerical_colors); int random_color_count; int red; int green; int blue; string hex_color; string table_bar_graph_single_hex_color = query_fields_util_get_table_bar_graph_single_hex_color(graph_colors); # node rgb_single_table_bar_graph = graph_colors{"single"}{"table_bar_graph"}; bool skip_escaping; int subitems_level; foreach report_field_item report_fields_node ( report_field_name = node_name(report_field_item); debug_message("#### report_field_name: " . report_field_name . "\n"); # Create the query_field_item node set_subnode_value(query_fields, report_field_name, ""); query_field_item = query_fields{report_field_name}; db_field_name = ""; # Must be set to "" because we use it for all fields, see "Add field_name" in bottom code! is_hierarchical_db_field = false; is_expression = if (report_field_item?{"database_field"} and (@report_field_item{"database_field"} ne "")) then (false) else (true); is_average_denominator_field = false; if (report_field_item?{"average_denominator_field"}) then ( average_denominator_field = @report_field_item{"average_denominator_field"}; debug_message("#### average_denominator_field: " . average_denominator_field . "\n"); # Make sure the average_denominator_field exists in report fields is_average_denominator_field = (report_fields_node?{average_denominator_field}); ); debug_message("#### is_average_denominator_field: " . is_average_denominator_field . "\n\n"); if (!is_expression) then ( db_field_name = @report_field_item{"database_field"}; db_field_item = db_fields{db_field_name}; is_hierarchical_db_field = get_is_hierarchical_db_field(db_field_item, log_fields); if (report_field_item?{"category"}) then ( # Get the category from the report field # Note, a given empty category="" in a report field overrides # any given database field category. # So the existence of a report field category (regardless if it has a value or not) # overrides any given database field category category = @report_field_item{"category"}; ) else ( # get the category from the database field category = @db_field_item{"category"}; ); # Check derivation_method # derivation_method = @db_field_item{"derivation_method"}; ) else ( db_field_item = new_node(); # Must reset db_field_item # derivation_method = "expression"; if (report_field_item?{"category"}) then ( category = @report_field_item{"category"}; ) else ( category = ""; ); ); # Get the labels report_field_label = @report_field_item{"label"}; column_label = if (@report_field_item{"column_label"} ne "") then (@report_field_item{"column_label"}) else (report_field_label); column_info = if (report_field_item?{"column_info"}) then (@report_field_item{"column_info"}) else (""); # query_field_item . ".derivation_method" = derivation_method; query_field_item . ".report_field_name" = report_field_name; query_field_item . ".report_field_label" = report_field_label; query_field_item . ".column_label" = column_label; query_field_item . ".column_info" = column_info; if (!is_expression) then ( # # report field is based on database field # db_field_type = @db_field_item{"type"}; if (db_field_type eq "int" and db_field_item?{"integer_bits"}) then ( integer_bits = @db_field_item{"integer_bits"}; ) else ( integer_bits = 0; ); aggregation_method = @db_field_item{"aggregation_method"}; query_field_type = db_field_type; table_field_type = query_fields_util_get_table_field_type(db_field_type, false); # query_field_item . ".database_field_type" = db_field_type; query_field_item . ".aggregation_method" = aggregation_method; query_field_item . ".table_field_name" = report_field_name; query_field_item . ".table_field_type" = table_field_type; # Note, a report_field with subitems_level=-2 and category="date_time" is a date_time # database field with a data_time timestamp, that means that its type changes to int, so we have to # set the table_field_type to "int". The date_time timestamp field is only used in the log_detail report. if ((category eq "date_time") and (report_field_item?{"subitems_level"}) and (@report_field_item{"subitems_level"} == -2)) then ( query_field_item . ".table_field_type" = "int"; ); is_aggregating_field = (aggregation_method ne "none"); ) else ( # # Expression # db_field_type = ""; integer_bits = 0; query_field_type = @report_field_item{"type"}; table_field_type = query_fields_util_get_table_field_type(query_field_type, true); query_field_item . ".table_field_name" = report_field_name; query_field_item . ".table_field_type" = table_field_type; query_field_item . ".aggregation_method" = if (query_field_type ne "string") then ("sum") else ("none"); query_field_item . ".expression" = @report_field_item{"expression"}; is_aggregating_field = (query_field_type ne "string"); query_field_item . ".sort_by_before_expression_evaluation" = if (report_field_item?{"sort_by_before_expression_evaluation"}) then (@report_field_item{"sort_by_before_expression_evaluation"}) else (""); query_field_item . ".sort_direction_before_expression_evaluation" = if (report_field_item?{"sort_direction_before_expression_evaluation"}) then (@report_field_item{"sort_direction_before_expression_evaluation"}) else (""); ); if (is_average_denominator_field) then ( # This field is based on a database_field AND expression! # We get the value from the database_field, then divide it by the average_denominator_field # and set the ssql table cell value. # Override # table_field_type to be always float # aggregation_method to be always sum # query_field_item . ".table_field_type" = "float"; # query_field_item . ".aggregation_method" = "sum"; # Add the expression # We require both, the average_denominator_field and the expression. # The expression is used for base_query_headers for total calculation in table reports, # the average_denominator_field is used when generating the raw overview report. query_field_item . ".average_denominator_field" = average_denominator_field; query_field_item . ".expression" = "cell_by_name('" . report_field_name . "') / cell_by_name('" . average_denominator_field . "')"; ); sort_type = if (report_field_item?{"sort_type"}) then (@report_field_item{"sort_type"}) else (""); display_format_type = @report_field_item{"display_format_type"}; if (display_format_type eq "custom") then ( display_format_type = @report_field_item{"custom_display_format_type"}; ); query_field_item . ".type" = query_field_type; if (table_field_type eq "int") then ( query_field_item . ".integer_bits" = integer_bits; ); query_field_item . ".sort_type" = sort_type; query_field_item . ".display_format_type" = display_format_type; query_field_item . ".category" = category; # add subitems_level if (is_hierarchical_db_field or report_field_item?{"subitems_level"}) then ( if (report_field_item?{"subitems_level"}) then ( # Use existing subitems_level subitems_level = @report_field_item{"subitems_level"}; ) else ( # Set default subitems_level subitems_level = -1; ); @query_field_item{"subitems_level"} = subitems_level; ); # Add database_field_name query_field_item . ".database_field_name" = db_field_name; query_field_item . ".database_field_type" = db_field_type; # Add database field node position query_field_item . ".database_field_number" = if (db_field_name ne "") then (@db_field_numbers{db_field_name}) else (-1); # Set is is_aggregating_field query_field_item . ".is_aggregating_field" = is_aggregating_field; # Set percent_calculation, show_average_value, show_min_value, etc. if (is_aggregating_field) then ( query_field_item . ".percent_calculation" = if (report_field_item?{"percent_calculation"}) then (@report_field_item{"percent_calculation"}) else ("sum"); query_field_item . ".show_remainder_value" = if (report_field_item?{"show_remainder_value"}) then (@report_field_item{"show_remainder_value"}) else (true); query_field_item . ".show_average_value" = if (report_field_item?{"show_average_value"}) then (@report_field_item{"show_average_value"}) else (true); query_field_item . ".show_min_value" = if (report_field_item?{"show_min_value"}) then (@report_field_item{"show_min_value"}) else (true); query_field_item . ".show_max_value" = if (report_field_item?{"show_max_value"}) then (@report_field_item{"show_max_value"}) else (true); query_field_item . ".show_total_value" = if (report_field_item?{"show_total_value"}) then (@report_field_item{"show_total_value"}) else (true); # # Set is_date_time_in_epoc # # KHP 24/Oct/2011 - disabled, see comment in query_fields_get_is_date_time_in_epoc() # is_date_time_in_epoc = query_fields_get_is_date_time_in_epoc( # db_fields, # db_field_item, # query_field_type, # category); # query_field_item . ".is_date_time_in_epoc" = is_date_time_in_epoc; # # # Add numerical field color # # if (numerical_colors?{report_field_name}) then ( # Get random numerical field color rgb_color = numerical_colors{report_field_name}; ) else ( # Get random numerical field color if (random_color_count == number_of_random_colors) then ( # Reset the random_color_count random_color_count = 0; ); rgb_color = random_numerical_colors{random_color_count}; random_color_count++; ); red = @rgb_color{"red"}; green = @rgb_color{"green"}; blue = @rgb_color{"blue"}; hex_color = rgb_to_hex_color(red, green, blue); query_field_item . ".rgb_color.red" = red; query_field_item . ".rgb_color.green" = green; query_field_item . ".rgb_color.blue" = blue; query_field_item . ".hex_color" = hex_color; # The table_bar_graph_single_hex_color is for all numerical fields identical. # We add it here for convenience per field so that we don't have to deal with the color node later. # query_field_item . ".table_bar_graph_single_rgb_color.red" = @rgb_single_table_bar_graph{"red"}; # query_field_item . ".table_bar_graph_single_rgb_color.green" = @rgb_single_table_bar_graph{"green"}; # query_field_item . ".table_bar_graph_single_rgb_color.blue" = @rgb_single_table_bar_graph{"blue"}; query_field_item . ".table_bar_graph_single_hex_color" = table_bar_graph_single_hex_color; skip_escaping = false; ) else ( skip_escaping = if (report_field_item?{"skip_escaping"}) then (@report_field_item{"skip_escaping"}) else (false); ); query_field_item . ".skip_escaping" = skip_escaping; # Set query_field is_expression and is_average_denominator_field # We added is_expression to query_fields due the average_denominator_field which is # based on a database_field AND has an expression query_field_item . ".is_expression" = (is_expression or is_average_denominator_field); query_field_item . ".is_average_denominator_field" = is_average_denominator_field; # # Add field_name # We add the database_field_name as "field_name" because it is required by # the C++ code. We may remove field_name later! # ToDO, check if the field_name is still required! # query_field_item . ".field_name" = db_field_name; ); # # Return query_fields # query_fields; ));