Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample display for classifying samples as requiring surgery (YES) or not (NO)
import ui, dialogs
source_data = [
['info1','info2','info3','info4'],
[0,1,1,0],
[1,1,1,0],
[0,0,0,0],
]
results = [ 'Data set 1' ]
# Have the first result be a bit of a label
# to keep source and result indexes aligned
def all_done(results):
print(results)
dialogs.alert('All data processed')
# Save to file or something
class SymptomSource:
def __init__(self, tableview, source_data, results):
self.tableview = tableview
self.source_data = source_data
self.results = results
self.index = 1
self.set_row_data()
self.no_surgery_button = ui.ButtonItem(
tint_color='black',
title='NO',
action=self.record_result,
)
self.yes_surgery_button = ui.ButtonItem(
tint_color='black',
title='YES',
action=self.record_result,
)
tableview.left_button_items = [
self.no_surgery_button]
tableview.right_button_items = [
self.yes_surgery_button]
def tableview_number_of_rows(self, tableview, section):
return len(self.row_data)
def tableview_cell_for_row(self, tableview, section, row):
cell = ui.TableViewCell()
cell.text_label.text = self.row_data[row]
return cell
def set_row_data(self):
row0 = self.source_data[0]
row = self.source_data[self.index]
self.row_data = [
row0[i]
for i in range(len(row0))
if row[i] == 1
]
def record_result(self, sender):
self.results.append(
1 if sender.title == 'YES'
else 0)
if self.index + 1 == len(self.source_data):
all_done(self.results)
else:
self.index += 1
self.set_row_data()
self.tableview.reload()
tv = ui.TableView(
background_color='black'
)
tv.data_source = SymptomSource(tv, source_data, results)
tv.present()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment