def get_time_series_fields()

in utils/tsdb.py [0:0]


def get_time_series_fields(mappings: {}):
    """
    Place all fields in the time time_series_fields dictionary.
    :param mappings: Mappings dictionary.
    """
    fields = mappings["properties"]

    # A function to flatten the name of the fields
    def get_all_fields(fields: {}, common: str, result: {}):
        def join_strings(str1: str, str2: str):
            if str1 == "":
                return str2
            return str1 + "." + str2

        for key in fields:
            if "properties" in fields[key]:
                get_all_fields(fields[key]["properties"], join_strings(common, key), result)
            else:
                new_key = join_strings(common, key)
                result[new_key] = fields[key]

    result = {}
    get_all_fields(fields, "", result)

    # Split the time series fields according to metric / dimension
    def cluster_fields_by_type(fields: {}):
        for field in fields:
            if "time_series_dimension" in fields[field] and fields[field]["time_series_dimension"]:
                time_series_fields["dimension"].append(field)
                if fields[field]["type"] in accepted_fields_for_routing:
                    time_series_fields["routing_path"].append(field)
            if "time_series_metric" in fields[field]:
                metric = fields[field]["time_series_metric"]
                time_series_fields[metric].append(field)

    cluster_fields_by_type(result)

    if len(time_series_fields["routing_path"]) == 0:
        print("Routing path is empty. Program will end.")
        exit(0)

    print("The time series fields for the TSDB index are: ")
    for key in time_series_fields:
        if len(time_series_fields[key]) > 0:
            print("\t- {} ({} fields):".format(key, len(time_series_fields[key])))
            for value in time_series_fields[key]:
                print("\t\t- {}".format(value))
    print()