Outline main into class

This commit is contained in:
Jose Gracia 2023-11-22 10:30:36 +01:00
parent 36bfb06228
commit ee106619ea

View file

@ -10,7 +10,7 @@ def parse_arguments():
parser.add_argument('-v', '--verbose', action='store_true',
help='Show database querries, etc.')
parser.add_argument('jobid', type=parse_jobid,
# nargs='+',
nargs='+',
help='Job ID such as "2260215" or "2260215.hawk-pbs5"')
return parser.parse_args()
@ -183,14 +183,27 @@ class MonitoringDB:
query = self.build_query(jobid, interval)
return pd.read_sql(query, con=self.connection)
class App:
def __init__(self, config):
self.config = config
self.db = MonitoringDB(self.config.verbose)
def run_all(self):
for jobid in self.config.jobid:
power = Power.from_db(self.db, jobid, self.config.interval)
fn = power.to_file(jobid)
if fn:
print('Created file {fn}'.format(fn=fn))
if __name__ == "__main__":
config = parse_arguments()
config.interval = 5
DB = MonitoringDB(config.verbose)
main = App(config)
main.run_all()
power = Power.from_db(DB, config.jobid, config.interval)
#power = Power.from_db(DB, config.jobid, config.interval)
#print("#epochs", len(power.epochs))
#
#print(power.header())
@ -201,7 +214,7 @@ if __name__ == "__main__":
#print('time:', power.summarize_time(ts))
#print('values:', power.summarize_values(values))
#print('epoch:', power.pretty_print(power.summarize_epoch((ts, values))))
print("filename: ", power.to_file(config.jobid))
#print("filename: ", power.to_file(config.jobid))