|
|
|
|
@ -194,32 +194,32 @@ class StatSectionsView(StatBaseView): |
|
|
|
|
if self.request.is_ajax(): |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
pt = self.get_pivot_table() |
|
|
|
|
|
|
|
|
|
# change numpy.nan values to python's None (js null with json) |
|
|
|
|
# result = pt.where(pt.notnull(), None) |
|
|
|
|
result = pt.fillna(value=0) |
|
|
|
|
result_summary = result.sum().to_dict() |
|
|
|
|
context['columns'] = self.get_column_names() |
|
|
|
|
|
|
|
|
|
# if self.pt_columns != 'kind': |
|
|
|
|
# result.columns = list(map(lambda x: str(int(x)), result.columns.tolist())) |
|
|
|
|
|
|
|
|
|
data = list(map( |
|
|
|
|
# lambda x: {'date': pydate_to_js(x[0]), 'attrs': json.dumps(x[1:]).replace('[', '').replace(']', '')}, |
|
|
|
|
lambda x: json.dumps(list(x), cls=CustomJSEncoder), |
|
|
|
|
result.itertuples() |
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
data_summary = [] |
|
|
|
|
for key, val in result_summary.items(): |
|
|
|
|
data_summary.append({ |
|
|
|
|
'name': self.get_col_map()[key], |
|
|
|
|
'val': val |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
context['data'] = data |
|
|
|
|
context['data_summary'] = data_summary |
|
|
|
|
if self.qs: |
|
|
|
|
pt = self.get_pivot_table() |
|
|
|
|
|
|
|
|
|
# change numpy.nan values to python's None (js null with json) |
|
|
|
|
# result = pt.where(pt.notnull(), None) |
|
|
|
|
result = pt.fillna(value=0) |
|
|
|
|
result_summary = result.sum().to_dict() |
|
|
|
|
context['columns'] = self.get_column_names() |
|
|
|
|
|
|
|
|
|
# if self.pt_columns != 'kind': |
|
|
|
|
# result.columns = list(map(lambda x: str(int(x)), result.columns.tolist())) |
|
|
|
|
|
|
|
|
|
data = list(map( |
|
|
|
|
# lambda x: {'date': pydate_to_js(x[0]), 'attrs': json.dumps(x[1:]).replace('[', '').replace(']', '')}, |
|
|
|
|
lambda x: json.dumps(list(x), cls=CustomJSEncoder), |
|
|
|
|
result.itertuples() |
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
data_summary = [] |
|
|
|
|
for key, val in result_summary.items(): |
|
|
|
|
data_summary.append({ |
|
|
|
|
'name': self.get_col_map()[key], |
|
|
|
|
'val': val |
|
|
|
|
}) |
|
|
|
|
context['data'] = data |
|
|
|
|
context['data_summary'] = data_summary |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -257,6 +257,7 @@ class EventStatView(StatBaseView): |
|
|
|
|
return self.render_to_response(self.get_context_data(form=form)) |
|
|
|
|
|
|
|
|
|
def get_params_form(self): |
|
|
|
|
form_kwargs = {} |
|
|
|
|
country_ids = set() |
|
|
|
|
city_ids = set() |
|
|
|
|
theme_ids = set() |
|
|
|
|
@ -271,27 +272,29 @@ class EventStatView(StatBaseView): |
|
|
|
|
'exposition__tag', |
|
|
|
|
'conference__tag', |
|
|
|
|
] |
|
|
|
|
e_country_ids, c_country_ids, e_city_ids, c_city_ids, e_theme_ids, c_theme_ids, e_tag_ids, c_tag_ids = \ |
|
|
|
|
zip(*self.qs.values_list(*val_list)) |
|
|
|
|
country_ids.update(e_country_ids) |
|
|
|
|
country_ids.update(c_country_ids) |
|
|
|
|
city_ids.update(e_city_ids) |
|
|
|
|
city_ids.update(c_city_ids) |
|
|
|
|
theme_ids.update(e_theme_ids) |
|
|
|
|
theme_ids.update(e_theme_ids) |
|
|
|
|
tag_ids.update(e_tag_ids) |
|
|
|
|
tag_ids.update(c_tag_ids) |
|
|
|
|
for ids_set in [country_ids, city_ids, theme_ids, tag_ids]: |
|
|
|
|
if None in ids_set: |
|
|
|
|
ids_set.remove(None) |
|
|
|
|
|
|
|
|
|
form_kwargs = { |
|
|
|
|
'country_choices': Country.objects.language().filter(pk__in=country_ids).values_list('pk', 'name').order_by('name'), |
|
|
|
|
'city_choices': City.objects.language().filter(pk__in=city_ids).values_list('pk', 'name').order_by('name'), |
|
|
|
|
'theme_choices': Theme.objects.language().filter(pk__in=theme_ids).values_list('pk', 'name').order_by('name'), |
|
|
|
|
'tag_choices': Tag.objects.language().filter(pk__in=tag_ids).values_list('pk', 'name').order_by('name'), |
|
|
|
|
'data': self.request.POST |
|
|
|
|
} |
|
|
|
|
values_list = self.qs.values_list(*val_list) |
|
|
|
|
if values_list: |
|
|
|
|
e_country_ids, c_country_ids, e_city_ids, c_city_ids, e_theme_ids, c_theme_ids, e_tag_ids, c_tag_ids = \ |
|
|
|
|
zip(*values_list) |
|
|
|
|
country_ids.update(e_country_ids) |
|
|
|
|
country_ids.update(c_country_ids) |
|
|
|
|
city_ids.update(e_city_ids) |
|
|
|
|
city_ids.update(c_city_ids) |
|
|
|
|
theme_ids.update(e_theme_ids) |
|
|
|
|
theme_ids.update(e_theme_ids) |
|
|
|
|
tag_ids.update(e_tag_ids) |
|
|
|
|
tag_ids.update(c_tag_ids) |
|
|
|
|
for ids_set in [country_ids, city_ids, theme_ids, tag_ids]: |
|
|
|
|
if None in ids_set: |
|
|
|
|
ids_set.remove(None) |
|
|
|
|
|
|
|
|
|
form_kwargs = { |
|
|
|
|
'country_choices': Country.objects.language().filter(pk__in=country_ids).values_list('pk', 'name').order_by('name'), |
|
|
|
|
'city_choices': City.objects.language().filter(pk__in=city_ids).values_list('pk', 'name').order_by('name'), |
|
|
|
|
'theme_choices': Theme.objects.language().filter(pk__in=theme_ids).values_list('pk', 'name').order_by('name'), |
|
|
|
|
'tag_choices': Tag.objects.language().filter(pk__in=tag_ids).values_list('pk', 'name').order_by('name'), |
|
|
|
|
'data': self.request.POST |
|
|
|
|
} |
|
|
|
|
form = self.params_form_cls(**form_kwargs) |
|
|
|
|
return form |
|
|
|
|
|
|
|
|
|
|