def indicators(self): """ Return all the dict data source indicator configurations that could be used by a report that uses the same case type/form as this DataSourceConfiguration. """ ret = [] for prop in self.data_source_properties.values(): if prop['type'] == 'meta': ret.append( make_form_meta_block_indicator(prop['source'], prop['column_id'])) elif prop['type'] == "question": ret.append( make_form_question_indicator(prop['source'], prop['column_id'])) elif prop['type'] == 'case_property' and prop[ 'source'] == 'computed/owner_name': ret.append(make_owner_name_indicator(prop['column_id'])) elif prop['type'] == 'case_property': ret.append( make_case_property_indicator(prop['source'], prop['column_id'])) ret.append({ "display_name": "Count", "type": "count", "column_id": "count" }) return ret
def indicators(self): """ Return all the dict data source indicator configurations that could be used by a report that uses the same case type/form as this DataSourceConfiguration. """ ret = [] for prop in self.data_source_properties.values(): if prop.type == 'meta': ret.append(make_form_meta_block_indicator( prop.source, prop.column_id )) elif prop.type == "question": ret.append(make_form_question_indicator( prop.source, prop.column_id )) elif prop.type == 'case_property' and prop.source == 'computed/owner_name': ret.append(make_owner_name_indicator(prop.column_id)) elif prop.type == 'case_property': ret.append(make_case_property_indicator( prop.source, prop.column_id )) ret.append({ "display_name": "Count", "type": "count", "column_id": "count" }) return ret
def _get_filter_and_agg_indicator(self): """ Return the data source indicator that will be used for filtering, or aggregating on this question (but not display) """ column_id = get_column_name(self._property.strip("/")) return make_form_question_indicator(self._question_source, column_id)
def get_indicator(self, aggregation, is_multiselect_chart_report=False): if aggregation in ("Sum", "Avg"): data_type = "decimal" elif aggregation in ("sum", "avg"): raise Exception("I think this should be Sum or Avg, where did you find this?...") else: data_type = None # use the default column_id = get_column_name(self._property.strip("/")) if data_type: column_id += ("_" + data_type) return make_form_question_indicator( self._question_source, column_id, data_type, root_doc=is_multiselect_chart_report )
def get_form_data_source(app, form): xform = XForm(form.source) form_name = form.default_name() questions = xform.get_questions([]) return DataSourceConfiguration( domain=app.domain, referenced_doc_type="XFormInstance", table_id=_clean_table_name(app.domain, form_name), display_name=form_name, configured_filter=make_form_data_source_filter(xform.data_node.tag_xmlns), configured_indicators=[ make_form_question_indicator(q, column_id=get_column_name(q["value"])) for q in questions ] + [make_form_meta_block_indicator(field) for field in FORM_METADATA_PROPERTIES], )
def _get_indicator(self, ui_aggregation, is_multiselect_chart_report=False): """ Return the report config snippet for the data source indicator for this form question column option """ assert ui_aggregation in UI_AGGREGATIONS, ( '"{}" is not an aggregation recognised by the Report Builder interface.'.format(ui_aggregation) ) if ui_aggregation in (UI_AGG_SUM, UI_AGG_AVERAGE): data_type = "decimal" else: data_type = None # use the default column_id = get_column_name(self._property.strip("/"), suffix=data_type) return make_form_question_indicator( self._question_source, column_id, data_type, root_doc=is_multiselect_chart_report )
def get_form_data_source(app, form): xform = XForm(form.source) form_name = form.default_name() questions = xform.get_questions([]) return DataSourceConfiguration( domain=app.domain, referenced_doc_type='XFormInstance', table_id=_clean_table_name(app.domain, form_name), display_name=form_name, configured_filter=make_form_data_source_filter(xform.data_node.tag_xmlns), configured_indicators=[ make_form_question_indicator(q, column_id=get_column_name(q['value'])) for q in questions ] + [ make_form_meta_block_indicator(field) for field in FORM_METADATA_PROPERTIES ], )