'Delete predicates/subjects/values at random.'

def _DeleteRandom(self, subjects, fraction, change_test=True):

    if change_test:
        self.test_name = ('delete    %d%%' % fraction)
    subjects_to_delete = []
    for (i, info) in subjects.items():
        subject = info['name']
        predicates = info['attrs']
        number_predicates = len(predicates)
        do_it = (self.rand.randint(0, 100) <= fraction)
        which = self.rand.randint(0, 2)
        count_values = 0
        predicates_to_delete = []
        for (j, timestamp_info) in predicates.items():
            number_timestamps = len(timestamp_info)
            count_values += number_timestamps
            if do_it:
                if (which == 0):
                    if timestamp_info:
                        ts = timestamp_info[0]
                        data_store.DB.DeleteAttributes(subject, [(self.predicate_template % j)], start=ts, end=ts, token=self.token)
                        self.values -= 1
                        timestamp_info.pop(0)
                        self.Register()
                    else:
                        which = 1
                if (which == 1):
                    data_store.DB.DeleteAttributes(subject, [(self.predicate_template % j)], token=self.token)
                    self.values -= number_timestamps
                    self.predicates -= 1
                    predicates_to_delete.append(j)
                    self.Register()
        if (do_it and (which == 1)):
            for j in predicates_to_delete:
                del predicates[j]
        if (do_it and (which == 2)):
            data_store.DB.DeleteSubject(subject, token=self.token)
            self.predicates -= number_predicates
            self.values -= count_values
            self.subjects -= 1
            subjects_to_delete.append(i)
            self.Register()
    for i in subjects_to_delete:
        del subjects[i]
    data_store.DB.Flush()
