def createsummary(options, totalprocs, procid): procidstr = "%s of %s " % (procid, totalprocs) if totalprocs != None else "" logging.info("Processor " + procidstr + "starting") referencetime = int(time.time()) - ( 7 * 24 * 3600 ) config = account.getconfig(options['config']) dbconf = config['accountdatabase'] outdb = output.factory(config['outputdatabase']) ratecalc = RateCalculator(procid) timewindows = dict() for resourcename, settings in config['resources'].iteritems(): if 'enabled' in settings: if settings['enabled'] == False: continue if options['resource'] not in (None, resourcename, str(settings['resource_id'])): continue processtimes = { "mintime": 2**64, "maxtime": 0 } dbreader = account.DbAcct( settings['resource_id'], dbconf, PROCESS_VERSION, totalprocs, procid, options['localjobid']) bacct = batch_acct.factory(settings['batch_system'], settings['acct_path'], settings['host_name_ext'] ) if settings['lariat_path'] != "": lariat = summarize.LariatManager(settings['lariat_path']) else: lariat = None dbwriter = account.DbLogger( dbconf["dbname"], dbconf["tablename"], dbconf["defaultsfile"] ) for acct in dbreader.reader(): logging.debug("%s local_job_id = %s", resourcename, acct['id']) job = job_stats.from_acct( acct, settings['tacc_stats_home'], settings['host_list_dir'], bacct ) summary,timeseries = summarize.summarize(job, lariat) insertOk = outdb.insert(resourcename, summary, timeseries) if summary['complete'] == False and summary["acct"]['end_time'] > referencetime: # Do not mark incomplete jobs as done unless they are older than the # reference time (which defaults to 7 days ago) dbwriter.logprocessed(acct, settings['resource_id'], ERROR_INCOMPLETE) continue if insertOk: dbwriter.logprocessed( acct, settings['resource_id'], PROCESS_VERSION ) processtimes['mintime'] = min( processtimes['mintime'], summary["acct"]['end_time'] ) processtimes['maxtime'] = max( processtimes['maxtime'], summary["acct"]['end_time'] ) ratecalc.increment() else: # Mark as negative process version to indicate that it has been processed # but no summary was output dbwriter.logprocessed( acct, settings['resource_id'], 0 - PROCESS_VERSION ) if processtimes['maxtime'] != 0: timewindows[resourcename] = processtimes logging.info("Processor " + procidstr + "exiting. Processed %s", ratecalc.count) if ratecalc.count == 0: # No need to generate a report if no docs were processed return proc = { "host": socket.getfqdn(), "instance": procid, "totalinstances": totalprocs, "start_time": ratecalc.starttime, "end_time": time.time() , "rate": ratecalc.rate, "records": ratecalc.count } report = { "proc": proc, "resources": timewindows } outdb.logreport(report)
def createsummary(options, totalprocs, procid): procidstr = "%s of %s " % (procid, totalprocs) if totalprocs != None else "" logging.info("Processor " + procidstr + "starting") referencetime = int(time.time()) - ( 7 * 24 * 3600 ) config = account.getconfig(options['config']) dbconf = config['accountdatabase'] outdb = output.factory(config['outputdatabase']) ratecalc = RateCalculator(procid) timewindows = dict() for resourcename, settings in config['resources'].iteritems(): if 'enabled' in settings: if settings['enabled'] == False: continue if options['resource'] not in (None, resourcename, str(settings['resource_id'])): continue processtimes = { "mintime": 2**64, "maxtime": 0 } if options['start'] == None: dbreader = account.DbAcct( settings['resource_id'], dbconf, PROCESS_VERSION, totalprocs, procid, options['localjobid']) else: # Choose a process version that doesn't exist so that all jobs are selected selectedProcVersion = PROCESS_VERSION + 1 if options['ignoreprocessed']: selectedProcVersion = PROCESS_VERSION dbreader = account.DbAcct( settings['resource_id'], dbconf, selectedProcVersion, totalprocs, procid, None) bacct = batch_acct.factory(settings['batch_system'], settings['acct_path'], settings['host_name_ext'] ) if settings['lariat_path'] != "": lariat = summarize.LariatManager(settings['lariat_path']) else: lariat = None dbwriter = account.DbLogger( dbconf["dbname"], dbconf["tablename"], dbconf["defaultsfile"] ) for acct in dbreader.reader(options['start'], options['end']): logging.debug("%s local_job_id = %s", resourcename, acct['id']) job = job_stats.from_acct( acct, settings['tacc_stats_home'], settings['host_list_dir'], bacct ) summary,timeseries = summarize.summarize(job, lariat) insertOk = outdb.insert(resourcename, summary, timeseries) if summary['complete'] == False and summary["acct"]['end_time'] > referencetime: # Do not mark incomplete jobs as done unless they are older than the # reference time (which defaults to 7 days ago) dbwriter.logprocessed(acct, settings['resource_id'], ERROR_INCOMPLETE) continue if insertOk: dbwriter.logprocessed( acct, settings['resource_id'], PROCESS_VERSION ) processtimes['mintime'] = min( processtimes['mintime'], summary["acct"]['end_time'] ) processtimes['maxtime'] = max( processtimes['maxtime'], summary["acct"]['end_time'] ) ratecalc.increment() else: # Mark as negative process version to indicate that it has been processed # but no summary was output dbwriter.logprocessed( acct, settings['resource_id'], 0 - PROCESS_VERSION ) if processtimes['maxtime'] != 0: timewindows[resourcename] = processtimes logging.info("Processor " + procidstr + "exiting. Processed %s", ratecalc.count) if ratecalc.count == 0: # No need to generate a report if no docs were processed return proc = { "host": socket.getfqdn(), "instance": procid, "totalinstances": totalprocs, "start_time": ratecalc.starttime, "end_time": time.time() , "rate": ratecalc.rate, "records": ratecalc.count } report = { "proc": proc, "resources": timewindows } outdb.logreport(report)
def _open_output(self): logging.debug("Opening output") self._output_engine = output.factory(self._output)(self._output) # print(self._output_engine) self._output_engine.connect()
import time import output import controller import morse def get_time(): return time.strftime('%H%M') if __name__ == "__main__": CHUNK = 2**10 RATE = 48000 outp = output.factory('optocoupler', CHUNK, RATE) outp.callback() m = morse.Morse(outp, 4) ctrl = controller.Controller() try: while True: curr_time = get_time() while curr_time == get_time(): outp.callback() print(curr_time) m.show(curr_time) finally: outp.close()
import time import output import controller if __name__ == "__main__": CHUNK = 2**10 RATE = 48000 outp = output.factory('pygame', CHUNK, RATE) outp.callback() ctrl = controller.Controller() i = 1 try: while True: outp.callback() print(i) if i == 1: outp.on() time.sleep(1) outp.off() time.sleep(1) i = int(time.time()) else: time.sleep(.1) if i % 2 == 0: outp.on() i = i // 2 else: