Exemplo n.º 1
0
 def setup_visitset(self):
     """
     When creating the first visit for a candidate, a complete set of visits is added based on a study/project visit list
     There are no parameters passed to this method since it will simply create a new 'empty'
     This method will:
         1-open studydata (the study visit list) and 'parse' the dict to a sorted list (dict cannot be sorted)
         2-create a temporary list of visit_labels that will serve as a key within the Candidate.visit_set dictionary
         3-instantiate individual visits based on the study visit list
     Usage:
         Called by Candidate.set_visit_date()
     """
     visit_list =[]
     visit_label_templist = []
     study_setup = dict()
     try:
         #1-open studydata
         study_setup = dict(DataManagement.read_studydata())
     except Exception as e:
         print str(e)  #TODO add error login (in case a study data file does not exist)
     for key, value in study_setup.iteritems():
         #2-parse into a sorted list
         visit_list.append(study_setup[key])
     visit_list = sorted(visit_list, key=lambda visit: visit.rank)
     #create a temporary list of visitlabels
     for each in visit_list:
         visit_label_templist.append(each.visitlabel)
     #3-instantiate individual visit based on each instance of VisitSetup()
     self.visitset = {}  #setup a dict to receive a set of Visit()
     count = 0
     #set values of :  uid, rank, visit_label, previous_visit, visit_window, visitmargin,
     for key in visit_list:
         mainkey = str(visit_label_templist[count])
         rank =key.rank
         visit_label = key.visitlabel
         previous_visit = key.previousvisit
         visit_window = key.visitwindow
         visit_margin = key.visitmargin
         visit_data = visit.Visit(rank, visit_label, previous_visit, visit_window, visit_margin,)
         self.visitset[mainkey] = visit_data
         count += 1
Exemplo n.º 2
0

def search_uid(db, value):
    return filter(lambda candidate: candidate['uid'] == value, db)
    

def print_object(something):
    #for dev only!
    #will print key, attributes, value in the console.
    #most likely will be an dict or a class instance.
    #so this is for the dict
    if type(something) is dict:
        for key, value in something.iteritems():
            c = something.get(key)
            for attr, value in c.__dict__.iteritems():
                print attr,": ", value
            print "\n"
    elif type(something) is list:
        for item in something:
            print item
    else:  #and this for the class instance
        for attr, value in something.__dict__.iteritems():
            print attr, value
    print "\n\n"


# self-test "module"  TODO remove before release
if __name__ == '__main__':
    import lib.datamanagement as DataManagement
    data=dict(DataManagement.read_studydata())
    print_object(data)