def get_Hao(seq_x: SequenceData, seq_y: SequenceData, k: int, result: Result, r: int = None) -> None:
        if k < 2:
            return
        ktuple_1 = seq_x.get_ktuple(k)
        total_1 = seq_x.get_total(k)
        markov_1 = seq_x.get_markov(k, k - 2)

        ktuple_2 = seq_y.get_ktuple(k)
        total_2 = seq_y.get_total(k)
        markov_2 = seq_y.get_markov(k, k - 2)
        res = Dissimilarity._get_Hao(ktuple_1, ktuple_2, total_1, total_2, markov_1, markov_2)
        key = 'Hao_k{}'.format(k)
        result.add(key, seq_x.id, seq_y.id, res)
    def get_D2S(seq_x: SequenceData, seq_y: SequenceData, k: int, result: Result, r_list: List[int]) -> None:
        for r in r_list:
            if k < r or k < 3:
                continue
            ktuple_1 = seq_x.get_ktuple(k)
            total_1 = seq_x.get_total(k)
            markov_1 = seq_x.get_markov(k, r)

            ktuple_2 = seq_y.get_ktuple(k)
            total_2 = seq_y.get_total(k)
            markov_2 = seq_y.get_markov(k, r)
            res = Dissimilarity._get_D2S(ktuple_1, ktuple_2, total_1, total_2, markov_1, markov_2)
            key = 'D2S_k{}_M{}'.format(k, r)
            result.add(key, seq_x.id, seq_y.id, res)
Exemple #3
0
    def __init__(self, parent, ID):
        wx.Panel.__init__(self, parent, ID)

        Registry.add("CONTACT", self)
        Result.addListener(self)
        
        self.grid = ContactGrid(self, -1)
        gridBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Contact List"), wx.HORIZONTAL)
        gridBox.Add(self.grid, 1, wx.GROW|wx.ALIGN_CENTER|wx.ALL, 3)

        self.physicalAddress = Address(self, "HOME_PHYSICAL", Colors.HOME)
        self.postalAddress = Address(self, "HOME_POSTAL", Colors.HOME)
        self.workPhysicalAddress = Address(self, "WORK_PHYSICAL", Colors.WORK)
        self.workPostalAdress = Address(self, "WORK_POSTAL", Colors.WORK)
        
        # register the widgets for later access
        self.addWidgets = {"HOME_PHYSICAL": self.physicalAddress,
                           "HOME_POSTAL": self.postalAddress,
                           "WORK_PHYSICAL": self.workPhysicalAddress,
                           "WORK_POSTAL": self.workPostalAdress}
                                    
        agrid = wx.GridSizer(1, 2, 3, 3)
        agrid.AddMany([(self.physicalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3),    
                       (self.workPhysicalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3),
                       (self.postalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3),
                       (self.workPostalAdress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)])

        #agrid.AddGrowableRow(0, 1)   
        #agrid.AddGrowableRow(1, 1) 
        #agrid.SetFlexibleDirection(wx.HORIZONTAL|wx.VERTICAL)

        # save
        saveBtn = wx.Button(self, wx.ID_SAVE)
        self.Bind(wx.EVT_BUTTON, self.__saveData, saveBtn)
        # new
        newBtn = wx.Button(self, wx.ID_NEW)
        self.Bind(wx.EVT_BUTTON, self.new, newBtn)
        
        btnBox = wx.BoxSizer(wx.HORIZONTAL)
        btnBox.Add(newBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3)
        btnBox.Add(saveBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(gridBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        sizer.Add(agrid, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        sizer.Add(btnBox, 0, wx.ALIGN_CENTER|wx.ALL, 3)

        self.SetSizer(sizer)
Exemple #4
0
 def deleteEntry(self, evt):
     """ delete selected entry"""
     
     from Dialogs.ConfirmationDialog import ConfirmationDialog
     
     i = self.normalResult.GetSelection()
     data = Result.getResult()[i]
     file_number = data["file_number"]
     
     msg = "Delete %(surname)s, %(first_names)s Folder %(file_number)d from database ?" % data
     
     dlg = ConfirmationDialog(self, msg=msg)
     if dlg.ShowModal() == wx.ID_OK:
         CONN.deleteEntry(file_number)
         self.__searchDB()
         Result.notify(self.normalResult.GetSelection())
Exemple #5
0
 def search(self, data):
     """search database """
     
     self.lastSearchData = data
     
     query = """
     select * from patient.patient where """
     
     filenoquery = "file_number=%(folderno)s" % data
     surnamequery = "surname ~* '%(surname)s'" % data
     firstnamequery = "first_names ~* '%(name)s'" % data
     bdatequery = "birth_date ~* '%(bdate)s'" % data
     
     post = """
     order by surname desc
     limit 50
     """ 
     
     qlist = []
     if data["folderno"]:
         qlist.append(filenoquery)
     if data["surname"]:
         qlist.append(surnamequery)
     if data["name"]:
         qlist.append(firstnamequery)
     if data["bdate"]:
         qlist.append(bdatequery)   
     
     if len(qlist) > 1:
         mq = " and ".join(qlist)
     elif len(qlist) != 0: 
         mq = qlist[0]
     else:
         BARWRITER.write("No Matches Found")
         return []
         
     
     q = query + mq + post
     
     cursor = self.conn.cursor()
     cursor.execute(q)
     
     # set the rusult 
     Result.setResult(cursor.dictfetchall())
     BARWRITER.write("Save Completed at %s" %  time.ctime())
Exemple #6
0
 def __init__(self,
              k_list: List[int],
              seq_file_list: List[str],
              dissimilirary_list: List[str],
              save_dir: str,
              markov_list: List[int] = None):
     self._k_list = k_list
     self._seq_list = [
         SequenceData(seq_file_list[i], i)
         for i in range(len(seq_file_list))
     ]
     self._dissimilarity = [
         self._DIC_FUNC[name] for name in dissimilirary_list
     ]
     self._markov_list = markov_list
     self._dissimilarity_names = dissimilirary_list
     self._result = Result(len(seq_file_list))
     self._save_dir = save_dir
Exemple #7
0
    def __init__(self, parent, ID):
        wx.Panel.__init__(self, parent, ID)

        Registry.add("VISITS", self)
        Result.addListener(self)
        
        self.visits = {}
        self.file_number = None
        self.selected = None
        
        # visit list
        self.visitListCtrl = wx.ListBox(self, -1, size=(100, -1))
        self.Bind(wx.EVT_LISTBOX, self.dateSelected, self.visitListCtrl)
        visitBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Visit List"), wx.HORIZONTAL)
        visitBox.Add(self.visitListCtrl, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        # note
        self.note = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
        # self.Bind(wx.EVT_CHAR, self.OnKeyDown, self.note)
        wx.EVT_CHAR(self.note, self.OnKeyDown)
        self.noteLabel = wx.StaticBox(self, -1, "Visit Note")
        noteBox = wx.StaticBoxSizer(self.noteLabel, wx.HORIZONTAL)
        noteBox.Add(self.note, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        topBox = wx.BoxSizer(wx.HORIZONTAL)
        topBox.Add(visitBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        topBox.Add(noteBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        # save
        saveBtn = wx.Button(self, wx.ID_SAVE)
        self.Bind(wx.EVT_BUTTON, self.__saveData, saveBtn)
        
        newBtn = wx.Button(self, wx.ID_NEW)
        self.Bind(wx.EVT_BUTTON, self.__new, newBtn)
        
        btnBox = wx.BoxSizer(wx.HORIZONTAL)
        btnBox.Add(newBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3)
        btnBox.Add(saveBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(topBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        sizer.Add(btnBox, 0, wx.ALIGN_CENTER|wx.ALL, 3)

        self.SetSizer(sizer)
Exemple #8
0
 def presentResult(self):
     """format and present the result"""
     
     res = Result.getResult()
     formatlist = []
     for d in res:
         formatlist.append("%(surname)s, %(first_names)s" % d)
         
     self.normalResult.Clear()
     self.normalResult.InsertItems(formatlist, 0)    
 
     if Result.currentIndex:
         self.normalResult.SetSelection(Result.currentIndex)
 def get_Ma(seq_x: SequenceData, seq_y: SequenceData, k: int, result: Result, r: int = None) -> None:
     ktuple_1 = seq_x.get_ktuple(k)
     ktuple_2 = seq_y.get_ktuple(k)
     res = Dissimilarity._get_Ma(ktuple_1, ktuple_2, seq_x.get_total(k), seq_y.get_total(k))
     key = 'Ma_k{}'.format(k)
     result.add(key, seq_x.id, seq_y.id, res)
Exemple #10
0
    def __init__(self, parent, ID):
        wx.Panel.__init__(self, parent, ID)

        Registry.add("BIO", self)
        Result.addListener(self)

        modefont = wx.Font(16, wx.NORMAL , wx.BOLD, wx.NORMAL, False)
        self.modeLabel = wx.StaticText(self, -1, editstr, size=(600, -1))
        self.modeLabel.SetFont(modefont)

        # folder number
        bigfont = wx.Font(22, wx.MODERN , wx.BOLD, wx.NORMAL, False)
        self.folderNumber = wx.TextCtrl(self, -1, "", size=(130, -1))
        self.folderNumber.SetBackgroundColour(Colors.LIGHTBLUE)
        self.folderNumber.SetFont(bigfont)
        folderBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Folder Number"), wx.HORIZONTAL)
        folderBox.Add(self.folderNumber, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        # name
        self.name = wx.TextCtrl(self, -1, "", size=(350, -1))
        self.name.SetFont(bigfont)
        self.name.SetBackgroundColour(Colors.PURPLE)
        nameBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "First Names"), wx.HORIZONTAL)
        nameBox.Add(self.name, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)

        # surname
        self.surname = wx.TextCtrl(self, -1, "", size=(250, -1))
        self.surname.SetFont(bigfont)
        self.surname.SetBackgroundColour(Colors.PURPLE)
        surnameBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Surname"), wx.HORIZONTAL)
        surnameBox.Add(self.surname, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)        

        # callname
        self.callname = wx.TextCtrl(self, -1, "", size=(120, -1))
        callnameBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Name"), wx.HORIZONTAL)
        callnameBox.Add(self.callname, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)

        # add the names to the top ass well, they are written in large font
        topBox = wx.BoxSizer(wx.HORIZONTAL)
        topBox.Add(folderBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        topBox.Add(nameBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        topBox.Add(surnameBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)

        # names
        # mainnameBox = wx.BoxSizer(wx.HORIZONTAL)
        # mainnameBox.Add(callnameBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        # mainnameBox.Add(nameBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)        
        # mainnameBox.Add(surnameBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
                
        # birthdate
        #self.birthdate = wx.DatePickerCtrl(self, size=(120,-1),
        #                                   style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        self.birthdate = wx.TextCtrl(self, -1, "", size=(120, -1))
        birthdayBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Birth Date"), wx.HORIZONTAL)
        birthdayBox.Add(self.birthdate, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
                
        # gender
        self.gender = wx.Choice(self, -1, choices=["Male", "Female", "Undefined"], size=(120, -1))
        genderBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Gender"), wx.HORIZONTAL)
        genderBox.Add(self.gender, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        # marital status
        self.marital_status = wx.Choice(self, -1, choices=["Single", "Married", "Divorced", "Widowed"], size=(120, -1))
        maritalBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Marital Status"), wx.HORIZONTAL)
        maritalBox.Add(self.marital_status, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        bgBox = wx.BoxSizer(wx.HORIZONTAL)
        bgBox.Add(birthdayBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        bgBox.Add(genderBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        bgBox.Add(maritalBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        
        # ID
        self.ID = wx.TextCtrl(self, -1, "", size=(200, -1))
        IDBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "National ID"), wx.HORIZONTAL)
        IDBox.Add(self.ID, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)        
        # nationality                              
        self.nationality = wx.TextCtrl(self, -1, "")
        nationalBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Nationality"), wx.HORIZONTAL)
        nationalBox.Add(self.nationality, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        # language                              
        self.language = wx.TextCtrl(self, -1, "", size=(200, -1))
        languageBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Language"), wx.HORIZONTAL)
        languageBox.Add(self.language, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        # race
        self.race = wx.TextCtrl(self, -1, "", size=(200, -1))
        raceBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Ethnicity"), wx.HORIZONTAL)
        raceBox.Add(self.race, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        # id
        allidBox = wx.BoxSizer(wx.HORIZONTAL)
        allidBox.Add(IDBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        allidBox.Add(nationalBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        allidBox.Add(languageBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        allidBox.Add(raceBox, 0, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        
        # occupation
        self.occupation = wx.TextCtrl(self, -1, "", size=(300, -1))
        occupationBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Occupation"), wx.HORIZONTAL)
        occupationBox.Add(self.occupation, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        # employer
        self.employer = wx.TextCtrl(self, -1, "", size=(300, -1))
        employerBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Employer"), wx.HORIZONTAL)
        employerBox.Add(self.employer, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        workBox = wx.BoxSizer(wx.HORIZONTAL)
        workBox.Add(occupationBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        workBox.Add(employerBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        # dependants
        self.dependants = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
        self.dependants.SetBackgroundColour(Colors.INFOCOL)        
        dependantBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Dependants, Only spouse and Children under 18"), wx.HORIZONTAL)
        dependantBox.Add(self.dependants, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        # note
        self.note = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
        self.note.SetBackgroundColour(Colors.INFOCOL)        
        noteBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Additional Notes"), wx.HORIZONTAL)
        noteBox.Add(self.note, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)

        depnoteBox = wx.BoxSizer(wx.HORIZONTAL)
        depnoteBox.Add(dependantBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        depnoteBox.Add(noteBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        
        # synopsis
        self.synopsis = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)        
        synopsisBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Synopsis"), wx.HORIZONTAL)
        synopsisBox.Add(self.synopsis, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)
        
        # save
        saveBtn = wx.Button(self, wx.ID_SAVE)
        self.Bind(wx.EVT_BUTTON, self.__saveData, saveBtn)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.modeLabel, 0, wx.ALIGN_LEFT|wx.ALL, 3)
        sizer.Add(topBox, 0, wx.ALIGN_LEFT|wx.ALL, 3)
        sizer.Add(callnameBox, 0, wx.ALIGN_LEFT|wx.ALL, 3)
        sizer.Add(bgBox, 0, wx.ALIGN_LEFT|wx.ALL, 3)
        sizer.Add(allidBox, 0, wx.ALIGN_LEFT|wx.ALL, 3)
        sizer.Add(workBox, 0, wx.ALIGN_LEFT|wx.ALL, 3)
        sizer.Add(depnoteBox, 2, wx.ALIGN_LEFT|wx.GROW|wx.ALL, 3)
        sizer.Add(synopsisBox, 1, wx.ALIGN_LEFT|wx.GROW|wx.ALL, 3)
        sizer.Add(saveBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3)

        self.SetSizer(sizer)
        
        self.widgetList = [
                           self.folderNumber,
                           self.surname,
                           self.name,
                           self.birthdate,
                           #self.gender,
                           self.ID,
                           self.nationality,
                           self.note,
                           self.callname,
                           self.language,
                           self.occupation,
                           self.synopsis,
                           self.dependants,
                           self.race,
                           self.employer
                           ]
Exemple #11
0
class Core:
    _DIC_FUNC = {
        'd2': Dissimilarity.get_D2,
        'Ch': Dissimilarity.get_Ch,
        'Eu': Dissimilarity.get_Eu,
        'Ma': Dissimilarity.get_Ma,
        'd2S': Dissimilarity.get_D2S,
        'd2Star': Dissimilarity.get_D2Star,
        'Hao': Dissimilarity.get_Hao
    }

    def __init__(self,
                 k_list: List[int],
                 seq_file_list: List[str],
                 dissimilirary_list: List[str],
                 save_dir: str,
                 markov_list: List[int] = None):
        self._k_list = k_list
        self._seq_list = [
            SequenceData(seq_file_list[i], i)
            for i in range(len(seq_file_list))
        ]
        self._dissimilarity = [
            self._DIC_FUNC[name] for name in dissimilirary_list
        ]
        self._markov_list = markov_list
        self._dissimilarity_names = dissimilirary_list
        self._result = Result(len(seq_file_list))
        self._save_dir = save_dir

    def n_to_n(self):
        names = [seq.name for seq in self._seq_list]
        for i in tqdm(range(len(self._seq_list) - 1)):  # type: int
            self.one_to_n(self._seq_list[i], self._seq_list[i + 1:])
            self._seq_list[i] = None
        self._result.save_to_file(self._save_dir, names)

    def one_to_n(self, one: SequenceData, others: List[SequenceData]):
        for seq in others:
            Core._one_to_one(one, seq, self._k_list, self._dissimilarity,
                             self._result, self._markov_list)

    @staticmethod
    def _one_to_one(seq_x: SequenceData, seq_y: SequenceData,
                    k_list: List[int], func_list: List[Callable],
                    result: Result, markov_list: List[int]):
        for k in k_list:
            [func(seq_x, seq_y, k, result, markov_list) for func in func_list]

    def _clear(self, k: int, r: int = None):
        if 'd2S' in self._dissimilarity_names or 'd2Star' in self._dissimilarity_names:
            if k in self._markov_list:
                return
        if 'Hao' in self._dissimilarity_names:
            k -= 3
        for seq in self._seq_list:
            seq.clear(k)

    @staticmethod
    def star(k_list: List[int],
             seq_dir: str,
             dissimilirary_list: List[str],
             save_dir: str,
             markov_list: List[int] = None):
        dirs = Core.recurrence_load(seq_dir)
        for dir_ in dirs:
            name = os.path.split(dir_)[-1]
            print('{} start.................'.format(name))
            seq_file_list = Core.get_file_path(dir_)
            save = os.path.join(save_dir, name)
            os.makedirs(save) if not os.path.exists(save) else None
            Core(k_list, seq_file_list, dissimilirary_list, save,
                 markov_list).n_to_n()

    @staticmethod
    def recurrence_load(dir_path: str):
        dirs = []

        def _rec_load(path: str):
            tmps = os.listdir(path)
            p = os.path.join(path, tmps[0])
            if os.path.isfile(p):
                dirs.append(path)
            elif os.path.isdir(p):
                [_rec_load(os.path.join(path, sub_path)) for sub_path in tmps]
            else:
                return

        _rec_load(dir_path)
        return dirs

    @staticmethod
    def get_file_path(dir_path: str) -> List[str]:
        tmps = os.listdir(dir_path)
        return [os.path.join(dir_path, sub_path) for sub_path in tmps]
Exemple #12
0
 def __resultSelected(self, evt):
     """user selected a result"""        
     
     Result.notify(evt.GetInt())