def organisation_survey_view(organisation_code, workflow, workflow_name, organisationsurvey, allowed_to_edit): organisation = Organisation.query.filter_by( organisation_code=organisation_code).first_or_404() surveydata = dqsurveys.getSurveyData(organisation_code, workflow_name) surveydata_allworkflows = dqsurveys.getSurveyDataAllWorkflows(organisation_code) indicators = dqindicators.indicators("pwyf2013") org_indicators = dqorganisations._organisation_indicators_split( organisation, 2) twentytwelvedata=get_organisation_results(organisation_code, indicators) publishedstatuses = dqsurveys.publishedStatus() publishedstatuses = dict(map(lambda ps: (ps.id, ps), publishedstatuses)) publishedformats = dqsurveys.publishedFormat() publishedformats = dict(map(lambda pf: (pf.id, pf), publishedformats)) template_path = "surveys/_survey_"+workflow.WorkflowType.name+".html" return render_template( template_path, organisation=organisation, indicators=indicators, org_indicators = org_indicators, twentytwelvedata=twentytwelvedata, old_publication_status=old_publication_status, publishedstatuses=publishedstatuses, workflow=workflow, surveydata=surveydata_allworkflows, organisationsurvey=organisationsurvey, allowed_to_edit=allowed_to_edit, publishedformats=publishedformats, admin=usermanagement.check_perms('admin'), loggedinuser=current_user)
def organisation_publication_authorised(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_split( organisation, aggregation_type) organisation_survey = dqsurveys.getSurvey(organisation_code) surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code) surveydata, surveydata_workflow = get_survey_data_and_workflow( organisation_survey, surveydata) published_status_by_id = dict(map(id_tuple, dqsurveys.publishedStatus())) publishedformats = dict(map(id_tuple, dqsurveys.publishedFormatsAll())) published_status_by_id[None] = { 'name': 'Unknown', 'publishedstatus_class': 'label-inverse' } publishedformats[None] = { 'name': 'Unknown', 'format_class': 'label-inverse' } latest_runtime=1 years = dict(get_ordinal_values_years()) 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, years=years)
def organisation_survey_view(organisation_code, workflow, workflow_name, organisationsurvey, allowed_to_edit): organisation = Organisation.query.filter_by( organisation_code=organisation_code).first_or_404() # the next line may be being called for its side effects dqsurveys.getSurveyData(organisation_code, workflow_name) surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code) try: print surveydata['cso'] except Exception: pass indicators = dqindicators.indicators(app.config["INDICATOR_GROUP"]) org_indicators = dqorganisations._organisation_indicators_split( organisation, 2) twentytwelvedata = iatidq.survey.mapping.get_organisation_results( organisation_code, [i[1]["indicator"]["name"] for i in org_indicators["zero"].items()] ) publishedstatuses = dict(map(id_tuple, dqsurveys.publishedStatus())) publishedformats = dict(map(id_tuple, dqsurveys.publishedFormatAll())) years = get_ordinal_values_years() year_data = dict(years) years.pop() donorresponses = donorresponse.RESPONSE_IDS old_publication_status = get_old_publication_status() admin = usermanagement.check_perms('admin') loggedinuser = current_user org_indicators['commitment'] = util.resort_sqlalchemy_indicator(org_indicators['commitment']) org_indicators['zero'] = util.resort_dict_indicator(org_indicators['zero']) return render_template( "surveys/_survey_%s.html" % workflow.WorkflowType.name, **locals())
def checkSurveyData(organisation_code): # for each currently active stage of the workflow # check if there is an indicator at each stage of the workflow # if not, then create one allindicators = dqindicators.indicators(app.config["INDICATOR_GROUP"]) allindicators = map(lambda x: x.id, allindicators) organisation = dqorganisations.organisations(organisation_code) org_indicators = dqorganisations._organisation_indicators_split(organisation, 2)["zero"].keys() survey = getSurvey(organisation_code).OrganisationSurvey survey_data = getSurveyDataAllWorkflows(organisation_code) for workflow_name, v in survey_data.items(): workflow = workflowByName(workflow_name) survey_indicators = v.keys() for indicator in org_indicators: if indicator not in survey_indicators: return False return True
def repairSurveyData(organisation_code): # for each currently active stage of the workflow # check if there is an indicator at each stage of the workflow # if not, then create one changes = False changed_indicators = [] allindicators = dqindicators.indicators(app.config["INDICATOR_GROUP"]) allindicators = map(lambda x: x.id, allindicators) organisation = dqorganisations.organisations(organisation_code) org_indicators = dqorganisations._organisation_indicators_split(organisation, 2)["zero"] survey = getSurvey(organisation_code).OrganisationSurvey survey_data = getSurveyDataAllWorkflows(organisation_code) for workflow_name, v in survey_data.items(): workflow = workflowByName(workflow_name) survey_indicators = v.keys() for indicator, indicatordata in org_indicators.items(): if indicator not in survey_indicators: print "NOT FOUND:", indicator data = { 'organisationsurvey_id' : survey.id, 'workflow_id' : workflow.Workflow.id, 'indicator_id' : indicator, 'published_status' : None, 'published_source' : None, 'published_comment' : None, 'published_accepted' : None, 'published_format' : None, 'ordinal_value' : None } addSurveyData(data) changes = True changed_indicators.append(indicatordata["indicator_name"]) else: print "FOUND:", indicator return {'changes': changes, 'changed_indicators': changed_indicators}
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)
def organisation_publication_authorised(organisation_code, aggregation_type): aggregation_type=integerise(request.args.get('aggregation_type', 2)) all_aggregation_types = dqaggregationtypes.allAggregationTypes() organisation = Organisation.query.filter_by( organisation_code=organisation_code).first_or_404() aggregate_results = dqorganisations._organisation_indicators_split( organisation, aggregation_type) aggregate_results['zero'] = util.resort_dict_indicator( aggregate_results['zero']) aggregate_results['non_zero'] = util.resort_dict_indicator( aggregate_results['non_zero']) organisation_survey = dqsurveys.getSurvey(organisation_code) surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code) surveydata, surveydata_workflow = dqsurveys.get_survey_data_and_workflow( organisation_survey, surveydata) published_status_by_id = dict(map(id_tuple, dqsurveys.publishedStatus())) publishedformats = dict(map(id_tuple, dqsurveys.publishedFormatsAll())) published_status_by_id[None] = { 'title': 'Unknown', 'title': 'unknown', 'publishedstatus_class': 'label-inverse' } publishedformats[None] = { 'title': 'Unknown', 'name': 'unknown', 'format_class': 'label-inverse' } latest_runtime=1 years = dict(get_ordinal_values_years()) test_level_description = { 3: ("on", "organisation files", ""), 2: ("on", "each package of data", ""), 1: ("for", "each activity", "in your data"), 0: ("for", "each transaction", "in your data") } links = { "organisation_page": url_for( 'organisations', organisation_code=organisation.organisation_code), "organisation_detail": url_for( 'organisation_publication_detail', organisation_code=organisation.organisation_code), "organisation_feedback": url_for( 'organisations_feedback', organisation_code=organisation.organisation_code) } if surveydata: links.update({ "organisation_survey_edit": url_for( 'organisation_survey_edit', organisation_code=organisation.organisation_code, workflow_name=surveydata_workflow) }) def agg_detail(agt): tmp = agt.as_dict() tmp["selected"] = agt.id == aggregation_type return tmp agg_type = [ agg_detail(agt) for agt in all_aggregation_types ] frequencies = { "less than quarterly": (0.5, """It looks like you publish less often than quarterly, so the maximum you can score for IATI data is 75 points. The total points for the relevant indicators have been adjusted accordingly"""), "quarterly": (0.9, """It looks like you publish quarterly and not monthly, so the maximum you can score for IATI data is 95 points. The total points for the relevant indicators have been adjusted accordingly.""") } freq_score = frequencies.get(organisation.frequency, (1.0, )) if organisation.frequency in frequencies: freq_alert = { "text": frequencies.get(organisation.frequency)[1] } else: freq_alert = None def annotate(res, zero): def annotate_test(t): tmp2 = dict(t) tmp2["results_pct_rounded"] = round(tmp2["results_pct"], 2) tmp2["results_num_rounded"] = round(tmp2["results_num"], 2) if "test_level" not in tmp2["test"]: # hopeless return tmp2 test_level = tmp2["test"]["test_level"] level = test_level_description[test_level] preposition, description, coda = level tmp2["level_preposition"] = preposition tmp2["level_description"] = description tmp2["level_coda"] = coda return tmp2 tmp = dict(res) tmp["is_activity"] = ( tmp["indicator"]["indicator_category_name"] == "activity") multiplier = {True: freq_score[0], False: 1}[tmp["is_activity"]] def points(): if not zero: return round((tmp["results_pct"] * multiplier / 2.0 + 50), 2) ind_id = res["indicator"]["id"] if surveydata: if (res["indicator"]["indicator_ordinal"] and surveydata[ind_id].PublishedFormat): return round( (surveydata[ind_id].OrganisationSurveyData.ordinal_value/3.0) * surveydata[ind_id].PublishedFormat.format_value * 50, 2) elif (surveydata[ind_id].PublishedStatus and surveydata[ind_id].PublishedFormat): return ( surveydata[ind_id].PublishedStatus.publishedstatus_value * surveydata[ind_id].PublishedFormat.format_value * 50) else: return 0 else: return "" tmp["points"] = points() if not zero: tmp["points_minus_50"] = tmp["points"] - 50 # it all fails if the other branch tries to use this value tmp["tests"] = map(annotate_test, res["tests"]) if zero: if surveydata: osd = surveydata[tmp["indicator"]["id"]].OrganisationSurveyData.as_dict() def status_class_and_text(): if tmp["indicator"]["indicator_ordinal"]: return (years[osd["ordinal_value"]]["class"], years[osd["ordinal_value"]]["text"]) else: return (published_status_by_id[osd["published_status"]]["publishedstatus_class"], published_status_by_id[osd["published_status"]]["title"]) def format_class_and_text(): if published_status_by_id[osd["published_status"]]["publishedstatus_class"] != 'important': return (publishedformats[osd["published_format"]]["format_class"], publishedformats[osd["published_format"]]["title"]) else: return ("", "") tmp["status_class"], tmp["status_text"] = status_class_and_text() tmp["format_class"], tmp["format_text"] = format_class_and_text() tmp["results_pct_rounded"] = round(tmp["results_pct"], 2) tmp["results_pct_halved_rounded"] = round(tmp["results_pct"]/2.0, 2) return tmp annotate_zero = lambda res : annotate(res, True) annotate_nonzero = lambda res : annotate(res, False) # testdata.results_pct|round(2) # testdata["results_num"]|round(2) # as far as line 296 def get_sd(data): return { "OrganisationSurveyData": data[0].as_dict(), "Workflow": data[3].as_dict(), } def jsonsurvey(surveydata): return dict(map(lambda x: (x[0], get_sd(x[1])), surveydata.items())) payload = { "organisation": organisation.as_dict(), "links": links, "agg_type": agg_type, "freq": freq_score, "freq_alert": freq_alert, "result": { "non_zero": map(annotate_nonzero, aggregate_results["non_zero"].values()), "zero":map(annotate_zero, aggregate_results["zero"].values()) }, "surveydata": jsonsurvey(surveydata) } json_data = json.dumps(payload, indent=2) return render_template("organisation_indicators.html", organisation=organisation, admin=usermanagement.check_perms('admin'), loggedinuser=current_user, json_data=json_data)