def delete(self): args = request.args # check if the input exists if not args: return {'message': 'No input data provided'}, 400 # get the input project_name = args['project_name'] repository_name = args['repository_name'] feature_name = args['feature_name'] # check if the project exists result = Repositories.get_repositories(project_name, repository_name) if not result: return {'message': 'Repository name not exists'}, 400 # check if the feature exists in this project result = Features.get_features(project_name, repository_name, feature_name) if not result: return {'message': 'Feature name not exists'}, 400 # delete the feature Features.delete_feature(project_name, repository_name, feature_name) result = json.dumps(result, indent=4, sort_keys=True, default=str) # return to the client the deleted feature return {"status": 'success', 'data': result}, 201
def put(self): json_data = request.get_json(force=True) # check if the input exists if not json_data: return {'message': 'No input data provided'}, 400 # get the input project_name = json_data['project_name'] repository_name = json_data['repository_name'] feature_name = json_data['feature_name'] feature_name_new = json_data['feature_name_new'] number_bugs_string = json_data['number_bugs'] number_bugs_string = number_bugs_string.replace('"', '') number_bugs_string = number_bugs_string.replace(" ", "") number_bugs = int(number_bugs_string) result = Features.get_features(project_name, repository_name, feature_name) if not result: return {'message': 'Feature name not exists'}, 400 Features.update_feature_number_bug(project_name, repository_name, feature_name, feature_name_new, number_bugs) return {"status": 'success'}, 201
def post(self): json_data = request.get_json(force=True) # check if the input exists if not json_data: return {'message': 'No input data provided'}, 400 # get the input project_name = json_data['project_name'] repository_name = json_data['repository_name'] feature_name = json_data['feature_name'] file_path = json_data['file_path'] # check if the project exists result = Repositories.get_repositories(project_name, repository_name) if len(result) < 1: return {'message': 'Repository name not exists'}, 400 # check if the file_name exists in the project file_path = file_path.replace('\\\\', '\\') file_path = file_path.replace(' ', '') result = Files.get_files(project_name=project_name, repository_name=repository_name, file_path=file_path) if not result: return {'message': 'File path not exists'}, 400 # check if the feature_name exists in the project result = Features.get_features(project_name, repository_name, feature_name) if not result: return {'message': 'Feature name not exists'}, 400 # check if the feature_name exists in the project result = Associations.get_associations(project_name, repository_name, file_path, feature_name) if result: return {'message': 'Association name already exists'}, 400 # create the association Associations.new_association(project_name, repository_name, file_path, feature_name) # update the numbe of features associated to the file Files.update_file(project_name, repository_name, file_path) # # update the number of files associated to the feature Features.update_feature_files_associated(project_name, repository_name, feature_name) # get the new association to confirm that everything is OK result = Associations.get_associations(project_name, repository_name, file_path, feature_name) result = json.dumps(result, indent=4, sort_keys=True, default=str) # return the new association to the client return {"status": 'success', 'data': result}, 201
def delete_repository(project_name, repository_name): print("Repositories.delete_repositories(" + project_name + ", " + repository_name + ")") Commits.delete_table(project_name, repository_name) Files.delete_table(project_name, repository_name) Features.delete_table(project_name, repository_name) Associations.delete_table(project_name, repository_name) Authors.delete_table(project_name, repository_name) Reports.delete_table(project_name, repository_name) mydb = client[project_name] mycol = mydb['repositories'] mycol.delete_one({'repository_name': repository_name})
def new_repository(project_name, repository_name, url): print("Repositories.new_repository(" + project_name + ", " + repository_name + ", " + url + ")") mydb = client[project_name] mycol = mydb['repositories'] mydict = {"repository_name": repository_name, "url": url} x = mycol.insert_one(mydict) Associations.__init__(project_name, repository_name) Features.__init__(project_name, repository_name) Files.__init__(project_name, repository_name) Authors.__init__(project_name, repository_name) Commits.__init__(project_name, repository_name)
def delete(self): args = request.args # check if the input exists if not args: return {'message': 'No input data provided'}, 400 # get the input project_name = args['project_name'] repository_name = args['repository_name'] feature_name = args['feature_name'] file_path = args['file_path'] # check if the project exists result = Repositories.get_repositories(project_name, repository_name) if not result: return {'message': 'Repository name not exists'}, 400 file_path = file_path.replace('\\\\', '\\') file_path = file_path.replace(' ', '') result = Files.get_files(project_name=project_name, repository_name=repository_name, file_path=file_path) if not result: return {'message': 'File path not exists'}, 400 # check if the association exists in this repository result = Associations.get_associations(project_name, repository_name, file_path, feature_name) if not result: return {'message': 'Association not exists'}, 400 # delete the association Associations.delete_association(project_name, repository_name, file_path, feature_name) # update the numbe of features associated to the file Files.update_file(project_name, repository_name, file_path) # # update the number of files associated to the feature Features.update_feature_files_associated(project_name, repository_name, feature_name) result = json.dumps(result, indent=4, sort_keys=True, default=str) # return to the client the deleted association return {"status": 'success', 'data': result}, 201
def get(self): print('GET Feature') args = request.args if not args: return {'message': 'No input data provided'}, 400 project_name = args['project_name'] repository_name = args['repository_name'] result = Features.get_features(project_name, repository_name) result = json.dumps(result, indent=4, sort_keys=True, default=str) return {"data": result}, 201
def post(self): json_data = request.get_json(force=True) # check if the input exists if not json_data: return {'message': 'No input data provided'}, 400 # get the input project_name = json_data['project_name'] repository_name = json_data['repository_name'] feature_name = json_data['feature_name'] number_bugs_string = json_data['number_bugs'] number_bugs = int(number_bugs_string) # check if the project exists result = Repositories.get_repositories(project_name, repository_name) if not result: return {'message': 'Repository name not exists'}, 400 # check if the feature already exists result = Features.get_features(project_name, repository_name, feature_name) if len(result) > 1: return {'message': 'Feature name already exists'}, 400 # create the new feature Features.new_feature(project_name, repository_name, feature_name, number_bugs) # get the new feature to confirm that everything is OK result = Features.get_features(project_name, repository_name, feature_name) result = json.dumps(result, indent=4, sort_keys=True, default=str) return {"status": 'success', 'data': result}, 201
def create_report(project_name, repository_name, date): try: from modelsFolder.model_Commits import Commits except ImportError: print("Repositories are already imported") try: from modelsFolder.model_Authors import Authors except ImportError: print("Authors are already imported") try: from modelsFolder.model_Files import Files except ImportError: print("Files are already imported") try: from modelsFolder.model_Associations import Associations except ImportError: print("Associations are already imported") try: from modelsFolder.model_Features import Features except ImportError: print("Features are already imported") mydb = client[project_name] mycol = mydb[repository_name + '_reports'] mycol.drop() date_init = date.replace('-', '') date_init = int(date_init) author_dict = { } # This dict is to save all the authors that make some commit in the date_range author_total_dict = { } # This dict is to save all the authors in the repo and the number of commits author_percent_dict = { } # This dict is to save the percent of commits that the author make compare to the total_commits total_commits = 0 # This int is to save the total number of commits commits = Commits.get_commits(project_name, repository_name) # Get the files modified in the range and see if was or not associated files_not_associated = [] files_associated = [] for c in commits: # print(str(c['date'])[0:9]) date_commit = int(str(c['date'])[0:10].replace( '-', '')) # Convert to int to compare if date_commit >= date_init: author_dict[c['author']] = author_dict.get( c['author'], 0) + 1 # Count the number of commits # Get the files modified in the commit files = Commits.get_files_commit(project_name, repository_name, c['hash']) for f in files: # Get the File object from table Files obj_file = Files.get_files(project_name, repository_name, file_path=f['file_path']) if obj_file[0]['number_features_associated'] > 0: files_associated.append(f['file_path']) else: files_not_associated.append(f['file_path']) authors = Authors.get_authors(project_name, repository_name) for a in authors: total_commits += a['number_commits'] if a['author_name'] in author_dict: author_total_dict[a['author_name']] = a['number_commits'] for a in author_total_dict: author_percent_dict[a] = author_total_dict[a] / total_commits print('Author percent dict: ' + str(author_percent_dict)) print("The files " + str(files_associated) + " have been associated.") print("The files " + str(files_not_associated) + " have not been associated yet.") # Get the features of associated files features_modified = {} for file_associated in files_associated: associations = Associations.get_associations( project_name=project_name, repository_name=repository_name, file_path=file_associated) for a in associations: features_modified[a['feature_name']] = features_modified.get( a['feature_name'], 0) + 1 print('Features modified: ' + str(features_modified)) # Init the Metric: features = Features.get_features(project_name, repository_name) features_prio = {} # This dict mesure the priorization of the feature for f in features: if f['feature_name'] in features_modified: features_prio[f['feature_name']] = f['number_bugs'] * 2 + f[ 'number_files_associated'] * 1 + features_modified[ f['feature_name']] * 4 else: features_prio[f['feature_name']] = f['number_bugs'] * 2 + f[ 'number_files_associated'] * 1 print(features_prio) for f in features: if f['feature_name'] in features_modified: mydict = { "feature_name": f['feature_name'], "prio": features_prio[f['feature_name']], "date": date, "number_files_associated": f['number_files_associated'], "number_bugs": f['number_bugs'], "number_files_modified": features_modified[f['feature_name']] } x = mycol.insert_one(mydict) else: mydict = { "feature_name": f['feature_name'], "prio": features_prio[f['feature_name']], "date": date, "number_files_associated": f['number_files_associated'], "number_bugs": f['number_bugs'], "number_files_modified": 0 } x = mycol.insert_one(mydict) return {"features_prio": features_prio}