def post(self, request): new_filters = request.data.get("filters", []) filters = get_qa_metrics_settings(request.user) fields = [field["name"] for field in filters] filters = update_drop_down_fields( filters, get_issues_dataframe( fields=fields, filters=[UNRESOLVED_BUGS_FILTER] ), ) if new_filters: for new_filter in new_filters: for filter_ in filters: if new_filter["name"] == filter_["name"]: filter_.update( { "current_value": new_filter["current_value"], "filtration_type": new_filter[ "filtration_type" ], "exact_match": new_filter["exact_match"], } ) filters += [UNRESOLVED_BUGS_FILTER] cached_filters = redis_conn.get( f"user:{request.user.id}:qa_metrics:filters" ) cached_filters = loads(cached_filters) if cached_filters else [] context = { "records_count": { "total": get_issue_count(filters=[UNRESOLVED_BUGS_FILTER]), "filtered": get_issue_count(filters), }, "filters": filters, } if not cached_filters or not check_filters_equality( filters, cached_filters ): clear_cache( [ "qa_metrics:predictions_table", "qa_metrics:predictions_page", ], request.user.id, ) for element in context: redis_conn.set( f"user:{request.user.id}:qa_metrics:{element}", dumps(context.get(element)), ) return Response(context)
def get(self, request): total_count = get_issue_count(filters=[UNRESOLVED_BUGS_FILTER]) if not total_count: Response({}) cache = redis_conn.get(f"user:{request.user.id}:qa_metrics:filters") filters = [UNRESOLVED_BUGS_FILTER] if cache: filters = loads(cache) context = { "records_count": { "total": total_count, "filtered": get_issue_count(filters), }, } return Response(context)
def create_report_file( created_issues: DataFrame, resolved_issues: DataFrame, filename: str, file_path: str, ) -> None: """Create report file. Parameters ---------- created_issues: Issues created on specific date. resolved_issues: Issues resolved on specific date. filename: Sheet name. file_path: File path. """ with ExcelWriter(file_path, engine="xlsxwriter") as writer: row = 0 text_style = writer.book.add_format({"bold": True}) text_style.set_font_size(SHEET_FONT_SIZE) if not writer.book.get_worksheet_by_name(filename): sheet = writer.book.add_worksheet(filename) writer.sheets.update({filename: sheet}) row += write_report_dataframe( df=created_issues, writer=writer, sheet_name=filename, header="Created", text_style=text_style, row_number=row, ) row += write_report_dataframe( df=resolved_issues, writer=writer, sheet_name=filename, header="Resolved", text_style=text_style, row_number=row, ) text_style = writer.book.add_format({"bold": True, "border": 1}) sheet.write_column( row, 0, ["Total", "Created", "Resolved"], text_style, ) sheet.write_column( row, 1, [get_issue_count(), len(created_issues), len(resolved_issues)], )
def get(self, request): total_count = get_issue_count() if not total_count: return Response({}) cache = redis_conn.get( f"user:{request.user.id}:analysis_and_training:filters" ) filters = None if cache: filters = loads(cache) filtered_count = get_issue_count(filters) context = { "records_count": { "total": total_count, "filtered": filtered_count, }, } return Response(context)
def post(self, request): fields = get_issues_fields(request.user) issues = get_issues_dataframe(fields=fields) filters = get_filters( request.user, issues=issues, ) if request.data.get("action") == "apply": new_filters = request.data.get("filters") if new_filters: for new_filter in new_filters: for filter_ in filters: if new_filter["name"] == filter_["name"]: filter_.update( { "current_value": new_filter[ "current_value" ], "filtration_type": new_filter[ "filtration_type" ], "exact_match": new_filter["exact_match"], } ) issues = get_issues(filters=filters, fields=fields) issues_count = len(issues) context = { "records_count": { "total": get_issue_count(), "filtered": issues_count, }, "filters": filters, } for element in context: redis_conn.set( f"user:{request.user.id}:analysis_and_training:{element}", dumps(context.get(element)), ) remove_cache_record( "analysis_and_training:defect_submission", request.user.id ) return Response(context)
def post(self, request): fields = get_issues_fields(request.user) filters = get_filters( request.user, issues=pd.DataFrame.from_records(get_issues(fields=fields)), ) if request.data.get("action") == "apply": new_filters = request.data.get("filters") if new_filters: for new_filter in new_filters: for filter_ in filters: if new_filter["name"] == filter_["name"]: filter_.update({ "current_value": new_filter["current_value"], "filtration_type": new_filter["filtration_type"], "exact_match": new_filter["exact_match"], }) issues = get_issues(filters=filters, fields=fields) else: issues = get_issues(fields=fields) else: issues = get_issues(fields=fields) if len(issues) == 0: context = { "records_count": { "total": get_issue_count(), "filtered": 0 }, "frequently_terms": [], "statistics": {}, "submission_chart": {}, "significant_terms": {}, "filters": filters, } redis_conn.set(f"analysis_and_training:{request.user.id}", dumps(context)) return Response({}) issues = pd.DataFrame.from_records(issues) freq_terms = calculate_frequently_terms(issues) statistics = calculate_statistics( df=issues, series=["Comments", "Attachments", "Time to Resolve"]) submission_chart = calculate_defect_submission(df=issues, period="Month") significant_terms = get_significant_terms( issues, get_training_settings(request.user)) context = { "records_count": { "total": get_issue_count(), "filtered": len(issues), }, "frequently_terms": freq_terms, "statistics": statistics, "submission_chart": submission_chart, "significant_terms": significant_terms, "filters": filters, } redis_conn.set(f"analysis_and_training:{request.user.id}", dumps(context)) return Response(context)
def check_issues_exist() -> None: """Checks that database have issues. If it doesn't have issues then raises warning.""" if not get_issue_count(): raise BugsNotFoundWarning
def get(self, request): issues_count = get_issue_count() return Response({"issues_loaded": bool(issues_count)})
def get(self, request): context = {"issues_exists": bool(get_issue_count())} return Response(context)