def resolve_consistency(self, data, seed):
	print data.varnames
        actList = []
	actListJoint = []

        data.sort([self.activityAttribs.hidName,
                   self.activityAttribs.pidName,
                   self.activityAttribs.scheduleidName])

        # Create Index Matrix
        self.create_indices(data)
        self.create_col_numbers(data._colnames)

	#if self.childDepProcessingType == 'Dummy':
	#    return data

        for hhldIndex in self.hhldIndicesOfPersons:
	    ti = time.time()
            firstPersonRec = hhldIndex[1]
            lastPersonRec = hhldIndex[2]

            persIndicesForActsForHhld = self.personIndicesOfActs[firstPersonRec:
                                                                     lastPersonRec,
                                                                 :]
	    #if hhldIndex[0] not in [8843,20008,20440,30985,48365,54850,60085,64006,68037,73093,77192,84903,84963]:
		# 1047
	    #	continue
            householdObject = Household(hhldIndex[0])

            for perIndex in persIndicesForActsForHhld:
                personObject = Person(perIndex[0], perIndex[1])
                schedulesForPerson = data.data[perIndex[2]:perIndex[3],:]
                activityList = self.return_activity_list_for_person(schedulesForPerson)
                personObject.add_episodes(activityList)
                workStatus, schoolStatus, childDependency = self.return_status_dependency(schedulesForPerson)
                personObject.add_status_dependency(workStatus, schoolStatus, 
                                                   childDependency)
                householdObject.add_person(personObject)

		
            #print 'household object created in - %.4f' %(time.time()-ti)
	    if self.specification.terminalEpisodesAllocation:
		householdObject.allocate_terminal_dependent_activities(seed)
	    elif self.childDepProcessingType == 'Allocation':
		householdObject.allocate_dependent_activities(seed)
	    elif self.childDepProcessingType == 'Resolution':
		householdObject.lineup_activities(seed)
	    elif self.childDepProcessingType == 'Fix Trip Purpose':
		householdObject.fix_trippurpose(seed)
	    elif self.childDepProcessingType == 'Extract Tour Attributes':
		householdObject.extract_tripattributes(seed)

		#raw_input('extract tour attributes')
	
		pass

	    reconciledSchedules = householdObject._collate_results()
            actList += reconciledSchedules
            #print 'created and reconciled in - %.4f' %(time.time()-ti)
	return DataArray(actList, self.colNames)
    def resolve_consistency(self, data, seed):
        print data.varnames
        actList = []
        actListJoint = []

        data.sort([self.activityAttribs.hidName,
                   self.activityAttribs.pidName,
                   self.activityAttribs.scheduleidName])

        # Create Index Matrix
        self.create_indices(data)
        self.create_col_numbers(data._colnames)

        #if self.childDepProcessingType == 'Dummy':
        #    return data

        for hhldIndex in self.hhldIndicesOfPersons:
            ti = time.time()
            firstPersonRec = hhldIndex[1]
            lastPersonRec = hhldIndex[2]

            persIndicesForActsForHhld = self.personIndicesOfActs[firstPersonRec:
                                                                     lastPersonRec,
                                                                 :]
            #if hhldIndex[0] not in [8843,20008,20440,30985,48365,54850,60085,64006,68037,73093,77192,84903,84963]:
                # 1047
            #   continue
            householdObject = Household(hhldIndex[0])

            for perIndex in persIndicesForActsForHhld:
                personObject = Person(perIndex[0], perIndex[1])
                schedulesForPerson = data.data[perIndex[2]:perIndex[3],:]
                activityList = self.return_activity_list_for_person(schedulesForPerson)
                personObject.add_episodes(activityList)
                workStatus, schoolStatus, childDependency = self.return_status_dependency(schedulesForPerson)
                personObject.add_status_dependency(workStatus, schoolStatus,
                                                   childDependency)
                householdObject.add_person(personObject)


            #print 'household object created in - %.4f' %(time.time()-ti)
            if self.specification.terminalEpisodesAllocation:
                householdObject.allocate_terminal_dependent_activities(seed)
            elif self.childDepProcessingType == 'Allocation':
                householdObject.allocate_dependent_activities(seed)
            elif self.childDepProcessingType == 'Resolution':
                householdObject.lineup_activities(seed)
            elif self.childDepProcessingType == 'Fix Trip Purpose':
                householdObject.fix_trippurpose(seed)
            elif self.childDepProcessingType == 'Extract Tour Attributes':
                householdObject.extract_tripattributes(seed)

                #raw_input('extract tour attributes')

                pass

            reconciledSchedules = householdObject._collate_results()
            actList += reconciledSchedules
            #print 'created and reconciled in - %.4f' %(time.time()-ti)
        return DataArray(actList, self.colNames)
Beispiel #3
0
def process_dependency(args):
    data = args[0]
    seed = args[1]
    activityAttribs = args[2]
    dailyStatusAttribs = args[3]
    dependencyAttribs = args[4]
    specification = args[5]

    t = time.time()
    data["actobjects"] = data.apply(lambda x: return_act(x, activityAttribs),
                                    axis=1)

    hschedulesGrouped = data.groupby(level=0, sort=False)
    pschedulesGrouped = data.groupby(level=[0, 1], sort=False)

    workStatus_df = pschedulesGrouped[dailyStatusAttribs.workStatusName].min()
    schoolStatus_df = pschedulesGrouped[
        dailyStatusAttribs.schoolStatusName].min()
    childDependency_df = pschedulesGrouped[
        dependencyAttribs.childDependencyName].min()

    #print workStatus_df.shape
    #print workStatus_df
    print "Size is %d and time taken to run the df apply - %.4f" % (
        data.shape[0], time.time() - t)

    t = time.time()
    actList = []
    for hid, hidSchedules in hschedulesGrouped:
        householdObject = Household(hid)
        for pid, pidSchedules in hidSchedules.groupby(level=1, axis=0):
            personObject = Person(hid, pid)

            activityList = list(pidSchedules["actobjects"].values)
            personObject.add_episodes(activityList)

            workStatus = workStatus_df[(hid, pid)]
            schoolStatus = schoolStatus_df[(hid, pid)]
            childDependency = childDependency_df[(hid, pid)]
            personObject.add_status_dependency(workStatus, schoolStatus,
                                               childDependency)
            householdObject.add_person(personObject)

        if specification.terminalEpisodesAllocation:
            householdObject.allocate_terminal_dependent_activities(seed)
        elif specification.childDepProcessingType == 'Allocation':
            householdObject.allocate_dependent_activities(seed)
        elif specification.childDepProcessingType == 'Resolution':
            householdObject.lineup_activities(seed)
        elif specification.childDepProcessingType == 'Fix Trip Purpose':
            householdObject.fix_trippurpose(seed)
        elif specification.childDepProcessingType == 'Extract Tour Attributes':
            householdObject.extract_tripattributes(seed)

        reconciledSchedules = householdObject._collate_results()
        actList += reconciledSchedules
    print "Time taken to loop through all schedules - %.4f" % (time.time() - t)
    return actList
def process_dependency(args):
    data = args[0]
    seed = args[1]
    activityAttribs = args[2]
    dailyStatusAttribs = args[3]
    dependencyAttribs = args[4]
    specification = args[5]    

    t = time.time()
    data["actobjects"] = data.apply(lambda x: return_act(x,  activityAttribs),  axis=1)
    
    hschedulesGrouped = data.groupby(level=0, sort=False)
    pschedulesGrouped = data.groupby(level=[0,1], sort=False)
    
    workStatus_df = pschedulesGrouped[dailyStatusAttribs.workStatusName].min()
    schoolStatus_df = pschedulesGrouped[dailyStatusAttribs.schoolStatusName].min()
    childDependency_df = pschedulesGrouped[dependencyAttribs.childDependencyName].min()
    
    #print workStatus_df.shape
    #print workStatus_df
    print "Size is %d and time taken to run the df apply - %.4f" %(data.shape[0], time.time()-t)

    t = time.time()
    actList = []
    for hid,  hidSchedules in hschedulesGrouped:
        householdObject = Household(hid)
        for pid,  pidSchedules in hidSchedules.groupby(level=1, axis=0):
            personObject = Person(hid, pid)                

            activityList = list(pidSchedules["actobjects"].values)
            personObject.add_episodes(activityList)
            
            workStatus = workStatus_df[(hid, pid)]
            schoolStatus = schoolStatus_df[(hid, pid)]
            childDependency = childDependency_df[(hid, pid)]
            personObject.add_status_dependency(workStatus, schoolStatus,
                                                    childDependency)
            householdObject.add_person(personObject)

        if specification.terminalEpisodesAllocation:
            householdObject.allocate_terminal_dependent_activities(seed)
        elif specification.childDepProcessingType == 'Allocation':
            householdObject.allocate_dependent_activities(seed)
        elif specification.childDepProcessingType == 'Resolution':
            householdObject.lineup_activities(seed)
        elif specification.childDepProcessingType == 'Fix Trip Purpose':
            householdObject.fix_trippurpose(seed)
        elif specification.childDepProcessingType == 'Extract Tour Attributes':
            householdObject.extract_tripattributes(seed)            

        reconciledSchedules = householdObject._collate_results()
        actList += reconciledSchedules
    print "Time taken to loop through all schedules - %.4f" %(time.time()-t)
    return actList