Beispiel #1
0
 def test_companion_recommendation(self):
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path, self.input_ecosystem)
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path, self.input_ecosystem)
     input_list = ['A', 'B', 'C', 'D']
     recommended_dependency_set = set(['A', 'B', 'C', 'D', 'E'])
     diff_list = obj.check_companion_recommendation_validity(
         recommended_dependency_set, input_list)
     self.assertTrue(len(diff_list) == 3)
     self.assertTrue(diff_list == ['E', 'E', 'F'])
     recommended_dependency_set = set(['A', 'B', 'C', 'D', 'Q'])
     diff_list = obj.check_companion_recommendation_validity(
         recommended_dependency_set, input_list)
     self.assertTrue(len(diff_list) == 0)
    def test_check_companion_recommendation(self):
        """Test the method check_companion_recommendation()."""
        obj = RecommendationValidator.load_package_list_local(
            self.input_folder_name, self.additional_path)
        input_list = ['A', 'B', 'C', 'D']
        companion_packages = [
            {
                "cooccurrence_probability": 0.49942501008907109,
                "package_name": "E",
                "topic_list": ["some_topic"]
            },
            {
                "cooccurrence_probability": 0.42699967636612329,
                "package_name": "F",
                "topic_list": ["some_topic"]
            },
            {
                "cooccurrence_probability": 0.42699967636612329,
                "package_name": "G",
                "topic_list": ["some_topic"]
            }
        ]

        result_companion_list = obj.check_companion_recommendation(
            input_list, companion_packages)
        self.assertTrue(len(result_companion_list) == 2)
        comp_name = [c.get('package_name') for c in result_companion_list]
        self.assertEqual(set(comp_name), {'E', 'F'})
        comp_confidence = [c.get('cooccurrence_probability')
                           for c in result_companion_list]
        self.assertEqual(set(comp_confidence), {100, 50})
 def test_load_manifest_file(self):
     """Test if package list can be deserialized properly."""
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path)
     self.assertTrue(obj is not None)
     self.assertTrue(isinstance(obj, RecommendationValidator))
     self.assertTrue(obj.manifest_len == 4)
 def test_check_alternate_recommendation(self):
     """Test the method check_alternate_recommendation()."""
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path)
     input_list = ['A', 'B', 'C', 'D']
     alternate_packages = {
         "B": [
             {
                 "package_name": "E",
                 "similarity_score": 0.75,
                 "topic_list": ["some_topic"]
             },
             {
                 "package_name": "P",
                 "similarity_score": 0.75,
                 "topic_list": ["some_topic"]
             }
         ]
     }
     result_alternate_list = obj.check_alternate_recommendation(
         input_list, alternate_packages)
     self.assertTrue(len(result_alternate_list) == 1)
     self.assertTrue(result_alternate_list.get(
         'B', [{'test': 'failed'}])[0].get('package_name') == 'E')
     self.assertTrue(result_alternate_list.get(
         'B', [{'test': 'failed'}])[0].get('similarity_score') == 2)
    def test_score_eco_user_package_dict(self):
        """Test the dependency dict deserialization, frequency list deserialization etc."""
        input_data_store = LocalFileSystem(
            "tests/data/data_pgm/input-score-data/")
        self.assertIsNotNone(input_data_store)

        output_data_store = LocalFileSystem(
            "tests/data/data_pgm/output-score-data/")
        self.assertIsNotNone(output_data_store)

        frequency_dict_data_store = LocalFileSystem(
            src_dir="tests/data/data_apollo/")
        self.assertIsNotNone(frequency_dict_data_store)

        user_eco_kronos_dict = load_user_eco_to_kronos_model_dict(
            input_kronos_data_store=input_data_store, additional_path="")

        self.assertIsNotNone(user_eco_kronos_dict)

        eco_to_kronos_dependency_dict = get_eco_to_kronos_dependency_dict(
            data_store=input_data_store, folderpath="data_kronos_dependency")

        self.assertIsNotNone(eco_to_kronos_dependency_dict)

        user_request = [{
            "ecosystem": "pypi",
            "comp_package_count_threshold": 10,
            "alt_package_count_threshold": 1,
            "outlier_probability_threshold": 0.61,
            "unknown_packages_ratio_threshold": 0.4,
            "outlier_package_count_threshold": 2,
            "package_list": ["p1", "p2", "p3", "np1"]
        }]

        frequency_dict = frequency_dict_data_store.read_json_file(
            filename=KD_PACKAGE_FREQUENCY)
        self.assertIsNotNone(frequency_dict)
        all_package_list_obj = RecommendationValidator.load_package_list_local(
            input_folder_name="tests/data/data_recom_valid/",
            additional_path="")

        response = score_eco_user_package_dict(
            user_request,
            user_eco_kronos_dict=user_eco_kronos_dict,
            eco_to_kronos_dependency_dict=eco_to_kronos_dependency_dict,
            all_package_list_obj=all_package_list_obj,
            package_frequency_dict=frequency_dict,
            use_filters=USE_FILTERS)

        self.assertIsNotNone(response)

        output_data_store.write_json_file(filename="response.json",
                                          contents=response)

        expected_response = output_data_store.read_json_file(
            filename="expected_response.json")
        self.assertIsNotNone(expected_response)

        self.assertDictEqual(response[0], expected_response[0])
Beispiel #6
0
 def test_generate_companion_set(self):
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path)
     input_list = ['A', 'B', 'C']
     companion_package = 'D'
     comp_set = obj.generate_companion_dependency_set(
         input_list, companion_package)
     self.assertEqual(comp_set, {'A', 'B', 'C', 'D'})
Beispiel #7
0
 def test_filter_input_list(self):
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path)
     input_set = {'A', 'B', 'C', 'Z'}
     missing_packages = ['Z']
     filtered_input_list = obj.get_filtered_input_list(
         input_set, missing_packages)
     self.assertTrue(sorted(filtered_input_list) == ['A', 'B', 'C'])
Beispiel #8
0
 def test_filter_input_list(self):
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path, self.input_ecosystem)
     input_list = ['A', 'B', 'C', 'Z']
     missing_packages = ['Z']
     filtered_input_list = obj.get_filtered_input_list(
         input_list, missing_packages)
     self.assertTrue(filtered_input_list == ['A', 'B', 'C'])
Beispiel #9
0
 def test_generate_alternate_set(self):
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path)
     input_list = ['A', 'B', 'C']
     alternate_package = 'B123'
     alternate_to = 'B'
     alt_set = obj.generate_alternate_dependency_set(
         input_list, alternate_package, alternate_to)
     self.assertEqual(alt_set, {'A', 'B123', 'C'})
Beispiel #10
0
 def test_companion_recommendation(self):
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path)
     recommended_dependency_set = {'A', 'B', 'C', 'D', 'E'}
     count = obj.check_companion_or_alternate_recommendation_validity(recommended_dependency_set)
     self.assertEqual(count, 2)
     recommended_dependency_set = {'A', 'B', 'C', 'D', 'Q'}
     count = obj.check_companion_or_alternate_recommendation_validity(recommended_dependency_set)
     self.assertEqual(count, 0)
 def test_filter_alternate_list(self):
     """Test the method to get filtered alternate list."""
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path)
     outlier_packages = [{
         "outlier_prbability": 0.99434381708188857,
         "package_name": "A",
         "topic_list": [
             "some_topic",
             "some_topic"
         ]
     }]
     alternate_packages = {
         "B": [
             {
                 "package_name": "Q",
                 "similarity_score": 0.75,
                 "topic_list": ["some_topic"]
             },
             {
                 "package_name": "R",
                 "similarity_score": 0.75,
                 "topic_list": ["some_topic"]
             }
         ],
         "C": [
             {
                 "package_name": "Q",
                 "similarity_score": 0.75,
                 "topic_list": ["some_topic"]
             },
             {
                 "package_name": "R",
                 "similarity_score": 0.75,
                 "topic_list": ["some_topic"]
             }
         ],
         "A": [
             {
                 "package_name": "Q",
                 "similarity_score": 0.75,
                 "topic_list": ["some_topic"]
             },
             {
                 "package_name": "R",
                 "similarity_score": 0.75,
                 "topic_list": ["some_topic"]
             }
         ]
     }
     filtered_alternate_list = obj.get_filtered_alternate_list(
         alternate_packages, outlier_packages)
     self.assertTrue(len(filtered_alternate_list) == len(outlier_packages))
     self.assertTrue(outlier_packages[0][
                     'package_name'] == list(filtered_alternate_list.keys())[0])
Beispiel #12
0
 def test_alternate_recommendation(self):
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path, self.input_ecosystem)
     recommended_dependency_set = set(['A', 'F', 'C', 'D'])
     count = obj.check_alternate_recommendation_validity(
         recommended_dependency_set)
     self.assertTrue(count == 2)
     recommended_dependency_set = set(['A', 'W', 'C', 'D'])
     count = obj.check_alternate_recommendation_validity(
         recommended_dependency_set)
     self.assertTrue(count == 0)
 def __init__(self):
     """Initialize this class."""
     super(CompanionOutlierAccuracy, self).__init__()
     self.user_eco_kronos_dict = load_user_eco_to_kronos_model_dict_s3(
         bucket_name=AWS_BUCKET_NAME, additional_path=KRONOS_MODEL_PATH)
     self.package_frequency_dict = load_package_frequency_dict_s3(
         bucket_name=AWS_BUCKET_NAME, additional_path=KRONOS_MODEL_PATH)
     self.all_package_list_obj = RecommendationValidator.load_package_list_s3(
         input_bucket_name=AWS_BUCKET_NAME, additional_path=KRONOS_MODEL_PATH)
     self.test_set = set()
     self.unique_items_len = 0
Beispiel #14
0
    def test_check_companion_recommendation(self):
        obj = RecommendationValidator.load_package_list_local(
            self.input_folder_name, self.additional_path, self.input_ecosystem)
        input_list = ['A', 'B', 'C', 'D']
        companion_packages = [{
            "cooccurrence_probability": 0.49942501008907109,
            "package_name": "E",
            "topic_list": ["some_topic"]
        }, {
            "cooccurrence_probability": 0.42699967636612329,
            "package_name": "F",
            "topic_list": ["some_topic"]
        }, {
            "cooccurrence_probability": 0.42699967636612329,
            "package_name": "G",
            "topic_list": ["some_topic"]
        }]

        result_companion_list = obj.check_companion_recommendation(
            input_list, companion_packages)
        self.assertTrue(len(result_companion_list) == 2)
        comp_name = [c.get('package_name') for c in result_companion_list]
        self.assertTrue(set(comp_name) == set(['E', 'F']))
Beispiel #15
0
global user_eco_kronos_dict
global eco_to_kronos_dependency_dict
global scoring_status
global all_package_list_obj

hash_dict = dict()

if KRONOS_SCORING_REGION != "":
    app.user_eco_kronos_dict = load_user_eco_to_kronos_model_dict_s3(
        bucket_name=AWS_BUCKET_NAME, additional_path=KRONOS_MODEL_PATH)

    app.eco_to_kronos_dependency_dict = load_eco_to_kronos_dependency_dict_s3(
        bucket_name=AWS_BUCKET_NAME, additional_path=KRONOS_MODEL_PATH)

    app.all_package_list_obj = RecommendationValidator.load_package_list_s3(
        AWS_BUCKET_NAME, KRONOS_MODEL_PATH)

    app.package_frequency_dict = load_package_frequency_dict_s3(
        bucket_name=AWS_BUCKET_NAME, additional_path=KRONOS_MODEL_PATH)

    app.scoring_status = True

    app.logger.info("The total manifest file for this ecosystem are: %d" %
                    app.all_package_list_obj.get_all_list_package_length())
else:
    app.scoring_status = False


@app.before_request
def before_request():
    g.request_start = datetime.datetime.utcnow()
Beispiel #16
0
 def test_load_manifest_file(self):
     obj = RecommendationValidator.load_package_list_local(
         self.input_folder_name, self.additional_path)
     self.assertTrue(obj is not None)
     self.assertTrue(isinstance(obj, RecommendationValidator))
     self.assertTrue(obj.manifest_len == 4)