# # # # build_chrono_data() # # # Builds a chronological data node # # # subroutine(build_chrono_data( node chrono_graph_query_header, table working_table, int total_rows, string main_field_report_field_name, string main_field_report_field_type, int main_field_ssql_column_number, string chrono_start, string chrono_end, string chrono_type, int number_of_variables_in_chrono_range, int x_length, node chrono_query_data, node every_1st_day_on_graph_lookup), ( debug_message("\n\n#### build_chrono_data() START \n\n"); node column; int ssql_column_number; string report_field_name; # # Set number_of_variables_in_graph # # # Check if the number_of_variables_in_chrono_range fit on the available x-length. # If they don't fit, then sample the variables down. # # int sampling_rate = 1; if (number_of_variables_in_chrono_range > x_length) then ( sampling_rate = number_of_variables_in_chrono_range / x_length; if ((number_of_variables_in_chrono_range % x_length) != 0) then ( sampling_rate += 1; ); ); int number_of_variables_in_graph = number_of_variables_in_chrono_range / sampling_rate; if ((number_of_variables_in_graph % sampling_rate) != 0) then ( number_of_variables_in_graph += 1; ); debug_message("#### build_chrono_data() - number_of_variables_in_graph: " . number_of_variables_in_graph . "\n"); debug_message("#### build_chrono_data() - sampling_rate: " . sampling_rate . "\n"); debug_message("#### build_chrono_data() - x_length: " . x_length . "\n"); debug_message("#### build_chrono_data() - main_field_report_field_type: " . main_field_report_field_type . "\n"); # # # # Create a temp_ssql_date_time_with_row_numbers_lookup node, i.e.: # 09/Feb/2006 __:__:__ = 0 # 10/Feb/2006 __:__:__ = 7 # We use this lookup to refer to the table row by a chrono_date # # # # node temp_ssql_date_time_with_row_numbers_lookup = new_node(); string date_time_lookup_value; for (int row_number = 0; row_number < total_rows; row_number++) ( if (main_field_report_field_type eq "string") then ( date_time_lookup_value = table_get_cell_string_value(working_table, row_number, main_field_ssql_column_number); ) else ( date_time_lookup_value = table_get_cell_value(working_table, row_number, main_field_ssql_column_number); ); @temp_ssql_date_time_with_row_numbers_lookup{date_time_lookup_value} = row_number; ); debug_message("#### temp_ssql_date_time_with_row_numbers_lookup:\n" . node_as_string(temp_ssql_date_time_with_row_numbers_lookup) . "\n"); # # # Create the chronological_query_data node # # string chrono_date = chrono_start; string calendar_date; int x_tick_count; node chrono_query_data_item; int ssql_table_item_row_number; float ssql_table_item_value; float chrono_query_item_value; for (int i = 0; i < number_of_variables_in_graph; i++) ( debug_message("#### i: " . i . "\n"); # Used only if days # Only relevant if use_specific_date_time_interval = true if (chrono_type eq "day") then ( x_tick_count = i; every_1st_day_on_graph_lookup . "." . x_tick_count . ".draft_label" = ""; ); # # # Add the main_field to the chronological_query_data # # chrono_query_data . "." . chrono_date . "." . main_field_report_field_name = chrono_date; # # # create a single chronological_query_data entry, set each graph field value to 0 # # foreach column chrono_graph_query_header ( report_field_name = @column{"report_field_name"}; chrono_query_data . "." . chrono_date . "." . report_field_name = 0.0; ); # # # Sample through the dates for the current chrono_date # # for (int j = 0; j < sampling_rate; j++) ( if (j == 0) then ( calendar_date = chrono_date; ) else ( calendar_date = get_raw_graph_chrono_next_time_unit(calendar_date, chrono_type); ); # # If chronological type is "day" then track the first day of each month # so that we have it right away in case that the x-ticks and x-lables # are displayed on every 1st. # Will only relevant if use_specific_date_time_interval = true # # Note, we only track the 1st! if (chrono_type eq "day") then ( if (starts_with(calendar_date, "01/") and (@(every_1st_day_on_graph_lookup . "." . x_tick_count . ".draft_label") eq "")) then ( every_1st_day_on_graph_lookup . "." . x_tick_count . ".draft_label" = calendar_date; ); ); debug_message("#### calendar_date: " . calendar_date . "\n"); # # # Check if the calendar_date exists in the query result, if it exists we look up # the values an override the graph field values in chrono_date_node_name node in case that # the query_data value is greater than the chronological_query_data value. # (We track only the peaks in chronological_query_data) # # if (temp_ssql_date_time_with_row_numbers_lookup?{calendar_date}) then ( debug_message("#### calendar date " . calendar_date . " exists in lookup \n"); ssql_table_item_row_number = @temp_ssql_date_time_with_row_numbers_lookup{calendar_date}; chrono_query_data_item = chrono_query_data{chrono_date}; foreach column chrono_graph_query_header ( ssql_column_number = node_name(column); report_field_name = @column{"report_field_name"}; ssql_table_item_value = table_get_cell_value(working_table, ssql_table_item_row_number, ssql_column_number); chrono_query_item_value = @chrono_query_data_item{report_field_name}; debug_message("#### ssql_table_item_value: " . ssql_table_item_value . "\n"); debug_message("#### chrono_query_item_value: " . chrono_query_item_value . "\n\n"); if (ssql_table_item_value > chrono_query_item_value) then ( set_subnode_value(chrono_query_data_item, report_field_name, ssql_table_item_value); ); ); ); #* else ( debug_message("#### calendar date " . calendar_date . " does not exist in lookup \n"); ); *# ); # # get the next main date # chrono_date = get_raw_graph_chrono_next_time_unit(calendar_date, chrono_type); ); delete_node(temp_ssql_date_time_with_row_numbers_lookup); # debug_message("\n" . node_as_string(chrono_query_data) . "\n"); # debug_message("\n" . node_as_string(every_1st_day_on_graph_lookup) . "\n"); ));