Evaluation.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from CertainTrust import Opinion
  2. from vendors.debian.CSVReader import CSVReader
  3. class Evaluator:
  4. @staticmethod
  5. def evaluate_system(packagefile, months):
  6. '''
  7. Generates AND-opinion of a system, based on its package names and months
  8. :param packagefile: packages installed on the system
  9. :param months: for how many months the prediction is done
  10. :return: system evaluation
  11. '''
  12. packages=CSVReader.readCSVPackages(packagefile)
  13. model=CSVReader.readCSVModel(months)
  14. system={}
  15. for p in packages:
  16. if p in model:
  17. system[p]=model[p]
  18. return Opinion._cum_and(list(system.values()))
  19. @staticmethod
  20. def fuse_models_equal_weights(*models):
  21. '''
  22. Fuses models , assume models have equal lists of packages
  23. :param models: list of model-dictionaries
  24. :return: fused model-dictionary
  25. '''
  26. result_dict = {}
  27. package_list = list(models[0].keys())
  28. for p in package_list:
  29. # get list of items to fuse
  30. p_ops = []
  31. for model in models:
  32. p_ops.append(model[p])
  33. print(p_ops)
  34. weights = [1]*len(p_ops)
  35. # fusion
  36. fused_op = Opinion._internal_fusion(p_ops, weights)
  37. result_dict[p]=fused_op
  38. return result_dict