本文整理汇总了Python中corehq.apps.reports.sqlreport.DataFormatter类的典型用法代码示例。如果您正苦于以下问题:Python DataFormatter类的具体用法?Python DataFormatter怎么用?Python DataFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataFormatter类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rows
def rows(self):
data = self.model.data
if isinstance(self.model, (NombreData, TauxConsommationData)):
localizations = sorted(set(key[0] for key in data))
else:
localizations = sorted(set(key[1] for key in data))
rows = []
formatter = DataFormatter(DictDataFormat(self.model.columns, no_value=self.no_value))
if isinstance(self.data_source, (NombreData, TauxConsommationData)):
result = {}
ppss = set()
for k, v in data.iteritems():
ppss.add(k[-2])
if 'region_id' in self.data_source.config:
helper_tuple = (k[2], k[1], k[0])
else:
helper_tuple = (k[1], k[0])
result[helper_tuple] = v
if 'region_id' in self.data_source.config:
result_sum = {}
for localization in localizations:
for pps in ppss:
for group in self.groups:
if(group.code, localization) in result_sum:
r = result_sum[(group.code, localization)]
cols = self.data_source.sum_cols
for col in cols:
r[col] += result.get((group.code, pps, localization), {col: 0})[col]
else:
helper_dict = {}
for col in self.data_source.sum_cols:
helper_dict[col] = 0
helper_dict['district_name'] = localization
result_sum[(group.code, localization)] = result.get((group.code,
pps, localization),
helper_dict)
result = result_sum
data = dict(formatter.format(result, keys=self.model.keys, group_by=self.model.group_by))
else:
data = dict(formatter.format(self.model.data, keys=self.model.keys, group_by=self.model.group_by))
reversed_map = dict(zip(self.PRODUCT_NAMES.values(), self.PRODUCT_NAMES.keys()))
for localization in localizations:
row = [localization]
for group in self.groups:
if (group.code, localization) in data:
product = data[(group.code, localization)]
row.extend([product[p] for p in self.model.col_names])
elif (self._safe_get(reversed_map, group.code), localization) in data:
product = data[(reversed_map[group.code], localization)]
row.extend([product[p] for p in self.model.col_names])
else:
row.extend([self.no_value for p in self.model.col_names])
rows.append(row)
return rows
示例2: rows
def rows(self):
def cell_format(data):
percent = 0
if isinstance(data, dict):
percent = 1
return {
'sort_key': percent,
'html': "oui" if percent else "non"
}
formatter = DataFormatter(DictDataFormat(self.columns, no_value=self.no_value))
data = formatter.format(self.data, keys=self.keys, group_by=self.group_by)
selected_location = location_filter(self.request, location_filter_selected=True)
if selected_location:
locations = SQLLocation.objects.get(
location_id=selected_location
).get_descendants(include_self=True).filter(location_type__code='centre-de-sante').order_by('name')
else:
locations = SQLLocation.objects.filter(
domain=self.domain,
location_type__code='centre-de-sante',
is_archived=False
).order_by('name')
user_locations = users_locations()
for site in locations:
loc_data = data.get(site.location_id, {})
if site.location_id in user_locations:
yield [
site.name,
cell_format(loc_data.get('completude', 0)),
cell_format(loc_data.get('promptitude', 0)),
]
示例3: rows
def rows(self):
no_value = dict(sort_key=0L, html=0L)
model = self.model
formatter = DataFormatter(TableDataFormat(model.columns, no_value=no_value))
rows = list(formatter.format(model.data, keys=model.keys, group_by=model.group_by))
if not rows:
return []
assert len(rows) == 1
row = [row.get('sort_key') or 0L for row in rows[0]]
示例4: rows
def rows(self):
formatter = DataFormatter(TableDataFormat(self.columns, no_value=self.no_value))
rows = list(formatter.format(self.data, keys=self.keys, group_by=self.group_by))
#Months are displayed in chronological order
if 'month' in self.group_by:
from custom.intrahealth.reports import get_localized_months
return sorted(rows, key=lambda row: get_localized_months().index(row[0]))
return rows
示例5: data
def data(self):
try:
data = super(SqlIndicatorSet, self).data
except (TableNotFoundException, ColumnNotFoundException) as e:
logger.exception(e)
return {}
format = DictDataFormat(self.columns, no_value=self.no_value)
formatter = DataFormatter(format, row_filter=self.include_row)
return formatter.format(data, keys=self.keys, group_by=self.group_by)
示例6: get_row_data
def get_row_data(self, row):
if 'user_data' in row['_source'] and 'awc' in row['_source']['user_data']:
sql_data = OpmHealthStatusSqlData(DOMAIN, row['_id'], self.datespan)
if sql_data.data:
formatter = DataFormatter(DictDataFormat(sql_data.columns, no_value=format_percent(0, 0)))
data = dict(formatter.format(sql_data.data, keys=sql_data.keys, group_by=sql_data.group_by))
data[row['_id']].update({'awc': row['_source']['user_data']['awc']})
return HealthStatus(**data[row['_id']])
else:
model = HealthStatus()
model.awc = row['_source']['user_data']['awc']
return model
else:
raise InvalidRow
示例7: get_user_ids
def get_user_ids(self):
# make an empty copy of this to just get the ids out
header_sql_data = McSqlData(
[], # blank sections
self.domain,
self.datespan,
self.fixture_type,
self.fixture_item
)
user_formatter = DataFormatter(TableDataFormat([self.user_column], no_value=NO_VALUE))
results = list(user_formatter.format(header_sql_data.data,
keys=header_sql_data.keys,
group_by=header_sql_data.group_by))
return [r[0] for r in results]
示例8: get_data
def get_data(self, start=None, limit=None):
ret = self._provider.get_data(start, limit)
# A way to bypass these transforms should be implemented.
# We can format data more efficiently in custom code if necessary
formatter = DataFormatter(DictDataFormat(self.columns, no_value=None))
formatted_data = list(formatter.format(ret, group_by=self.group_by).values())
for report_column in self.top_level_db_columns:
report_column.format_data(formatted_data)
for computed_column in self.top_level_computed_columns:
for row in formatted_data:
row[computed_column.column_id] = computed_column.wrapped_expression(row)
return formatted_data
示例9: rows
def rows(self):
data = self.model.data
ppss = sorted(list(set(zip(*data.keys())[1]))) if data.keys() else []
rows = []
formatter = DataFormatter(DictDataFormat(self.model.columns, no_value=self.no_value))
data = dict(formatter.format(self.model.data, keys=self.model.keys, group_by=self.model.group_by))
reversed_map = dict(zip(self.PRODUCT_NAMES.values(), self.PRODUCT_NAMES.keys()))
for pps in ppss:
row = [pps]
for group in self.groups:
if (group, pps) in data:
product = data[(group, pps)]
row.extend([product[p] for p in self.model.col_names])
elif (self._safe_get(reversed_map, group), pps) in data:
product = data[(reversed_map[group], pps)]
row.extend([product[p] for p in self.model.col_names])
else:
row.extend([self.no_value for p in self.model.col_names])
rows.append(row)
return rows
示例10: get_report_context
def get_report_context(self, data_provider):
headers = DataTablesHeader(*[c.data_tables_column for c in data_provider.columns])
if self.needs_filters:
rows = []
charts = []
total_row = []
else:
formatter = DataFormatter(TableDataFormat(data_provider.columns, no_value=self.no_value))
rows = list(formatter.format(data_provider.data, keys=data_provider.keys, group_by=data_provider.group_by))
charts = list(self.get_chart(
rows,
data_provider.columns,
x_label=data_provider.chart_x_label,
y_label=data_provider.chart_y_label,
has_total_column=data_provider.has_total_column
))
total_row = list(calculate_total_row(rows))
if total_row:
total_row[0] = 'Total'
context = dict(
report_table=dict(
title=data_provider.title,
headers=headers,
rows=rows,
total_row=total_row,
default_rows=self.default_rows,
datatables=True
),
charts=charts,
chart_span=12
)
return context
示例11: records
def records(self):
formatter = DataFormatter(DictDataFormat(self.columns, no_value=self.no_value))
return OrderedDict(sorted(formatter.format(self.data, keys=self.keys, group_by=self.group_by).items()))
示例12: rows
def rows(self):
formatter = DataFormatter(TableDataFormat(self.data_provider.columns, no_value=self.data_provider.no_value))
return formatter.format(self.data_provider.data, keys=self.data_provider.keys, group_by=self.data_provider.group_by)
示例13: rows
def rows(self):
formatter = DataFormatter(
self.format_class(self.columns, self.report.get_users()))
raw_data = formatter.format(
self.data, keys=self.keys, group_by=self.group_by)
return transpose(self.columns, list(raw_data))