def complex_chain(stack, x_keys, y_keys, views, view_keys, orient, incl_tests, incl_sum): # Custom view methods... # ---SIG sigtest_props_l80_total = qp.ViewMapper().make_template('coltests') view_name = 't_p_80' options = {'level': 0.8, 'metric': 'props', 'test_total': True} sigtest_props_l80_total.add_method(view_name, kwargs=options) sigtest_means_l80_total = qp.ViewMapper().make_template('coltests') view_name = 't_m_80' options = {'level': 0.8, 'metric': 'means', 'test_total': True} sigtest_means_l80_total.add_method(view_name, kwargs=options) sig_views = [sigtest_props_l80_total, sigtest_means_l80_total] # ------------------------------------------------------------------------ stack.add_link(x=x_keys, y=y_keys, views=views) if incl_tests: for v in sig_views: stack.add_link(x=x_keys, y=y_keys, views=v) if incl_sum: stack.add_link(x=x_keys, y=y_keys, views=['counts_sum', 'c%_sum']) _chain = ChainManager(stack) _chain.get(data_key='x', filter_key='no_filter', x_keys=x_keys, y_keys=y_keys, views=view_keys, orient=orient) _chains = _chain # if isinstance(_chains, Chain): # single chain # _chains = [_chains] return _chains
def new_net_mapper(): freq = qp.QuantipyViews().frequency iters = dict(iterators=dict(rel_to=[None, 'y', 'x'], groups='Nets')) return qp.ViewMapper(template=dict(method=freq, kwargs=iters))
def complex_chain_manager(self, stack): weight = [None, p.WEIGHT_COMPLEX] for x, y in [(p.XKEYS_COMPLEX, p.YKEYS_COMPLEX), ('q5', '@'), ('@', 'q5')]: stack.add_link(x=x, y=y, views=p.VIEWS_COMPLEX, weights=weight) kwargs = dict(combine=False) mapper = self.net_mapper('No', [dict(No=[1, 2, 3])], 'Net: No', **kwargs) stack.add_link(x=p.XKEYS_COMPLEX[0], y=p.YKEYS_COMPLEX, views=mapper, weights=p.WEIGHT_COMPLEX) stack.add_link(x='q5', y='@', views=mapper, weights=p.WEIGHT_COMPLEX) stack.add_link(x='@', y='q5', views=mapper, weights=p.WEIGHT_COMPLEX) mapper = self.net_mapper('Yes', [dict(Yes=[4, 5, 97])], 'Net: Yes', **kwargs) stack.add_link(x=p.XKEYS_COMPLEX[0], y=p.YKEYS_COMPLEX, views=mapper, weights=p.WEIGHT_COMPLEX) stack.add_link(x='q5', y='@', views=mapper, weights=p.WEIGHT_COMPLEX) stack.add_link(x='@', y='q5', views=mapper, weights=p.WEIGHT_COMPLEX) logic = [ dict(N1=[1, 2], text={'en-GB': 'Waves 1 & 2 (NET)'}, expand='after'), dict(N2=[4, 5], text={'en-GB': 'Waves 4 & 5 (NET)'}, expand='after') ] kwargs = dict(combine=False, complete=True, expand='after') mapper = self.net_mapper('BLOCK', logic, 'Net: ', **kwargs) stack.add_link(x=p.XKEYS_COMPLEX[-1], y=p.YKEYS_COMPLEX, views=mapper, weights=p.WEIGHT_COMPLEX) mapper = self.new_net_mapper() kwargs = { 'calc_only': False, 'calc': { 'text': { u'en-GB': u'Net YES' }, 'Net agreement': ('Net: Yes', sub, 'Net: No') }, 'axis': 'x', 'logic': [{ 'text': { u'en-GB': 'Net: No' }, 'Net: No': [1, 2] }, { 'text': { u'en-GB': 'Net: Yes' }, 'Net: Yes': [4, 5] }] } mapper.add_method(name='NPS', kwargs=kwargs) kwargs = { 'calc_only': True, 'calc': { 'text': { u'en-GB': u'Net YES' }, 'Net agreement (only)': ('Net: Yes', sub, 'Net: No') }, 'axis': 'x', 'logic': [{ 'text': { u'en-GB': 'Net: No' }, 'Net: No': [1, 2] }, { 'text': { u'en-GB': 'Net: Yes' }, 'Net: Yes': [4, 5] }] } mapper.add_method(name='NPSonly', kwargs=kwargs) stack.add_link(x=p.XKEYS_COMPLEX[0], y=p.YKEYS_COMPLEX, views=mapper, weights=p.WEIGHT_COMPLEX) stack.add_link(x='q5', y='@', views=mapper, weights=p.WEIGHT_COMPLEX) stack.add_link(x='@', y='q5', views=mapper, weights=p.WEIGHT_COMPLEX) options = dict(stats=None, source=None, rescale=None, drop=False, exclude=None, axis='x', text='') stats = [ 'mean', 'stddev', 'median', 'var', 'varcoeff', 'sem', 'lower_q', 'upper_q' ] for stat in stats: options = { 'stats': stat, 'source': None, 'rescale': None, 'drop': False, 'exclude': None, 'axis': 'x', 'text': '' } mapper = qp.ViewMapper() mapper.make_template('descriptives') mapper.add_method('stat', kwargs=options) stack.add_link(x=p.XKEYS_COMPLEX, y=p.YKEYS_COMPLEX, views=mapper, weights=p.WEIGHT_COMPLEX) stack.add_link(x='q5', y='@', views=mapper, weights=p.WEIGHT_COMPLEX) stack.add_link(x='@', y='q5', views=mapper, weights=p.WEIGHT_COMPLEX) mapper = qp.ViewMapper().make_template('coltests') options = dict(level=0.8, metric='props', test_total=True, flag_bases=[30, 100]) mapper.add_method('test', kwargs=options) stack.add_link(x=p.XKEYS_COMPLEX, y=p.YKEYS_COMPLEX, views=mapper, weights=p.WEIGHT_COMPLEX) mapper = qp.ViewMapper().make_template('coltests') options = dict(level=0.8, metric='means', test_total=True, flag_bases=[30, 100]) mapper.add_method('test', kwargs=options) stack.add_link(x=p.XKEYS_COMPLEX, y=p.YKEYS_COMPLEX, views=mapper, weights=p.WEIGHT_COMPLEX) _complex = ChainManager(stack) _complex.get(data_key=DATA_KEY, filter_key=FILTER_KEY, x_keys=p.XKEYS_COMPLEX[:-1], y_keys=p.YKEYS_COMPLEX, views=p.VIEWS_COMPLEX_MAIN, orient='x', folder='Main') _complex.get(data_key=DATA_KEY, filter_key=FILTER_KEY, x_keys=p.XKEYS_COMPLEX[-1], y_keys=p.YKEYS_COMPLEX, views=p.VIEWS_COMPLEX_WAVE, orient='x', folder='Main') _complex.get(data_key=DATA_KEY, filter_key=FILTER_KEY, x_keys='q5', y_keys='@', views=p.VIEWS_COMPLEX_ARRAY, folder='arr_0') _complex.get(data_key=DATA_KEY, filter_key=FILTER_KEY, x_keys='@', y_keys='q5', views=p.VIEWS_COMPLEX_ARRAY, folder='arr_1') _complex.get(data_key=DATA_KEY, filter_key=FILTER_KEY, x_keys='q5', y_keys='@', views=p.VIEWS_COMPLEX_MEAN, folder='mean_0') _complex.get(data_key=DATA_KEY, filter_key=FILTER_KEY, x_keys='@', y_keys='q5', views=p.VIEWS_COMPLEX_MEAN, folder='mean_1') _complex.add(stack[DATA_KEY].data.loc[:, p.OPENS_COMPLEX], meta_from=DATA_KEY, name='Open Ends') _complex.paint_all(transform_tests='full') self.add_annotations(_complex) return _complex