ivoflipse / Pawlabeling

Tool for processing and analyzing pressure measurements
Other
18 stars 1 forks source link

SubjectsTable.get_new_id is broken #102

Closed ivoflipse closed 10 years ago

ivoflipse commented 10 years ago

If you delete a subject, after creating a new one. The next time you call get_new_id, it will count how many items there are in the table and use that number to create a new subject_id. However, because we just deleted one (or more) items, the count is no longer representative of the last element.

So to be safe, traverse the table and check the highest id and add one to that

ivoflipse commented 10 years ago

I now traverse the tree and check for the largest id and increment that with one. Seems to work.

def get_new_id(self):
    subjects = self.get_subjects()
    max_id = len(subjects)
    for subject in subjects:
        subject_id = int(subject["subject_id"].split("_")[-1])
        if subject_id > max_id:
            max_id = subject_id

    max_id += 1
    return "{}_{}".format(self.table_name, max_id)