#!/usr/bin/env python3 import sys import os import mysql.connector DBHOST = 'gluondb1' DBUSER = 'hoss' DBPASS = '' DB_DB = 'HOSS' def Usage(): print('hoss_db.py - tool for querying HOSS file info. DB') #------------------------------------------- # GetRunRangeByRunPeriod #------------------------------------------- def GetRunRangeByRunPeriod(runperiod): # Need a better system than this if runperiod == 'RunPeriod-2019-11': return (70000,79999) if runperiod == 'RunPeriod-2019-01': return (60000,69999) if runperiod == 'RunPeriod-2018-08': return (50000,59999) if runperiod == 'RunPeriod-2018-01': return (40000,49999) if runperiod == 'RunPeriod-2017-01': return (30000,39999) # is this right? print('Unknown Run Period: ' + runperiod) #------------------------------------------- # ReportRunPeriod #------------------------------------------- def ReportRunPeriod(runperiod=''): if not runperiod: runperiod = os.getenv('RUN_PERIOD','RunPeriod-2019-11') (minrun,maxrun) = GetRunRangeByRunPeriod( runperiod ) runlimit = ' WHERE (run>=%d AND run <=%d) ' % (minrun, maxrun) sql = 'SELECT count(*) AS Nfiles FROM skiminfo ' + runlimit cur.execute( sql ) Nfiles = int(cur.fetchone()['Nfiles']) sql = 'SELECT run,count(run) AS Nfiles,MAX(file) AS max_file FROM skiminfo' + runlimit + 'GROUP BY run' cur.execute( sql ) Nruns = 0 Nincomplete = 0 Nmissing_tot = 0 for row in cur.fetchall(): Nruns += 1 Nmissing = row['max_file'] + 1 - row['Nfiles'] Nmissing_tot += Nmissing if Nmissing != 0: Nincomplete += 1 print(' Num. files: %d' % Nfiles) print(' Num. runs: %d' % Nruns) print('Num. incomplete runs: %d' % Nincomplete) print(' Num. missing files: %d' % Nmissing_tot) #======================================================================================= for arg in sys.argv[1:]: if arg=='-h' or arg=='--help': Usage() sys.exit(0) cnx = mysql.connector.connect(host=DBHOST, user=DBUSER, password=DBPASS, database=DB_DB) cur = cnx.cursor(dictionary=True) ReportRunPeriod() cur.close() cnx.close()