当前位置: 首页>>代码示例>>Python>>正文


Python util.Reader类代码示例

本文整理汇总了Python中util.Reader的典型用法代码示例。如果您正苦于以下问题:Python Reader类的具体用法?Python Reader怎么用?Python Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Reader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exec

    def exec(self,command):
        if not self.__connection.isAuthenticationComplete():
            print "Connection not established"
            return

        if self.__session == None:
          self.__session = self.__connection.openSession()
        sess = self.__session

        if type(command) is type([]): # if command is a list make it a string
            command = " ".join(command)

        # make environment variables to string and assemble command
        environment = " ".join(["=".join(i) for i in self.__env])
        command = "export " + environment + " && " + command

        sess.execCommand(command) # execute command
        self.__outputwriter = DataOutputStream(sess.getStdin())

        # start a new thread for the input stream of the process and set the
        # Reader
        self.__instr = StreamGobbler(sess.getStdout())
        self.__inputreader = Reader(BufferedReader(InputStreamReader(self.__instr)))

        # start a new thread for error stream of the process and set the
        # Reader
        self.__errstr = StreamGobbler(sess.getStderr())
        self.__errorreader = Reader(BufferedReader(InputStreamReader(self.__errstr)))
开发者ID:gidiko,项目名称:gridapp,代码行数:28,代码来源:ssh.py

示例2: getPiePieces

def getPiePieces():
    """Classifies the relative time difference into pieces (intervals) used for drawing the pie chart."""
    taxis = reader.readAnalysisInfo()
    pieces = [0, 0, 0, 0, 0, 0]
    for taxi in taxis:
        try:
            diff = getTimeDiff(taxi.getSteps())
        except TypeError as e:
            print("Error by taxi %s : %s" % (taxi.id, e.message))

        # classify the relative time difference
        #<10%', '10%-30%', '30%-50%', '50%-70%', '70%-90%', '>90%
        if diff < 10:
            pieces[0] += 1
        elif diff < 30:
            pieces[1] += 1
        elif diff < 50:
            pieces[2] += 1
        elif diff < 70:
            pieces[3] += 1
        elif diff < 90:
            pieces[4] += 1
        else:
            pieces[5] += 1
    print(pieces)
    print(sum(pieces))
    return pieces
开发者ID:702nADOS,项目名称:sumo,代码行数:27,代码来源:Traveltime.py

示例3: getBars

def getBars():
    """Classifies the time difference in single bars."""
    taxis = reader.readAnalysisInfo(WEE)
    barsDict = {}
    barsDictSim = {}
    stdDev = []
    mw = []
    for taxi in taxis:
        if len(taxi.getSteps()) < 1:
            continue
        try:
            # diff=getTimeDiff(taxi.getSteps(),False)
            diffSim, fcd, sim, no = getTimeDiff(taxi.getSteps())

            # anna
            if diffSim > 150:
                print(diffSim, " ", taxi.id, " ", no, " ", fcd, " ", sim)

            # standard deviation
            stdDev.append((diffSim - 9.46) * (diffSim - 9.46))
            mw.append(diffSim)
            # classify the absolute time difference
            # barsDict[(diff/10)*10]=barsDict.setdefault((diff/10)*10,0)+1
            barsDictSim[
                (diffSim / 10) * 10] = barsDictSim.setdefault((diffSim / 10) * 10, 0) + 1
        except TypeError as e:
            tueNichts = True
            # print "Error by taxi %s : %s"  %(taxi.id,e.message)
    print("mw", sum(mw) / (len(mw) + 0.0))  # 9.46
    print("standard deviation ", sqrt(sum(stdDev) / (len(stdDev) + 0.0)))
    return (barsDictSim, barsDict)
开发者ID:702nADOS,项目名称:sumo,代码行数:31,代码来源:Traveltime.py

示例4: getBars

def getBars():
   """Classifies the time difference in single bars."""
   taxis=reader.readAnalysisInfo(WEE)   
   barsDict={}
   barsDictSim={}
   stdDev=[]
   mw=[]
   for taxi in taxis:
        if len(taxi.getSteps())<1:
            continue        
        try:
            #diff=getTimeDiff(taxi.getSteps(),False)
            diffSim,fcd,sim,no=getTimeDiff(taxi.getSteps())
            
            #anna     
            if diffSim>150:  
                print diffSim," ",taxi.id," ",no," ",fcd," ",sim                 
            
            #standard deviation 
            stdDev.append((diffSim-9.46)*(diffSim-9.46))   
            mw.append(diffSim) 
            #classify the absolute time difference
            #barsDict[(diff/10)*10]=barsDict.setdefault((diff/10)*10,0)+1   
            barsDictSim[(diffSim/10)*10]=barsDictSim.setdefault((diffSim/10)*10,0)+1 
        except TypeError, e:
            tueNichts=True
开发者ID:florianjomrich,项目名称:veinsSimConnectionToUnity,代码行数:26,代码来源:Traveltime.py

示例5: readFCDCompleteOLD

def readFCDCompleteOLD(fcdPath):
    """Reads the FCD-File and creates a list of Id's with a belonging List of Data tuples."""
    # reset all
    global taxis, routes, vlsEdges, taxiIdDict, fcdDict
    taxis = []
    routes = []
    vlsEdges = []
    taxiIdDict = {}
    fcdDict = {}

    vlsEdges = reader.readVLS_Edges()

    inputFile = open(fcdPath, 'r')
    for line in inputFile:
        words = line.split("\t")
        # add route
        taxiId = getTaxiId(words[4])
        if taxiId in taxis:
            if words[1] in vlsEdges:
                # routes[taxis.index(taxiId)].append(words[1])
                fcdDict[taxiId].append(
                    (getTimeInSecs(words[0]), words[1], words[2]))
            else:
                taxiIdDict[words[4]] += 1
        # if the edge is in the VLS-Area a new route is created
        elif words[1] in vlsEdges:
            taxis.append(taxiId)
            #                 departTime
            # routes.append([(int)(mktime(strptime(words[0],format))-simDate),words[1]])
            fcdDict[taxiId] = [(getTimeInSecs(words[0]), words[1], words[2])]

    inputFile.close()
    return fcdDict
开发者ID:RamonHPSilveira,项目名称:urbansim,代码行数:33,代码来源:GenerateTaxiRoutes.py

示例6: readFCD

def readFCD():
    """Reads the FCD and creates a list of Taxis and for each a list of routes"""
    vlsEdges = reader.readVLS_Edges()

    inputFile = open(path.fcd, 'r')
    for line in inputFile:
        words = line.split("\t")
        # add route
        taxiId = getTaxiId(words[4])
        actTime = getTimeInSecs(words[0])
        if taxiId in taxis:
            prevTime = routes[taxis.index(taxiId)][-1][0]
            # check if time lies not to far away from each other
            if words[1] in vlsEdges and (actTime - prevTime) < 180:
                routes[taxis.index(taxiId)].append((actTime, words[1]))
            # if time diff >3min add a new taxiId and start a new route
            elif words[1] in vlsEdges:
                taxiIdDict[words[4]] += 1  # create new taxiId
                taxis.append(getTaxiId(words[4]))  # append new created id
                # append new list (list will be filled with edges)
                routes.append([(actTime, words[1])])
            else:
                taxiIdDict[words[4]] += 1
        # if the edge is in the VLS-Area a new route is created
        elif words[1] in vlsEdges:
            taxis.append(taxiId)
            #                 departTime
            routes.append([(actTime, words[1])])

    inputFile.close()
    print len(taxis)
开发者ID:RamonHPSilveira,项目名称:urbansim,代码行数:31,代码来源:GenerateTaxiRoutes.py

示例7: getBarsMulti

def getBarsMulti():
    """Classifies the time difference in single bars.
     But uses insted of getBars() several analysis-File and calculates a mean value"""          
        
    fileIter=iglob(path.newPath(path.main,"auswertung/reisezeit/analysisFiles/taxiAnalysisInformation*.xml"))
    fcdDiffDict={}
    simDiffDict={}
    barsDict={}
    barsDictSim={}
    stdDev=[]
    mw=[]
    #calc diffs
    for file in fileIter: #for each 
        path.analysisWEE=path.newPath(file)
        print path.analysisWEE
        taxis=reader.readAnalysisInfo(WEE)
        
        for taxi in taxis:
            if len(taxi.getSteps())<1:                
                continue        
            try:
                #diff=getTimeDiff(taxi.getSteps(),False)
                diffSim,fcd,sim,no=getTimeDiff(taxi.getSteps())
                simDiffDict.setdefault(taxi.id,[]).append(sim)
                fcdDiffDict.setdefault(taxi.id,fcd)
                
            except TypeError, e:
                tueNichts=True                
开发者ID:cathyyul,项目名称:sumo-0.18,代码行数:28,代码来源:TraveltimeMulti.py

示例8: getAveragedValues

def getAveragedValues(interval):
    """catches all data in the given interval steps and calculates the average speed for each interval."""
    timeValues = range(0, 86410, interval)
    fcdValues = [[] for i in range(0, 86410, interval)]
    simFcdValues = [[] for i in range(0, 86410, interval)]
    vtypeValues = [[] for i in range(0, 86410, interval)]
    relErrorValues = [[] for i in range(0, 86410, interval)]
    absErrorValues = [[] for i in range(0, 86410, interval)]
    fcdValuesNo = [set() for i in range(0, 86410, interval)]
    simFcdValuesNo = [set() for i in range(0, 86410, interval)]
    vtypeValuesNo = [set() for i in range(0, 86410, interval)]
    taxis = reader.readAnalysisInfo(WEE)

    # helper function
    def calcAverageOrLen(list, no=False):
        for i in range(len(list)):
            if len(list[i]) > 0:
                if no:  # if no True clac Len
                    list[i] = len(list[i])
                else:
                    list[i] = sum(list[i]) / len(list[i])
            else:
                list[i] = None
        return list

    for taxi in taxis:
        for step in taxi.getSteps():
            if step.source == SOURCE_FCD:
                # add the speed to the corresponding time interval
                fcdValues[step.time / interval].append(step.speed)
                fcdValuesNo[step.time / interval].add(taxi.id)
            elif step.source == SOURCE_SIMFCD:
                # add the speed to the corresponding time interval
                simFcdValues[step.time / interval].append(step.speed)
                simFcdValuesNo[step.time / interval].add(taxi.id)
            elif step.source == SOURCE_VTYPE:
                # add the speed to the corresponding time interval
                vtypeValues[step.time / interval].append(step.speed)
                vtypeValuesNo[step.time / interval].add(taxi.id)

    vtypeValues = calcAverageOrLen(vtypeValues)
    fcdValues = calcAverageOrLen(fcdValues)
    simFcdValues = calcAverageOrLen(simFcdValues)
    vtypeValuesNo = calcAverageOrLen(vtypeValuesNo, True)
    fcdValuesNo = calcAverageOrLen(fcdValuesNo, True)
    simFcdValuesNo = calcAverageOrLen(simFcdValuesNo, True)

    # calc relative Error
    for i in range(len(fcdValues)):
        if simFcdValues[i] is None or fcdValues[i] is None:
            relErrorValues[i] = None
            absErrorValues[i] = None
        else:
            # (angezeigter-richtiger Wert)
            absErr = simFcdValues[i] - fcdValues[i]
            relErrorValues[i] = absErr / float(fcdValues[i]) * 100
            absErrorValues[i] = absErr
    return ([timeValues, fcdValues, simFcdValues, vtypeValues, fcdValuesNo, simFcdValuesNo, vtypeValuesNo,
            relErrorValues, absErrorValues], interval)
开发者ID:fieryzig,项目名称:sumo,代码行数:59,代码来源:VelocityCurve.py

示例9: main

def main(): 
    print "start program"
    global taxis, edgeDict 
    #load data
    edgeDict=load(open(path.edgeLengthDict,'r'))
    taxis=reader.readAnalysisInfo(WEE)
    plotAllTaxis()
    #plotIt(taxiId)
    #reader.readEdgesLength()
    print "end"
开发者ID:harora,项目名称:ITS,代码行数:10,代码来源:VelocityOverRoute.py

示例10: clacAvg

def clacAvg():
   durationList=[]
   taxis=reader.readAnalysisInfo()   
   for taxi in taxis:
       try:    
           dur=getTimeDiff(taxi.getSteps())
           durationList.append(dur)
           if dur >=1479:
               print "maxtaxi", taxi
       except TypeError, e:
            print "Error by taxi %s : %s"  %(taxi.id,e.message) 
开发者ID:florianjomrich,项目名称:veinsSimConnectionToUnity,代码行数:11,代码来源:Traveltime.py

示例11: sendmessage

def sendmessage(usr):
    reader.write_file('./util/'+usr+'message.txt','','a')
    url='/account/'+usr+'/sendmessage'
    if not 'username' in session:
        return redirect('/')
    user_list=reader.getCsvDict('./util/credentials.txt').keys()
    messages=reader.read_file('./util/'+usr+'message.txt')
    messages=messages.split('\n')
    messages.pop(-1)
    if messages==['']:
        out=False
    else:
        out=True
    if request.method=='GET':
        return render_template('messages.html',dir=url,messages=messages,out=out)
    elif request.method=='POST':
        if not request.form['recipient'] in user_list:
            return render_template('messages.html',dir=url,messages=messages,out=out)
        mess.sendMessage(session['username'],request.form['recipient'],request.form['message'])
        return redirect(url)
开发者ID:supershdow,项目名称:SlothPal,代码行数:20,代码来源:app.py

示例12: account

def account(usr):
    if not 'username' in session:
        return redirect('/')
    user_list = reader.getCsvDict("./util/credentials.txt")
    if not usr in user_list.keys():
        return render_template("error.html",error = "The username you have provided does not exist.",globe=globe)
    img=reader.getCsvDict('util/pfpimg.txt')
    userinfo=user_list[usr]
    gender=userinfo[1]
    Countryin=userinfo[2]
    Target=userinfo[3]
    url='/account/'+session['username']+'/settings'
    if session['username']==usr:
        own=True
    else:
        own=False
    if usr in img:
        img=img[usr][0]
    else:
        img='http://s3-static-ak.buzzfed.com/static/2014-07/14/12/campaign_images/webdr09/meet-lunita-the-cutest-baby-sloth-on-planet-earth-2-9684-1405357019-4_big.jpg'
    return render_template("account.html",user = usr,user_list = user_list,globe=globe, img=img,gender=gender,Country=Countryin,target=Target,own=own,dir=url)
开发者ID:supershdow,项目名称:SlothPal,代码行数:21,代码来源:app.py

示例13: delete

def delete():
    if request.method=='GET':
        reader.write_file('./util/'+session['username']+'message.txt','')
    else: 
        if request.method=='POST':
            old=reader.getCsvList('./util/'+session['username']+'message.txt')
            old.pop([int(request.form.keys()[0])][0])
            reader.write_file('./util/'+session['username']+'message.txt','')
            old.pop()
            for mess in old:
                reader.write_file('./util/'+session['username']+'message.txt',mess[0]+'\n','a')
    return redirect('/account/'+session['username']+'/sendmessage')
开发者ID:supershdow,项目名称:SlothPal,代码行数:12,代码来源:app.py

示例14: generateVLS_FCD_File

def generateVLS_FCD_File():
    """Creates a new FCD-file which contains only the rows which edges belongs to the VLS-Area"""
    outputVLSFile = open(path.vls, 'w')
    inputFile = open(path.fcd, 'r')

    vlsEdgeList = reader.readVLS_Edges()

    for line in inputFile:
        words = line.split("\t")
        # check if edge belongs to the VLS-Area
        if words[1] in vlsEdgeList:
            outputVLSFile.write(line)
    inputFile.close()
    outputVLSFile.close()
开发者ID:fieryzig,项目名称:sumo,代码行数:14,代码来源:SeparateVLSArea.py

示例15: getBarsMulti

def getBarsMulti():
    """Classifies the time difference in single bars.
     But uses insted of getBars() several analysis-File and calculates a mean value"""

    fileIter = iglob(path.newPath(
        path.main, "auswertung/reisezeit/analysisFiles/taxiAnalysisInformation*.xml"))
    fcdDiffDict = {}
    simDiffDict = {}
    barsDict = {}
    barsDictSim = {}
    stdDev = []
    mw = []
    # calc diffs
    for file in fileIter:  # for each
        path.analysisWEE = path.newPath(file)
        print(path.analysisWEE)
        taxis = reader.readAnalysisInfo(WEE)

        for taxi in taxis:
            if len(taxi.getSteps()) < 1:
                continue
            try:
                # diff=getTimeDiff(taxi.getSteps(),False)
                diffSim, fcd, sim, no = getTimeDiff(taxi.getSteps())
                simDiffDict.setdefault(taxi.id, []).append(sim)
                fcdDiffDict.setdefault(taxi.id, fcd)

            except TypeError as e:
                tueNichts = True
                # print "Error by taxi %s : %s"  %(taxi.id,e.message)

    for taxi, simList in simDiffDict.iteritems():
        simDiffDict[taxi] = sum(simList) / (len(simList) + 0.0)
    # create barsDict
    for taxi in fcdDiffDict:
        fcd = fcdDiffDict[taxi]
        sim = simDiffDict[taxi]
        diff = sim - fcd
        relDiff = int(round(((100.0 * diff) / fcd)))
        barsDictSim[
            (relDiff / 10) * 10] = barsDictSim.setdefault((relDiff / 10) * 10, 0) + 1
        # standard deviation
        stdDev.append((relDiff - 9.53) * (relDiff - 9.53))
        mw.append(relDiff)
    print("mw", sum(mw) / (len(mw) + 0.0))  # 9.91 #kor 0.48
    print("standard deviation ", sqrt(sum(stdDev) / (len(stdDev) + 0.0)))
    return (barsDictSim, barsDict)
开发者ID:702nADOS,项目名称:sumo,代码行数:47,代码来源:TraveltimeMulti.py


注:本文中的util.Reader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。