import os from CertainTrust import Opinion from vendors.debian.CSVReader import CSVReader class Tests: @staticmethod def input_prediction_error_test(model): norm_param = 4 model_filename = os.path.join(model.module_path, "models", "dummy_input_package_prediction_errorcompl.csv") model_set = model.gen_model_opinion_set(model_filename, 9, norm_param) system_filename = os.path.join(model.module_path, "inputs", "dummy_input_package_server.csv") system = CSVReader.read_csv_package_names(system_filename) # get system dict system_dict = dict() for key in system: print(key) new_key = model.unifySrcName(key) if new_key in model_set: system_dict[new_key] = model_set[new_key] print("Evaluating on: " + str(len(system_dict)) + " out of " + str( len(system)) + " packages, since they are not present in our model.") Tests.evaluate_expectation(system_dict, model, 9, norm_param) @staticmethod def evaluate_expectation(package_list, vendormodel, months, norm_val): """ TODO: :param package_list: dictionary of opinions with names as key and opinion as value :param vendormodel: the vendor-model to compare the prediction with :return: TODO: """ print("For normalization value = " + str(norm_val)) # ANDed prediction system_and = Opinion._cum_and(list(package_list.values())) expectation = system_and.expectation_value() AND_prediction = (1 - expectation) * (norm_val * months * 30) # separate prediction sep_pred = 0 for k in package_list: sep_pred = sep_pred + ((1 - package_list[k].expectation_value()) * (norm_val * months * 30)) # src2month prediction gathering summ = 0 for package in package_list: unified_package = vendormodel.unifySrcName(package) src2month = vendormodel.get_src2month() if unified_package in src2month: summ = summ + sum(src2month[package][-months - 3:-3]) file_error = abs(summ - CSVReader.prediction_read) / summ print("Input file prediction = " + str(CSVReader.prediction_read) + ", ( error = " + str(file_error) + " )") sep_error = abs(summ - sep_pred) / summ print("Separate prediction = " + str(sep_pred) + ", ( error = " + str(sep_error) + " )") and_error = abs(summ - AND_prediction) / summ print("ANDed prediction = " + str(AND_prediction) + ", ( error = " + str(and_error) + " )") print("Src2month data = " + str(summ))