def next_state_base(self, text): self.write_variable("throw_away", False) file_str = self.read_variable("loaded_file").content success, headers = check_file_header(file_str) self.context['headers'] = headers format_header = util.prettify_data(headers) if not success or self.force_ask: state_machine = [] if self.force_ask: state_machine.append( sm.Assign( "throw_away", t.YesNo( "In that case, would you like to throw away the first line of data?", yes=True, no=False))) state_machine.append( sm.Print( ["Okay, how would you like to generate the header?"])) else: state_machine.append( sm.Print(["This file does not appear to have a header."])) state_machine.append( t.Select( options={ "Generate the values automatically": GenerateHeaders(), "Enter the headers manually": AskForHeaders(), "Use first line as header:": FirstLineHeader() })) return sm.DoAll(state_machine).when_done( self.get_when_done_state()) return FirstLineHeader().when_done(self.get_when_done_state())
def next_state_base(self, text): possible_headers = [x.strip() for x in split_line(text)] if len(possible_headers) == len(self.context['headers']): self.context['headers'] = [x.lower() for x in possible_headers] start_from = 1 if self.read_variable("throw_away") else 0 self.context["data"] = self.read_variable("loaded_file").content.split("\n")[start_from:] return True, sm.Print(["Great, thanks."]).when_done(self.get_when_done_state()) else: problem = sm.Print([ "I ran into a problem. You need to enter {} values.".format(len(self.context["headers"])) ]).when_done(self) return problem
def next_state_base(self, text): self.context["types"][self.index] = self.read_variable("category_select") return sm.DoAll([ sm.Print([ "Great, I've set {} to {}.".format(self.context["headers"][self.index], self.read_variable("category_select")), ]), CheckTypes(force_check=True) ]).when_done(self.get_when_done_state())
def next_state_base(self, text): if util.verify_response(text): self.write_variable("throw_away", True) self.context['data'] = self.read_variable( "loaded_file").content.split("\n")[1:] return sm.Print(["Great, thanks." ]).when_done(self.get_when_done_state()) return CheckHeader(force_ask=True).when_done( self.get_when_done_state())
def next_state_base(self, text): file_str = self.context['data'] types = rows_and_types(split_line(file_str[0])) if not self.force_check: self.context["types"] = types if self.force_check or util.verify_response(text): print(types) dummy_frame = iris_objects.IrisDataframe(column_names=self.context['headers'], column_types=["String" for _ in types], data=[types]) print_types = sm.Print([{"type":"collection_select_one", "value":dummy_frame.generate_spreadsheet_data()}]) #util.prettify_data(type_obj)}]) return sm.DoAll([print_types, ChangeIndex()]).when_done(self.get_when_done_state()) return None #True, Done().when_done(self.get_when_done_state())
def next_state_base(self, text): file_str = self.read_variable("loaded_file").content lines = file_str.split("\n") num_cols = len(split_line(lines[0])) headers = ["column{}".format(i) for i in range(0,num_cols)] self.context['headers'] = headers start_from = 1 if self.read_variable("throw_away") else 0 self.context['data'] = file_str.split("\n")[start_from:] format_header = util.prettify_data(headers) data_sample = [[x for x in split_line(line)] for line in self.context['data'][start_from+1:start_from+4]] dummy_frame = iris_objects.IrisDataframe(column_names=headers, column_types=headers, data=data_sample) return sm.Print([{"type":"collection", "value":dummy_frame.generate_spreadsheet_data()}]).when_done(self.get_when_done_state())
def next_state_base(self, text): file_str = self.read_variable("loaded_file").content lines = file_str.split("\n") num_cols = len(split_line(lines[0])) headers = ["column{}".format(i) for i in range(0, num_cols)] self.context['headers'] = headers start_from = 1 if self.read_variable("throw_away") else 0 self.context['data'] = file_str.split("\n")[start_from:] format_header = util.prettify_data(headers) return sm.Print([{ "type": "data", "value": format_header }]).when_done(self.get_when_done_state())
def next_state_base(self, text): success, index, column_names, column_types = self.lookup_text(text) if success and index in column_names: print_text = sm.Print([ "What type would you like to change {} to?".format(column_names[index]) + " It's currently been set to a {} value.".format(column_types[index]) ]) select_types = sm.Assign("category_select", t.Select(options={ "Number (e.g., 2 or 3.4)": "Number", "String (e.g., 'a line of text')": "String", "Categorical (e.g., 'large' or 'small')": "Categorical" })) set_index = SetIndex(index) return sm.DoAll([print_text, select_types, set_index]).when_done(self.get_when_done_state()) return None #True, Done().when_done(self.get_when_done_state())
def next_state_base(self, text): file_str = self.context['data'] types = rows_and_types(split_line(file_str[0])) if not self.force_check: self.context["types"] = types if self.force_check or util.verify_response(text): type_obj = { i: { "name": self.context["headers"][i], "type": self.context["types"][i], "example": split_line(self.context["data"][0])[i] } for i, _ in enumerate(self.context["headers"]) } print_types = sm.Print([{ "type": "data", "value": util.prettify_data(type_obj) }]) return sm.DoAll([print_types, ChangeIndex() ]).when_done(self.get_when_done_state()) return None #True, Done().when_done(self.get_when_done_state())