def reconcile_schedules(args): data = args[0] seed = args[1] activityAttribs = args[2] t = time.time() data["actobjects"] = data.apply(lambda x: return_act(x, activityAttribs), axis=1) pschedulesGrouped = data.groupby(level=[0,1], sort=False) 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,pid), pidSchedules in pschedulesGrouped: personObject = Person(hid, pid) activityList = list(pidSchedules["actobjects"].values) personObject.add_episodes(activityList) reconciledSchedules = personObject.reconcile_activity_schedules(seed) if not personObject._check_for_conflicts(): raise Exception, "THE SCHEDULES ARE STILL MESSED UP" actList += reconciledSchedules print "Time taken to loop through all schedules - %.4f" %(time.time()-t) return actList
def resolve_consistency(self, data, seed): actList = [] data.sort([ self.activityAttribs.hidName, self.activityAttribs.pidName, self.activityAttribs.scheduleidName ]) ti = time.time() # Create Index Matrix self.create_indices(data) self.create_col_numbers(data._colnames) #print data._colnames, data.varnames print 'Indices created in %.4f' % (time.time() - ti) for hhldIndex in self.hhldIndicesOfPersons: firstPersonRec = hhldIndex[1] lastPersonRec = hhldIndex[2] persIndicesForActsForHhld = self.personIndicesOfActs[ firstPersonRec:lastPersonRec, :] 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) if self.schedAdjType == "Arrival Adjustment": actualArrival, expectedArrival, tripDependentPerson = self.return_arrival_info( schedulesForPerson) personObject.add_arrival_status(actualArrival, expectedArrival, tripDependentPerson) elif self.schedAdjType == "Occupancy Adjustment": tripInd, tripStTime = self.return_trip_occupancy_info( schedulesForPerson) #print 'trip indicator, trip start time -- ', tripInd, tripStTime personObject.add_occupancy_status(tripInd, tripStTime) householdObject.wait_push_subsequent_activities( personObject) else: raise Exception, 'Invalid adjustment type ... ' if self.schedAdjType == "Arrival Adjustment": householdObject.adjust_schedules_given_arrival_info(seed) elif self.schedAdjType == "Occupancy Adjustment": #raw_input() pass #raw_input() reconciledSchedules = householdObject._collate_results() if not personObject._check_for_conflicts(): personObject.print_activity_list() print "THE SCHEDULES ARE STILL MESSED UP" raise Exception, "THE SCHEDULES ARE STILL MESSED UP" actList += reconciledSchedules print 'Finished running the component including index creation in %.4f' % ( time.time() - ti) return DataArray(actList, self.colNames)
def resolve_consistency(self, data, seed): actList = [] data.sort([self.activityAttribs.hidName, self.activityAttribs.pidName, self.activityAttribs.scheduleidName]) ti = time.time() # Create Index Matrix self.create_indices(data) print 'Indices created in %.4f' %(time.time()-ti) hidCol = data._colnames[self.activityAttribs.hidName] pidCol = data._colnames[self.activityAttribs.pidName] schidCol = data._colnames[self.activityAttribs.scheduleidName] actTypeCol = data._colnames[self.activityAttribs.activitytypeName] locidCol = data._colnames[self.activityAttribs.locationidName] sttimeCol = data._colnames[self.activityAttribs.starttimeName] endtimeCol = data._colnames[self.activityAttribs.endtimeName] durCol = data._colnames[self.activityAttribs.durationName] colNames = [self.activityAttribs.hidName, self.activityAttribs.pidName, self.activityAttribs.scheduleidName, self.activityAttribs.activitytypeName, self.activityAttribs.starttimeName, self.activityAttribs.endtimeName, self.activityAttribs.locationidName, self.activityAttribs.durationName, self.activityAttribs.dependentPersonName, self.activityAttribs.tripCountName] row = 0 for perIndex in self.indices: schedulesForPerson = data.data[perIndex[2]:perIndex[3],:] activityList = [] for sched in schedulesForPerson: hid = sched[hidCol] pid = sched[pidCol] scheduleid = sched[schidCol] activitytype = sched[actTypeCol] locationid = sched[locidCol] starttime = sched[sttimeCol] endtime = sched[endtimeCol] duration = sched[durCol] actepisode = ActivityEpisode(hid, pid, scheduleid, activitytype, locationid, starttime, endtime, duration) activityList.append(actepisode) personObject = Person(perIndex[0], perIndex[1]) personObject.add_episodes(activityList) personObject.reconcile_activity_schedules(seed) reconciledSchedules = personObject._collate_results_aslist() if not personObject._check_for_conflicts(): raise Exception, "THE SCHEDULES ARE STILL MESSED UP" actList += reconciledSchedules return DataArray(actList, colNames)
def resolve_consistency(self, data, seed): actList = [] data.sort([self.activityAttribs.hidName, self.activityAttribs.pidName, self.activityAttribs.scheduleidName]) ti = time.time() # Create Index Matrix self.create_indices(data) print 'Indices created in %.4f' %(time.time()-ti) hidCol = data._colnames[self.activityAttribs.hidName] pidCol = data._colnames[self.activityAttribs.pidName] schidCol = data._colnames[self.activityAttribs.scheduleidName] actTypeCol = data._colnames[self.activityAttribs.activitytypeName] locidCol = data._colnames[self.activityAttribs.locationidName] sttimeCol = data._colnames[self.activityAttribs.starttimeName] endtimeCol = data._colnames[self.activityAttribs.endtimeName] durCol = data._colnames[self.activityAttribs.durationName] colNames = [self.activityAttribs.hidName, self.activityAttribs.pidName, self.activityAttribs.scheduleidName, self.activityAttribs.activitytypeName, self.activityAttribs.starttimeName, self.activityAttribs.endtimeName, self.activityAttribs.locationidName, self.activityAttribs.durationName, self.activityAttribs.dependentPersonName, self.activityAttribs.tripCountName] row = 0 for perIndex in self.indices: schedulesForPerson = data.data[perIndex[2]:perIndex[3],:] activityList = [] for sched in schedulesForPerson: hid = sched[hidCol] pid = sched[pidCol] scheduleid = sched[schidCol] activitytype = sched[actTypeCol] locationid = sched[locidCol] starttime = sched[sttimeCol] endtime = sched[endtimeCol] duration = sched[durCol] actepisode = ActivityEpisode(hid, pid, scheduleid, activitytype, locationid, starttime, endtime, duration) activityList.append(actepisode) personObject = Person(perIndex[0], perIndex[1]) personObject.add_episodes(activityList) personObject.reconcile_activity_schedules(seed) reconciledSchedules = personObject._collate_results_aslist() if not personObject._check_for_conflicts(): raise Exception, "THE SCHEDULES ARE STILL MESSED UP" actList += reconciledSchedules return DataArray(actList, colNames)
def resolve_consistency(self, data, seed): actList = [] data.sort([self.activityAttribs.hidName, self.activityAttribs.pidName, self.activityAttribs.scheduleidName]) ti = time.time() # Create Index Matrix self.create_indices(data) self.create_col_numbers(data._colnames) # print data._colnames, data.varnames print 'Indices created in %.4f' % (time.time() - ti) for hhldIndex in self.hhldIndicesOfPersons: firstPersonRec = hhldIndex[1] lastPersonRec = hhldIndex[2] persIndicesForActsForHhld = self.personIndicesOfActs[firstPersonRec: lastPersonRec, :] 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) if self.schedAdjType == "Arrival Adjustment": actualArrival, expectedArrival, tripDependentPerson = self.return_arrival_info( schedulesForPerson) personObject.add_arrival_status( actualArrival, expectedArrival, tripDependentPerson) elif self.schedAdjType == "Occupancy Adjustment": tripInd, tripStTime = self.return_trip_occupancy_info( schedulesForPerson) # print 'trip indicator, trip start time -- ', tripInd, # tripStTime personObject.add_occupancy_status(tripInd, tripStTime) householdObject.wait_push_subsequent_activities( personObject) else: raise Exception, 'Invalid adjustment type ... ' if self.schedAdjType == "Arrival Adjustment": householdObject.adjust_schedules_given_arrival_info(seed) elif self.schedAdjType == "Occupancy Adjustment": # raw_input() pass # raw_input() reconciledSchedules = householdObject._collate_results() if not personObject._check_for_conflicts(): personObject.print_activity_list() print "THE SCHEDULES ARE STILL MESSED UP" raise Exception, "THE SCHEDULES ARE STILL MESSED UP" actList += reconciledSchedules print 'Finished running the component including index creation in %.4f' % (time.time() - ti) return DataArray(actList, self.colNames)