from typing import List
import json


def compare_apache_profiles(baseline_file, test_file, threshold=0.5) -> List:
    """
    Compare baseline Apache access log profile against test profile.
    :param baseline_file: file containing baseline profile
    :param test_file: file containing test profile
    :param threshold: percent (in decimal format) difference test profile must be from baseline to be considered malicious
    :return: list of results
    """
    results = []
    with open(baseline_file, 'r') as f:
        baseline_profile = json.load(f)
    with open(test_file, 'r') as f:
        test_profile = json.load(f)
    baseline_all_avg_per_min = baseline_profile['requests']['all']['avg_per_min']
    test_all_avg_per_min = test_profile['requests']['all']['avg_per_min']
    baseline_limit_avg_per_min = baseline_all_avg_per_min * (1 + threshold)
    if test_all_avg_per_min > baseline_limit_avg_per_min:
        result = {'category': 'Potential DoS Attack',
                  'details': {'baseline_profile_avg_per_min': baseline_all_avg_per_min,
                              'test_profile_avg_per_min': test_all_avg_per_min,
                              'baseline_profile_upper_limit': baseline_limit_avg_per_min,
                              'baseline_profile_threshold_percent': threshold * 100}}
        results.append(result)
    return results