def _organisation_indicators_summary(organisation, aggregation_type=2): summarydata = dqorganisations._organisation_indicators(organisation, aggregation_type) # Create crude total score totalpct = 0.00 totalindicators = 0 if not summarydata: return None percentages = [ i["results_pct"] for i in summarydata.values() ] totalpct = reduce(operator.add, percentages, 0.0) totalindicators = len(percentages) totalscore = totalpct/totalindicators return totalscore, totalindicators
def organisation_publication_unauthorised(organisation_code, aggregation_type): aggregation_type=integerise(request.args.get('aggregation_type', 2)) all_aggregation_types = dqaggregationtypes.aggregationTypes() organisation = Organisation.query.filter_by( organisation_code=organisation_code).first_or_404() aggregate_results = dqorganisations._organisation_indicators( organisation, aggregation_type) packages = dqorganisations.organisationPackages(organisation_code) return render_template("organisation_publication_public.html", organisation=organisation, results=aggregate_results, all_aggregation_types=all_aggregation_types, aggregation_type=aggregation_type, packages=packages, admin=usermanagement.check_perms('admin'), loggedinuser=current_user)
def all_organisations_publication_csv(): strIO = StringIO.StringIO() fieldnames = "organisation_name organisation_code indicator_category_name indicator_subcategory_name indicator_name indicator_description percentage_passed num_results points".split() out = unicodecsv.DictWriter(strIO, fieldnames=fieldnames) headers = {} for fieldname in fieldnames: headers[fieldname] = fieldname out.writerow(headers) organisations = Organisation.query.all() for organisation in organisations: aggregate_results = dqorganisations._organisation_indicators( organisation) if (organisation.frequency == "less than quarterly"): freq = 0.9 else: freq = 1.0 for resultid, result in aggregate_results.items(): if result['results_pct'] == 0: points = str(0) else: points = str(((float(result['results_pct'])*freq)/2.0)+50) out.writerow({ "organisation_name": organisation.organisation_name, "organisation_code": organisation.organisation_code, "indicator_category_name": result['indicator']['indicator_category_name'], "indicator_subcategory_name": result['indicator']['indicator_subcategory_name'], "indicator_name": result['indicator']['description'], "indicator_description": result['indicator']['longdescription'], "percentage_passed": result['results_pct'], "num_results": result['results_num'], "points": points }) strIO.seek(0) return send_file(strIO, attachment_filename="dataqualityresults_all.csv", as_attachment=True)
def organisation_publication(organisation_code=None, aggregation_type=2): check_perms = usermanagement.check_perms( 'organisation', 'view', {'organisation_code': organisation_code} ) if check_perms: aggregation_type=integerise(request.args.get('aggregation_type', 2)) all_aggregation_types = dqaggregationtypes.aggregationTypes() organisation = Organisation.query.filter_by( organisation_code=organisation_code).first_or_404() aggregate_results = dqorganisations._organisation_indicators_split( organisation, aggregation_type) organisation_survey = dqsurveys.getSurvey(organisation_code) surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code) if organisation_survey: if organisation_survey.Workflow.name in ['donorreview', 'pwyfreview']: surveydata = surveydata["researcher"] surveydata_workflow = 'donorreview' elif organisation_survey.Workflow.name in ['donorcomments', 'pwyffinal']: surveydata = surveydata["pwyfreview"] surveydata_workflow = 'donorcomments' elif organisation_survey.Workflow.name == 'finalised': surveydata = surveydata["pwyffinal"] surveydata_workflow = 'finalised' else: surveydata = None surveydata_workflow=None else: surveydata = None surveydata_workflow=None published_status = dqsurveys.publishedStatus() published_status_by_id = dict(map(lambda x: (x.id, x), published_status)) publishedformats = dqsurveys.publishedFormatsAll() publishedformats = dict(map(lambda pf: (pf.id, pf), publishedformats)) published_status_by_id[None] = { 'name': 'Unknown', 'publishedstatus_class': 'label-inverse' } publishedformats[None] = { 'name': 'Unknown', 'format_class': 'label-inverse' } latest_runtime=1 return render_template("organisation_indicators.html", organisation=organisation, results=aggregate_results, runtime=latest_runtime, all_aggregation_types=all_aggregation_types, aggregation_type=aggregation_type, surveydata=surveydata, published_status=published_status_by_id, published_format=publishedformats, surveydata_workflow=surveydata_workflow, admin=usermanagement.check_perms('admin'), loggedinuser=current_user) else: aggregation_type=integerise(request.args.get('aggregation_type', 2)) all_aggregation_types = dqaggregationtypes.aggregationTypes() organisation = Organisation.query.filter_by( organisation_code=organisation_code).first_or_404() aggregate_results = dqorganisations._organisation_indicators( organisation, aggregation_type) packages = dqorganisations.organisationPackages(organisation_code) return render_template("organisation_publication_public.html", organisation=organisation, results=aggregate_results, all_aggregation_types=all_aggregation_types, aggregation_type=aggregation_type, packages=packages, admin=usermanagement.check_perms('admin'), loggedinuser=current_user)