def findTime(self, item: TimeNode) -> TimeNode: # todo this probably takes up a lot of time for node in self.times.values(): if node.__eq__(item): return node n = self.times[item.getTimeID() + str(item.getWeekDay())] return n
def createTimeIntervals(self, startTime: str, endTime: str, interval: int): currTime = startTime '''create the time intervals''' while timeToInt(currTime) < timeToInt(endTime): """is < and not <- becuase this way we will not map anything past the endTime""" '''for every day of the week''' for i in range(0, 7): """create a timenode and add it to the list of timenodes""" currDateTime = datetime.strptime(currTime, "%H:%M") timeNode = TimeNode.TimeNode(currDateTime, i, interval) self.addTimeNode(timeNode) """the current hour and min""" hour = currTime[0:2] min = currTime[3:] """update the current time""" minInt = int(min) newMinInt = minInt + interval """if the minutes go over 60 go to the next hour""" if newMinInt >= 60: hourInt = int(hour) newHourInt = hourInt + 1 newHour = str(newHourInt) newMinInt = newMinInt % 60 newMin = str(newMinInt) else: newHour = hour newMin = str(newMinInt) """times need to be the proper length""" if newHour.__len__() < 2: newHour = "0" + newHour if newMin.__len__() < 2: newMin = "0" + newMin currTime = newHour + ":" + newMin
'''update the period counts of the od node''' vodnode.setAmCount(int(vamCount)) vodnode.setPmCount(int(vpmCount)) '''readout the "Times: "''' readOut = outputTextFile1.readline().strip() '''update the times of the od node''' vt = outputTextFile1.readline().strip() '''for all the timenodes listed''' while vt.__contains__("WeekDay"): '''get the weekday, time, and count''' weekday = int(vt[9:11]) vtime = vt[19:24] vcount = int(vt[32:]) '''create the TimeNode''' vdt = datetime.strptime(vtime, "%H:%M") vtimenode = TimeNode.TimeNode(vdt, weekday, 1) vtimenode.setCount(vcount) '''the dict to be used as the dict of paths for timenode''' paths = {} '''read the next line in the file''' nl = outputTextFile1.readline().strip() # changed the output of the hashtable to be correct if nl.__contains__("Paths"): nl = outputTextFile1.readline().strip() while nl.__contains__("PathID"): '''get the PathNode attributes''' countIndex = nl.index("Count:") path = nl[8:countIndex - 1]
vodnode.setInbound(True) else: vodnode.setInbound(False) '''readout the "Times: "''' readOut = inputfile17.readline().strip() '''update the times of the od node''' vt = inputfile17.readline().strip() '''for all the timenodes listed''' while vt.__contains__("WeekDay"): '''get the weekday, time, and count''' weekday = int(vt[9:11]) vtime = vt[19:24] vcount = int(vt[32:]) '''create the TimeNode''' vdt = datetime.strptime(vtime, "%H:%M") vtimenode = TimeNode.TimeNode(vdt, weekday, timeInterval) vtimenode.setCount(vcount) '''the dict to be used as the dict of paths for timenode''' paths = {} '''read the next line in the file''' nl = inputfile17.readline().strip() # changed the output of the hashtable to be correct if nl.__contains__("Paths"): nl = inputfile17.readline().strip() while nl.__contains__("PathID"): '''get the PathNode attributes''' countIndex = nl.index("Count:") path = nl[8:countIndex - 1]
def addTimeNode(self, timeNode: TimeNode): """add a TimeNode to the list of TimeNodes for this ODNode""" self.times[timeNode.getTimeID() + str(timeNode.getWeekDay())] = timeNode
'''find the correct od node''' n = ODNodes.find(tempNode, novaClose, dcClose) '''find the index of the correct od node''' getindex = ODNodes.getIndex(tempNode, novaClose, dcClose) '''add the trip id to the dict of trip id mapped to od node index''' tripIDandODNode[tripID] = getindex '''increment the correct od node''' n.inc() '''make note that this was mapped''' ODCounter += 1 '''if this trip was at a time that can be mapped''' '''every od node is created with all the times of interest''' tempTimeNode = TimeNode.TimeNode(startDateLocal, weekDay, timeInterval) if n.__contains__(tempTimeNode): '''find the correct timenode''' t = n.findTime(tempTimeNode) '''add the tripID to the list of trip ids''' t.addTripID(tripID) '''increment the correct time node''' t.inc() '''increment the global count of time maps''' TimeCounter += 1 '''incremement the correct period in od node'''
def getODNodesFromFile(fileName: str, timeInterval: int): """ :param fileName: the name of the file to get the info :return: a list of all the od nodes the file contained """ '''list of od nodes''' ODNodes = [] with open(fileName, 'r') as inputfile17: for line in inputfile17: line = line.strip() '''get the general attributes from the outputfile''' if line.__contains__("Total Trips"): totalTripCount = int(line[13:]) if line.__contains__("Int Trips"): interestTripCount = int(line[13:]) if line.__contains__("OD Maps"): odMapCount = int(line[13:]) if line.__contains__("Time Maps"): timeMapCount = int(line[13:]) if line.__contains__("Path Maps"): pathMapCount = int(line[13:]) '''if we are looking at a new od node''' while line.__contains__("Index"): '''get the origin of the od node''' voriginLine = inputfile17.readline().strip() if voriginLine == '': break vorigin = voriginLine[8:] vcommaIndex = vorigin.index(",") voriginLat = vorigin[:vcommaIndex] voriginLong = vorigin[vcommaIndex + 1:] voriginC = Coordinate.Coordinate(float(voriginLat), float(voriginLong)) '''get the destination of the od node''' vdestLine = inputfile17.readline().strip() vdestination = vdestLine[13:] vcommaIndex = vdestination.index(",") vdestlat = vdestination[:vcommaIndex] vdestlong = vdestination[vcommaIndex + 1:] vdestC = Coordinate.Coordinate(float(vdestlat), float(vdestlong)) '''readout the direction''' direction = inputfile17.readline() '''get the count of the od node''' vcountLine = inputfile17.readline().strip() vcount = vcountLine[7:] '''get the am count of the od node''' vamCountLine = inputfile17.readline().strip() vamCount = vamCountLine[9:] '''get the pm count of the od node''' vpmCountLine = inputfile17.readline().strip() vpmCount = vpmCountLine[9:] '''create the od node''' vodnode = ODNode.ODNode(voriginC, vdestC, int(vcount)) '''update the period counts of the od node''' vodnode.setAmCount(int(vamCount)) vodnode.setPmCount(int(vpmCount)) '''set the direction of the node''' if direction.__contains__("In-"): vodnode.setInbound(True) else: vodnode.setInbound(False) '''readout the "Times: "''' readOut = inputfile17.readline().strip() '''update the times of the od node''' vt = inputfile17.readline().strip() '''for all the timenodes listed''' while vt.__contains__("WeekDay"): '''get the weekday, time, and count''' weekday = int(vt[9:11]) vtime = vt[19:24] vcount = int(vt[32:]) '''create the TimeNode''' vdt = datetime.strptime(vtime, "%H:%M") vtimenode = TimeNode.TimeNode(vdt, weekday, timeInterval) vtimenode.setCount(vcount) '''the dict to be used as the dict of paths for timenode''' paths = {} '''read the next line in the file''' nl = inputfile17.readline().strip() # changed the output of the hashtable to be correct if nl.__contains__("Paths"): nl = inputfile17.readline().strip() while nl.__contains__("PathID"): '''get the PathNode attributes''' countIndex = nl.index("Count:") path = nl[8:countIndex - 1] count = nl[countIndex + 7:] '''create the pathNode''' pathNode = PathNode.PathNode(path) pathNode.setCount(int(count)) '''add the PathNode to the dict of PathNodes''' paths[path] = pathNode nl = inputfile17.readline().strip() vt = nl '''set the paths of the time node''' vtimenode.setPaths(paths) vt = nl '''add the time node to the list of times in od node''' vodnode.addTimeNode(vtimenode) if vt.__contains__("Index"): line = vt '''add the od node to the list of od nodes''' '''only if it is not an empty node''' e = Coordinate.Coordinate(0, 0) empty = ODNode.ODNode(e, e, 0) if vodnode.__eq__(empty) is False: ODNodes.append(vodnode) inputfile17.close() return ODNodes