def test_async_calc(conjoint_dsc, merge): from time import sleep class RunState(object): def __init__(self): self.is_done = True self.messages = '' run_state = RunState() consAttr = get_ds_by_name('Consumers', conjoint_dsc) odflLike = get_ds_by_name('Odour-flavor', conjoint_dsc) # consistencyLike = get_ds_by_name('Consistency', conjoint_dsc) # overallLike = get_ds_by_name('Overall', conjoint_dsc) designVar = get_ds_by_name('Tine yogurt design', conjoint_dsc) selected_structure = 1 selected_consAttr = ['Sex'] selected_designVar = ['Flavour', 'Sugarlevel'] cm = ConjointMachine(run_state) cm.schedule_calculation( selected_structure, consAttr, selected_consAttr, designVar, selected_designVar, odflLike, merge) while(not run_state.is_done): print("Waiting for result") sleep(1) sleep(1) res = cm.get_result() print(run_state.messages) print(res.keys()) assert True
def conj_res(): import pickle # Filename for result cache file cache_fn = 'conj_cached.pkl' try: fp = open(cache_fn, 'r') print("Read result data from: {0}.".format(cache_fn)) res = pickle.load(fp) fp.close() except IOError: print("Cache file ({0}) not found".format(cache_fn)) from conjoint_machine import ConjointMachine dsc = conjoint_dsc() consAttr = get_ds_by_name('Consumers', dsc) odflLike = get_ds_by_name('Odour-flavor', dsc) consistencyLike = get_ds_by_name('Consistency', dsc) overallLike = get_ds_by_name('Overall', dsc) designVar = get_ds_by_name('Tine yogurt design', dsc) selected_structure = 2 selected_consAttr = ['Sex'] selected_designVar = ['Flavour', 'Sugarlevel'] consLiking = odflLike cm = ConjointMachine() res = cm.synchronous_calculation(designVar, selected_designVar, consLiking, selected_structure, consAttr, selected_consAttr) with open(cache_fn, 'w') as fp: pickle.dump(res, fp) return res
def test_model(conjoint_dsc): design = get_ds_by_name('Tine yogurt design', conjoint_dsc) liking = get_ds_by_name('Odour-flavor', conjoint_dsc) consumers = get_ds_by_name('Consumers', conjoint_dsc) cj = Conjoint(design_set=design, cons_liking=liking, consumer_attr_set=consumers) cj.chosen_design_vars = ['Flavour', 'Sugarlevel'] cj.chosen_consumer_attr_vars = ['Sex'] # cj.print_traits() # cj_res = cj.res # print(cj_res) assert True
def test_completeness(conjoint_dsc): e_attr = get_ds_by_name('Estland consumers', conjoint_dsc) e_liking = get_ds_by_name('Estland liking data', conjoint_dsc) design = get_ds_by_name('Barley bread design', conjoint_dsc) selected_structure = 1 # [u'Sex', u'Age', u'WB', u'BB', u'Edu', u'Health'] selected_consAttr = ['Sex', 'Age', 'Edu'] # [u'Barley', u'Salt'] selected_designVar = ['Barley', 'Salt'] cm = ConjointMachine(start_r=False) cm._prepare_data( selected_structure, e_attr, selected_consAttr, design, selected_designVar, e_liking, False)
def test_all_struct(conjoint_dsc, structure): consAttr = get_ds_by_name('Consumers', conjoint_dsc) odflLike = get_ds_by_name('Odour-flavor', conjoint_dsc) # consistencyLike = get_ds_by_name('Consistency', conjoint_dsc) # overallLike = get_ds_by_name('Overall', conjoint_dsc) designVar = get_ds_by_name('Tine yogurt design', conjoint_dsc) selected_structure = structure selected_consAttr = ['Sex'] selected_designVar = ['Flavour', 'Sugarlevel'] cm = ConjointMachine() res = cm.synchronous_calculation( selected_structure, consAttr, selected_consAttr, designVar, selected_designVar, odflLike, True) print(res.keys())
def test_category_strings(conjoint_dsc): e_attr = get_ds_by_name('Estland consumers', conjoint_dsc) e_liking = get_ds_by_name('Estland liking data', conjoint_dsc) design = get_ds_by_name('Barley bread design', conjoint_dsc) selected_structure = 1 selected_consAttr = ['Sex', 'Age'] # [u'Barley', u'Salt'] selected_designVar = ['Barley', 'Salt'] cm = ConjointMachine() res = cm.synchronous_calculation( selected_structure, e_attr, selected_consAttr, design, selected_designVar, e_liking, True) print(res['lsmeansTable']['rowNames']) print(res['lsmeansTable']['colNames'])
), # _traitsui.Item('controller.model_struct', style='simple', label='Model'), label='Select data set', show_border=True, ) conjoint_plugin_view = make_plugin_view('Conjoint', conjoint_nodes, selection_view, conjoint_view) if __name__ == '__main__': print("Conjoint GUI test start") from tests.conftest import conjoint_dsc from dataset_container import get_ds_by_name one_branch = False dsc = conjoint_dsc() if one_branch: d = get_ds_by_name('Tine yogurt design', dsc) l = get_ds_by_name('Odour-flavor', dsc) c = get_ds_by_name('Consumers', dsc) cj = Conjoint(design=d, liking=l, consumers=c) cjc = ConjointController(cj) test = TestOneNode(one_model=cjc) test.configure_traits(view=dummy_view(conjoint_nodes)) else: conjoint = CalcContainer(dsc=conjoint_dsc()) cpc = ConjointPluginController(conjoint) cpc.configure_traits(view=conjoint_plugin_view)
if not self.cm.run_state: self.cm.run_state = self.ccs model = { 'Struct 1': 1, 'Struct 2': 2, 'Struct 3': 3 }[self.model_struct] self.cm.schedule_calculation(self.design, sorted(self.design_vars), self.liking, model, self.consumers, sorted(self.consumers_vars)) self.ccs.edit_traits(kind='livemodal') return self.cm.get_result() if __name__ == '__main__': print("Conjoint start") from tests.conftest import conjoint_dsc from dataset_container import get_ds_by_name conjoint_dsc = conjoint_dsc() design = get_ds_by_name('Tine yogurt design', conjoint_dsc) liking = get_ds_by_name('Odour-flavor', conjoint_dsc) consumers = get_ds_by_name('Consumers', conjoint_dsc) cj = Conjoint(design=design, liking=liking, consumers=consumers) cj.design_vars = ['Flavour', 'Sugarlevel'] cj.consumers_vars = ['Sex'] cj.print_traits() ## cj_res = cj.res ## print(cj_res.keys())
# ascii_name = name.encode('ascii', 'ignore') # return ascii_name.translate(None, throw_chrs) return name.encode('utf-8').decode('ascii', 'ignore') if __name__ == '__main__': print("Hello World") logging.basicConfig(level=logging.DEBUG) logger.info('Start interactive') from dataset_container import get_ds_by_name from tests.conftest import conjoint_dsc cm = ConjointMachine(start_r=True) selected_structure = 1 dsc = conjoint_dsc() consAttr = get_ds_by_name('Consumers', dsc) odflLike = get_ds_by_name('Odour-flavor', dsc) consistencyLike = get_ds_by_name('Consistency', dsc) overallLike = get_ds_by_name('Overall', dsc) designVar = get_ds_by_name('Tine yogurt design', dsc) selected_consAttr = ['Sex'] selected_designVar = ['Flavour', 'Sugarlevel'] empty = DataSet() # res = cm.synchronous_calculation(designVar, selected_designVar, odflLike) res = cm.synchronous_calculation(designVar, selected_designVar, odflLike, selected_structure, empty, []) res.print_traits() print(res.residualsTable.mat) # print(res.residIndTable.mat)