templates/aws-cloudfront-monitoring/source/lambda.d/metric_collector_download_speed_cdn/metric_collector_download_speed_cdn.py [65:122]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    log.info('[assemble_query_string] End')
    return query_string


def count_by_speed(value, res):
    float_value = float(value)
    if float_value < SPEED_DICT['250K']:
        res['250K'] += 1
    elif float_value >= SPEED_DICT['250K'] and float_value < SPEED_DICT['500K']:
        res['500K'] += 1
    elif float_value >= SPEED_DICT['500K'] and float_value < SPEED_DICT['750K']:
        res['750K'] += 1
    elif float_value >= SPEED_DICT['750K'] and float_value < SPEED_DICT['1M']:
        res['1M'] += 1
    elif float_value >= SPEED_DICT['1M'] and float_value < SPEED_DICT['2M']:
        res['2M'] += 1
    elif float_value >= SPEED_DICT['2M'] and float_value < SPEED_DICT['3M']:
        res['3M'] += 1
    elif float_value >= SPEED_DICT['3M'] and float_value < SPEED_DICT['4M']:
        res['4M'] += 1
    else:
        res['Other'] += 1

    return res


# Generate detailed data according to start time, end time and interval
def gen_detailed_by_interval(metric, start_time, end_time, domain):
    interval_list = []
    start_datetime = datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S")
    end_datetime = datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")
    temp_datetime = start_datetime
    detailed_data = []

    while True:
        log.info("[gen_detailed_by_interval] Setup interval list")
        interval_item = {}
        interval_item['start'] = temp_datetime.strftime("%Y-%m-%d %H:%M:%S")
        temp_datetime += timedelta(minutes=5)
        if not temp_datetime < end_datetime:
            interval_item['end'] = end_datetime.strftime("%Y-%m-%d %H:%M:%S")
            athena_qs = assemble_speed(metric, interval_item['start'],
                                       interval_item['end'], domain)
            athena_query_result = schedule_athena_query(athena_qs)
            interval_item['QueryId'] = athena_query_result['QueryExecutionId']
            interval_list.append(interval_item)
            break
        interval_item['end'] = temp_datetime.strftime("%Y-%m-%d %H:%M:%S")
        athena_qs_5m = assemble_speed(metric, interval_item['start'],
                                      interval_item['end'], domain)
        athena_query_result_5m = schedule_athena_query(athena_qs_5m)
        interval_item['QueryId'] = athena_query_result_5m['QueryExecutionId']
        interval_list.append(interval_item)

    for item in interval_list:
        log.info("[gen_detailed_by_interval] Start to get query result")
        speed_item = {}
        speed_item["domain"] = domain
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



templates/aws-cloudfront-monitoring/source/lambda.d/metric_collector_download_speed_origin/metric_collector_download_speed_origin.py [63:120]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    log.info('[assemble_query_string] End')
    return query_string


def count_by_speed(value, res):
    float_value = float(value)
    if float_value < SPEED_DICT['250K']:
        res['250K'] += 1
    elif float_value >= SPEED_DICT['250K'] and float_value < SPEED_DICT['500K']:
        res['500K'] += 1
    elif float_value >= SPEED_DICT['500K'] and float_value < SPEED_DICT['750K']:
        res['750K'] += 1
    elif float_value >= SPEED_DICT['750K'] and float_value < SPEED_DICT['1M']:
        res['1M'] += 1
    elif float_value >= SPEED_DICT['1M'] and float_value < SPEED_DICT['2M']:
        res['2M'] += 1
    elif float_value >= SPEED_DICT['2M'] and float_value < SPEED_DICT['3M']:
        res['3M'] += 1
    elif float_value >= SPEED_DICT['3M'] and float_value < SPEED_DICT['4M']:
        res['4M'] += 1
    else:
        res['Other'] += 1

    return res


# Generate detailed data according to start time, end time and interval
def gen_detailed_by_interval(metric, start_time, end_time, domain):
    interval_list = []
    start_datetime = datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S")
    end_datetime = datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")
    temp_datetime = start_datetime
    detailed_data = []

    while True:
        log.info("[gen_detailed_by_interval] Setup interval list")
        interval_item = {}
        interval_item['start'] = temp_datetime.strftime("%Y-%m-%d %H:%M:%S")
        temp_datetime += timedelta(minutes=5)
        if not temp_datetime < end_datetime:
            interval_item['end'] = end_datetime.strftime("%Y-%m-%d %H:%M:%S")
            athena_qs = assemble_speed(metric, interval_item['start'],
                                       interval_item['end'], domain)
            athena_query_result = schedule_athena_query(athena_qs)
            interval_item['QueryId'] = athena_query_result['QueryExecutionId']
            interval_list.append(interval_item)
            break
        interval_item['end'] = temp_datetime.strftime("%Y-%m-%d %H:%M:%S")
        athena_qs_5m = assemble_speed(metric, interval_item['start'],
                                      interval_item['end'], domain)
        athena_query_result_5m = schedule_athena_query(athena_qs_5m)
        interval_item['QueryId'] = athena_query_result_5m['QueryExecutionId']
        interval_list.append(interval_item)

    for item in interval_list:
        log.info("[gen_detailed_by_interval] Start to get query result")
        speed_item = {}
        speed_item["domain"] = domain
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



