def __init__(self, sha):
        self.sha = sha

        settings = Settings()
        self._downloads_path = settings.get_path('downloads')
        self._download_archive_path = settings.get_path('download_archive')
        self._earliest_project_view = settings.get_database_view(
            'earliest_project')
Beispiel #2
0
    def __init__(self,
                 expert_language,
                 second_language,
                 expert_loc=10000,
                 second_loc=1000):
        """
        :param expert_language: helper.language.Language object of the expert language.
        :param second_language: helper.language.Language object of the language to examine. For now just Python.
        :param expert_loc: Lines of code that is the threshold for an expert.
        :param second_loc: Lines of code threshold for the language to examine to get a code base that is large enough.
        """
        self.expert_language = expert_language
        self.second_language = second_language
        self.expert_loc = expert_loc
        self.second_loc = second_loc

        settings = Settings()
        loc_user_file_ext_view = settings.get_database_view(
            'loc_user_file_ext')

        self.query = SQL('''
            SELECT
                u1.user_id,
                u1.login
            FROM {} AS u1
                JOIN {} AS u2 ON u1.user_id = u2.user_id
                JOIN users u ON u1.user_id = u.id
            WHERE u1.additions >= %s AND u1.file_ext = ANY(%s) AND u2.additions >= %s AND u2.file_ext = ANY(%s) AND u.type = 'USR';
        ''').format(Identifier(loc_user_file_ext_view),
                    Identifier(loc_user_file_ext_view))

        self.detection_path = settings.get_path([
            'detections',
            expert_language.language + '_' + second_language.language
        ])
Beispiel #3
0
    def __init__(self,
                 user_id,
                 login,
                 expert_language,
                 second_language,
                 expert_loc=10000,
                 second_loc=1000):
        """
        :param user_id: User id
        :param login: User name
        :param expert_language: helper.language.Language object of the expert language.
        :param second_language: helper.language.Language object of the language to examine. For now just Python.
        :param expert_loc: Lines of code that is the threshold for an expert.
        :param second_loc: Lines of code threshold for the language to examine to get a code base that is large enough.
        """
        self.user_id = user_id
        self.login = login
        self.expert_language = expert_language
        self.second_language = second_language
        self.expert_loc = expert_loc
        self.second_loc = second_loc

        settings = Settings()
        if self.expert_language.language == 'java' and self.second_language.language == 'python':
            self.candidates_view = settings.get_database_view(
                'candidates_java_py')
            self.result_dir_path = settings.get_path(
                ['detections', 'java_python'])
        elif self.expert_language.language == 'cpp' and self.second_language.language == 'python':
            self.candidates_view = settings.get_database_view(
                'candidates_cpp_py')
            self.result_dir_path = settings.get_path(
                ['detections', 'cpp_python'])
        elif self.expert_language.language == 'fun' and self.second_language.language == 'python':
            self.candidates_view = settings.get_database_view(
                'candidates_fun_py')
            self.result_dir_path = settings.get_path(
                ['detections', 'fun_python'])
        else:
            raise ValueError(
                'No database view for this combination of languages.')
 def __init__(self):
     settings = Settings()
     self.archive_path = settings.get_path('download_archive')
     self.download_path = settings.get_path('downloads')
 def __init__(self, figsize=(800, 600)):
     settings = Settings()
     self.figsize = figsize
     self.plot_dir = settings.get_path('plots')
def main():
    settings = Settings()
    java_aggregation_path = settings.get_path(['detections', 'java_python'])
    cpp_aggregation_path = settings.get_path(['detections', 'cpp_python'])
    fun_aggregation_path = settings.get_path(['detections', 'fun_python'])

    aggregation_paths = [
        java_aggregation_path, cpp_aggregation_path, fun_aggregation_path
    ]
    aggregation_paths = [p + '/detections.json' for p in aggregation_paths]

    aggregators = [Aggregator.load(p) for p in aggregation_paths]
    labels = ['Java', 'C++', 'func languages']

    plotter = Plotter()

    # if
    if_percentage = [a.percentage(IfDetection, 'user_id') for a in aggregators]
    if_elseif_count_aggregation = [
        a.aggregate(IfDetection, 'elseif_count', 'user_id')
        for a in aggregators
    ]
    if_has_else_aggregation = [
        a.aggregate(IfDetection, 'has_else', 'user_id') for a in aggregators
    ]

    plotter(if_percentage, labels, 'If percentage')
    plotter(if_elseif_count_aggregation, labels, 'Elseif count')
    plotter(if_has_else_aggregation, labels, 'If has else')

    # class
    def line_count(detection):
        return detection.end - detection.begin + 1

    def name_length(detection):
        return len(detection.name)

    class_definition_percentage = [
        a.percentage(ClassDefinitionDetection, 'user_id') for a in aggregators
    ]
    class_line_count_aggregation = [
        a.aggregate(ClassDefinitionDetection, line_count, 'user_id')
        for a in aggregators
    ]
    class_method_count_aggregation = [
        a.aggregate(ClassDefinitionDetection, 'method_count', 'user_id')
        for a in aggregators
    ]
    class_name_length_aggregation = [
        a.aggregate(ClassDefinitionDetection, name_length, 'user_id')
        for a in aggregators
    ]
    class_is_nested_aggregation = [
        a.aggregate(ClassDefinitionDetection, 'nested', 'user_id')
        for a in aggregators
    ]

    plotter(class_definition_percentage, labels, 'Class percentage')
    plotter(class_line_count_aggregation, labels, 'Class line count')
    plotter(class_method_count_aggregation, labels, 'Class method count')
    plotter(class_name_length_aggregation, labels, 'Class name length')
    plotter(class_is_nested_aggregation, labels, 'Class is nested')

    # built in functions
    class IsFunction:
        def __init__(self, name):
            self.name = name

        def __call__(self, detection):
            return 1 if detection.name == self.name else 0

    bif_percentage = [
        a.percentage(BuiltInFunctionDetection, 'user_id') for a in aggregators
    ]
    bif_map_count_aggregation = [
        a.aggregate(BuiltInFunctionDetection, IsFunction('map'), 'user_id')
        for a in aggregators
    ]
    bif_filter_count_aggregation = [
        a.aggregate(BuiltInFunctionDetection, IsFunction('filter'), 'user_id')
        for a in aggregators
    ]
    bif_list_count_aggregation = [
        a.aggregate(BuiltInFunctionDetection, IsFunction('list'), 'user_id')
        for a in aggregators
    ]
    bif_dict_count_aggregation = [
        a.aggregate(BuiltInFunctionDetection, IsFunction('dict'), 'user_id')
        for a in aggregators
    ]
    bif_set_count_aggregation = [
        a.aggregate(BuiltInFunctionDetection, IsFunction('set'), 'user_id')
        for a in aggregators
    ]

    plotter(bif_percentage, labels, 'Built in function percentage')
    plotter(bif_map_count_aggregation, labels, 'Map percentage')
    plotter(bif_filter_count_aggregation, labels, 'Filter percentage')
    plotter(bif_list_count_aggregation, labels, 'List percentage')
    plotter(bif_dict_count_aggregation, labels, 'Dict percentage')
    plotter(bif_set_count_aggregation, labels, 'Set percentage')

    # comprehensions
    list_comprehension_percentage = [
        a.percentage(ListComprehensionDetection, 'user_id')
        for a in aggregators
    ]
    dict_comprehension_percentage = [
        a.percentage(DictComprehensionDetection, 'user_id')
        for a in aggregators
    ]
    set_comprehension_percentage = [
        a.percentage(SetComprehensionDetection, 'user_id') for a in aggregators
    ]

    list_comprehension_generator_count_aggregation = [
        a.aggregate(ListComprehensionDetection, 'generator_count', 'user_id')
        for a in aggregators
    ]
    dict_comprehension_generator_count_aggregation = [
        a.aggregate(DictComprehensionDetection, 'generator_count', 'user_id')
        for a in aggregators
    ]
    set_comprehension_generator_count_aggregation = [
        a.aggregate(SetComprehensionDetection, 'generator_count', 'user_id')
        for a in aggregators
    ]

    plotter(list_comprehension_percentage, labels,
            'List comprehension percentage')
    plotter(dict_comprehension_percentage, labels,
            'Dict comprehension percentage')
    plotter(set_comprehension_percentage, labels,
            'Set comprehension percentage')
    plotter(list_comprehension_generator_count_aggregation, labels,
            'List comprehension generator count')
    plotter(dict_comprehension_generator_count_aggregation, labels,
            'Dict comprehension generator count')
    plotter(set_comprehension_generator_count_aggregation, labels,
            'Set comprehension generator count')