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 get_output(self): file_str = self.read_variable("loaded_file").content start_read = 1 if self.read_variable("throw_away") else 0 headers = [x.lower() for x in split_line(file_str.split("\n")[start_read])] data_sample = [[x for x in split_line(line)] for line in file_str.split("\n")[start_read+1:start_read+4]] format_header = util.prettify_data(headers) dummy_frame = iris_objects.IrisDataframe(column_names=headers, column_types=headers, data=data_sample) return [ "Here are the headers I inferred from the first line. Do these look good?", {"type":"collection", "value":dummy_frame.generate_spreadsheet_data()} ]
def get_output(self): start_from = 1 if self.read_variable("throw_away") else 0 sample_data = split_line( self.read_variable("loaded_file").content.split("\n")[start_from]) return [ "What are the headers? Please enter a list of comma-separated values. I've provided a line of sample data below.", { "type": "data", "value": util.prettify_data(sample_data) } ]
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 get_output(self): file_str = self.read_variable("loaded_file").content start_read = 1 if self.read_variable("throw_away") else 0 headers = [ x.lower() for x in split_line(file_str.split("\n")[start_read]) ] format_header = util.prettify_data(headers) return [ "Here are the headers I inferred from the first line. Do these look good?", { "type": "data", "value": format_header } ]
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())