def getPValue(self, field):
     if (field not in self.fields):
         print(field)
         raise DatabaseError.EntryWithUnknownFields
     index_field = self.fields.index(field)
     if self.ttest[index_field] is 0:
         raise DatabaseError.CannotComputeTTestOnField(field)
     groups = ({self.groups[0]: [], self.groups[1]: []})
     pvalue = 0
     entry_number = 0
     for entry in self.entries:
         if entry_number + 1 not in self.rejected_entries:
             if self.getFieldTypeFromField(field) == "List":
                 groups[entry["Group"]].append(
                     self.getLimitedValuesFromField(field).index(
                         entry[field]))
             elif self.getFieldTypeFromField(field) == "Number":
                 groups[entry["Group"]].append(int(float(entry[field])))
         entry_number = entry_number + 1
     if self.getFieldTypeFromField(field) == "List":
         obs = [
             groups[self.groups[0]].count(0),
             groups[self.groups[0]].count(1)
         ]
         obs2 = [
             groups[self.groups[1]].count(0),
             groups[self.groups[1]].count(1)
         ]
         _, pvalue = stats.chisquare(obs, obs2)
     elif self.getFieldTypeFromField(field) == "Number":
         _, pvalue = stats.ttest_ind(groups[self.groups[0]],
                                     groups[self.groups[1]],
                                     equal_var=False)
     return pvalue
 def destroy(self):
     fullpath = self.folder + "/" + self.file_name
     if (not os.path.exists(fullpath)):
         raise DatabaseError.FileNotExistError(fullpath)
     os.remove(fullpath)
     fullpath = self.folder + "/" + self.file_name.replace('db', 'csv')
     os.remove(fullpath)
 def addField(self, field, ttest, field_type, limited_values=''):
     if (field == ""):
         raise DatabaseError.EmptyFieldError()
     self.fields.append(field)
     self.ttest.append(int(ttest))
     self.field_types.append(field_type)
     self.limited_values.append(limited_values)
     self.order.append(field)
 def __check_writing_path__(self, fullpath):
     if (self.file_name == ""):
         raise DatabaseError.EmptyFileNameError()
 def __check_reading_path__(self, fullpath):
     if (self.file_name == ""):
         raise DatabaseError.EmptyFileNameError()
     if (not os.path.exists(fullpath)):
         raise DatabaseError.FileNotExistError(fullpath)
 def getEntryId(self, index):
     if index > len(self.entries):
         raise DatabaseError.EntryOutOfRange(index)
     return self.entries[index]["SubjectID"]
 def getEntryGroup(self, index):
     if index > len(self.entries):
         raise DatabaseError.EntryOutOfRange(index)
     return self.entries[index]["Group"]