from CertainTrust import Opinion
from CSVReader import CSVReader

class Evaluator:
    @staticmethod
    def evaluate_system(packagefile, months):
        '''
        Evaluates a system, based on its packages and months to evaluate
        :param packagefile: packages installed on the system
        :param months: for how many months the prediction is done
        :return: system evaluation
        '''
        packages=CSVReader.readCSVPackages(packagefile)
        model=CSVReader.readCSVModel(months)

        system={}
        for p in packages:
            if p in model:
                system[p]=model[p]

        return Opinion._cum_and(list(system.values()))

    @staticmethod
    def fuse_models_equal_weights(*models):
        '''
        Fuses models , assume models have equal lists of packages
        :param models: list of model-dictionaries
        :return: fused model-dictionary
        '''
        result_dict = {}
        package_list = list(models[0].keys())
        for p in package_list:
            # get list of items to fuse
            p_ops = []
            for model in models:
                p_ops.append(model[p])
            print(p_ops)
            weights = [1]*len(p_ops)
            # fusion
            fused_op = Opinion._internal_fusion(p_ops, weights)
            result_dict[p]=fused_op
        return result_dict



'''
print( Evaluator.fuse_models_equal_weights(CSVReader.readCSVModel(9),CSVReader.readCSVModel(12)))
print(Evaluator.evaluate_system("inputs/dummy_input_package.csv", 9))
'''
