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


Python Library.timeConv方法代码示例

本文整理汇总了Python中Library.timeConv方法的典型用法代码示例。如果您正苦于以下问题:Python Library.timeConv方法的具体用法?Python Library.timeConv怎么用?Python Library.timeConv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Library的用法示例。


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

示例1: dateOverlapCheck

# 需要导入模块: import Library [as 别名]
# 或者: from Library import timeConv [as 别名]
 def dateOverlapCheck(self, startTime, stopTime): 
     
     startTimeSec = Library.timestamp(Library.timeConv(startTime))
     stopTimeSec = startTimeSec + float(stopTime)
     # print startTimeSec
     # print stopTimeSec
     
     dtNowSec = Library.timestamp(dt.now())
     # print "dt.now():",dt.now()
     # print "dtNow:",dtNowSec
     
     if startTimeSec <= dtNowSec or stopTimeSec <= dtNowSec:
         print "Error: Dates cannot be in the past"
         return "Error: Dates cannot be in the past"
         
 
     if startTimeSec >= stopTimeSec:
         print "Start Date cannot be the same or later than stop time"
         return 
         
      
     n = "1"
     try:
         conn = Library.dbconn()
         c = conn.cursor()
     
         c.execute('SELECT startTime, stopTime FROM emulationLifetime')
                 
         emulationLifetimeFetch = c.fetchall()
         
         if emulationLifetimeFetch:
             for row in emulationLifetimeFetch:
                 # print row
                 startTimeDBsec = Library.timestamp(Library.timeConv(row[0]))
                 stopTimeDBsec = startTimeDBsec + float(row[1])
                 
                 if startTimeSec >= startTimeDBsec and startTimeSec <= stopTimeDBsec:
                     # print "Emulation already exist for this date change the date(1)"
                     
                     n = "Emulation already exist for this date change the date(1)"
                 
                     
                     
                 if stopTimeSec >= startTimeDBsec and stopTimeSec <= stopTimeDBsec:
                     # print "Emulation already exist for this date change the date(2)"
                     n = "Emulation already exist for this date change the date(2)"
                     
                     
                 
                 if startTimeSec <= startTimeDBsec and stopTimeSec >= stopTimeDBsec:
                     # print "Emulation already exist for this date change the date(3)"
                     
                     n = "Emulation already exist for this date change the date(3)"
                     
                     
                 
         else:
             pass    
         conn.commit()
         c.close()
     except Exception, e:
         print "dateOverlapCheck() SQL Error %s:" % e.args[0]
         print e
         return str(e)
开发者ID:cragusa,项目名称:cocoma,代码行数:66,代码来源:Emulation.py

示例2: createDistributionRuns

# 需要导入模块: import Library [as 别名]
# 或者: from Library import timeConv [as 别名]
def createDistributionRuns(newEmulation):
    daemon=Library.getDaemon()
    daemon.setEmuObject(newEmulation)
    
    for distro in newEmulation.distroList:

        if distro.getDistributionID() != "none":
            #do nothing continue to next element, because this distribution was already scheduled.
            print "Already scheduled"

        else:
                        
            try:
                conn = Library.dbconn()
                c = conn.cursor()
                    
                # 1. We populate "distribution" table      
                c.execute('INSERT INTO distribution (distributionGranularity, distributionType,emulator,distributionName,startTime,duration,emulationID) VALUES (?, ?, ?, ?,?, ?,?)', [distro.granularity, distro.type, distro.emulatorName,distro.name,distro.startTime,distro.duration,newEmulation.emulationID])
                distro.setDistributionID(c.lastrowid)
                daemon.setEmuObject(newEmulation)
                '''
                {'startLoad': u'10', 'stopLoad': u'90'}
                '''
                #print "distributionArg:", distributionArg
                #print "emulatorArg:",emulatorArg
                
                #2. populate DistributionParameters, of table determined by distributionType name in our test it is "linearDistributionParameters"
                for d in distro.distroArgs :
                    c.execute('INSERT INTO DistributionParameters (paramName,value,distributionID) VALUES (?, ?, ?)',[d,distro.distroArgs[d],distro.ID])
                distributionParametersID=c.lastrowid
                
                
                c.execute('UPDATE distribution SET distributionParametersID=? WHERE distributionID =?',(distributionParametersID,distro.ID))
                
                
                for emu in distro.emulatorArg :
                    c.execute('INSERT INTO EmulatorParameters (paramName,value,resourceType,distributionID) VALUES (?, ?, ?,?)',[emu,distro.emulatorArg[emu],distro.resourceType,distro.ID])
                distributionParametersID=c.lastrowid
                
                conn.commit()
                c.close()
            except sqlite.Error, e:
                print "Error %s:" % e.args[0]
                print e
                sys.exit(1)                        
                   
            startTime= Library.timeConv(newEmulation.startTimeEmu)
            startTimesec=time.mktime(startTime.timetuple()) + float(distro.startTime)
            #making sure that the run after event has valid date for scheduling
            nowTime = Library.timeSinceEpoch(5)
            if startTimesec < nowTime:
                startTimesec = nowTime + float(distro.startTime)
                
            '''
            1. Load the module according to Distribution Type to create runs
            '''
    
            #1. Get required module loaded
            modhandleMy=Library.loadDistribution(distro.type)
            #Check if error returned
            if (type(modhandleMy) is str):
                raise Exception (modhandleMy)
             
            #2. Use this module for calculation and run creation   
            stressValues,runStartTime,runDurations,triggerType=modhandleMy(newEmulation.emulationID,newEmulation.emulationName,newEmulation.getEmulationLifetimeID(),startTimesec,distro.duration, int(distro.granularity),distro.distroArgs,distro.resourceType,HOMEPATH)

            if (distro.type != "event"): #event distributions don't require a minjobtime
                try:
                    if (distro.distroArgs.has_key("minjobtime")):
                        minJobTime = distro.distroArgs["minjobtime"]
                    else:
                        minJobTime = 2
                    (stressValues, runStartTime, runDurations) = Library.checkMinJobTime(distro.name, stressValues, runStartTime, runDurations, distro.distroArgs["minjobtime"])
                except Exception, e:
                    print "Could not enforce minimum job time. " + str(e)

            runStartTime = Library.staggerStartTimes(runStartTime)
            (stressValues, runStartTime, runDurations) = Library.removeZeroJobs(stressValues, runStartTime, runDurations) #Remove jobs with a stressValue of 0
            #event and time type disro's separation
            try :
                    n=0
                    for vals in stressValues:
                        #print "stressValues: ",vals
                        try:
                            #print "Things that are sent to daemon:\n",emulationID,emulationName,distributionName,emulationLifetimeID,runDurations[n],emulator,emulatorArg,resourceTypeDist,vals,runStartTime[n],str(n)
                            daemon.hello()
                            #Sending emulation name already including ID stamp
                            emulationNameID =str(newEmulation.emulationID)+"-"+str(newEmulation.emulationName)
                            
                            schedulerReply = str(daemon.createJob(newEmulation.emulationID,emulationNameID,distro.ID,distro.name,newEmulation.getEmulationLifetimeID(),runDurations[n],distro.emulatorName,distro.emulatorArg,distro.resourceType,vals,runStartTime[n],str(n),runDurations[n]))
                            distLoggerDM=singleLogger("Distribution Manager",None,str(newEmulation.emulationID)+"-"+str(newEmulation.emulationName)+"-syslog"+"_"+str(newEmulation.startTimeEmu)+".csv")
                            distLoggerDM.info("Job Created: "+schedulerReply)
            
                            
                            
                            #adding values to the table for recovery
                            try:
                                conn = Library.dbconn()
                                c = conn.cursor()
                                    
#.........这里部分代码省略.........
开发者ID:cragusa,项目名称:cocoma,代码行数:103,代码来源:DistributionManager.py

示例3: createDistribution

# 需要导入模块: import Library [as 别名]
# 或者: from Library import timeConv [as 别名]
def createDistribution(newEmulation):
    daemon=Library.getDaemon()
    
    global producer
    if producer is None:
        # print "In distributionManager, copying producer"
        producer = producer()

    # print "Who calls "+sys._getframe(0).f_code.co_name+": "+sys._getframe(1).f_code.co_name
#    distLoggerDM = ""
    
    # if distLoggerDM is None:
    #        distLoggerDM=Library.loggerSet("Distribution Manager",str(newEmulation.emulationID)+"-"+str(newEmulation.emulationName)+"-syslog"+"_"+str(newEmulation.startTimeEmu)+".csv")



    # connecting to the DB and storing parameters
    loggerJobReply = "No logger scheduled"
    try:

        conn = Library.dbconn()
        c = conn.cursor()
                
        # 1. Populate "emulation"
        c.execute('INSERT INTO emulation (emulationName,emulationType,resourceType,active,logging,logFrequency,logLevel,xmlData) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [newEmulation.emulationName, newEmulation.emulationType, newEmulation.resourceTypeEmulation, 1, newEmulation.emulationLog, newEmulation.emulationLogFrequency, newEmulation.emulationLogLevel, newEmulation.xmlData])
        newEmulation.setEmulationID(c.lastrowid)
        # start logger here once we know emulation ID
#        distLoggerDM = singleLogger("Distribution Manager", None, str(newEmulation.emulationID) + "-" + str(newEmulation.emulationName) + "-syslog" + "_" + str(newEmulation.startTimeEmu) + ".csv")
        
        c.execute('UPDATE emulation SET emulationName=? WHERE emulationID =?', (str(newEmulation.emulationID) + "-" + newEmulation.emulationName, newEmulation.emulationID))
        
        # 2. We populate "emulationLifetime" table  
        c.execute('INSERT INTO emulationLifetime (startTime,stopTime,emulationID) VALUES (?,?,?)', [newEmulation.startTimeEmu, newEmulation.stopTimeEmu, newEmulation.emulationID])
        emulationLifetimeID = c.lastrowid

        newEmulation.setEmulationLifetimeID(emulationLifetimeID)
        c.execute('UPDATE emulationLifetime SET stopTime=? WHERE emulationLifetimeID =?',(newEmulation.stopTimeEmu,emulationLifetimeID))
        c.execute('UPDATE emulation SET emulationLifetimeID=? WHERE emulationID=?',(emulationLifetimeID,newEmulation.emulationID))
        
        conn.commit()
        c.close()
        
        """
        # Here we create runs
        """

#        raise Exception ("newEmulation.emulationLog = " + str(newEmulation.emulationLog))
        if newEmulation.emulationLog == "1":
            
            # creating run for logger with probe interval of 2 seconds
            distLoggerDM = singleLogger("Distribution Manager", None, str(newEmulation.emulationID) + "-" + str(newEmulation.emulationName) + "-syslog" + "_" + str(newEmulation.startTimeEmu) + ".csv")
            interval = int(newEmulation.emulationLogFrequency)
            singleRunStartTime = Library.timeConv(newEmulation.startTimeEmu)
            loggerJobReply = daemon.createLoggerJob(singleRunStartTime, newEmulation.stopTimeEmu, interval, newEmulation.emulationID, newEmulation.emulationName, newEmulation.startTimeEmu)       
        
        createEndJob(daemon, newEmulation)
        
    except sqlite.Error, e:
        print e
        return "SQL error:", e
        sys.exit(1)
开发者ID:cragusa,项目名称:cocoma,代码行数:63,代码来源:DistributionManager.py

示例4: createEndJob

# 需要导入模块: import Library [as 别名]
# 或者: from Library import timeConv [as 别名]
def createEndJob (daemon, newEmulation):
    returnEmulationName = (str(newEmulation.emulationID) + "-" + newEmulation.emulationName)
    #Calcualte when the end job should be (start + duration +1) //+1 is to allow for delay in scheduler starting emulation 
    emulationEndTime = (Library.timeConv(newEmulation.startTimeEmu)) + dt.timedelta(0, (float(newEmulation.stopTimeEmu) + 1))
    emulationEndJobReply = daemon.createEmulationEndJob(emulationEndTime, returnEmulationName)
开发者ID:cragusa,项目名称:cocoma,代码行数:7,代码来源:DistributionManager.py


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