From 4c1c3d2aeb22e6f535a01c27828286ff35e124a4 Mon Sep 17 00:00:00 2001 From: "Kevin A. Tactac" Date: Tue, 2 Jan 2024 13:21:28 -0500 Subject: [PATCH 1/6] bug fixed --- scripts/ar_report.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/ar_report.py b/scripts/ar_report.py index e0c0f1c..bf5823c 100755 --- a/scripts/ar_report.py +++ b/scripts/ar_report.py @@ -315,8 +315,9 @@ def __init__(self, direc, filename): with h5py.File(self.filename, "r") as handle: entry = handle.get("entry") - self.timeStart = entry.get("start_time").value[0].decode("utf-8")[:16] - self.timeStop = entry.get("end_time").value[0].decode("utf-8")[:16] + + self.timeStart = entry.get("start_time")[0].decode("utf-8")[:16] + self.timeStop = entry.get("end_time")[0].decode("utf-8")[:16] def __str__(self): return self.prefix From 3143953708fd8969929d99cff0e946e3cfe9ffe9 Mon Sep 17 00:00:00 2001 From: "Kevin A. Tactac" Date: Mon, 18 Dec 2023 16:45:30 -0500 Subject: [PATCH 2/6] add h5py dependency and actually commit f-strings --- environment.yml | 1 + scripts/ar-report.py | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/environment.yml b/environment.yml index 323f6bd..6546ac3 100644 --- a/environment.yml +++ b/environment.yml @@ -11,5 +11,6 @@ dependencies: - pytest-mock - requests=2.25 - stomp.py=7 + - h5py # needed for wheel - add when switching to python3 # - build diff --git a/scripts/ar-report.py b/scripts/ar-report.py index 77b6b8a..46906cd 100755 --- a/scripts/ar-report.py +++ b/scripts/ar-report.py @@ -47,22 +47,22 @@ def iso8601(self): return self.timeCreation.strftime("%Y-%m-%dT%H:%M") def filesizeMiB(self): - return "%.f" % (float(self.filesize) / 1024.0 / 1024.0) + return f"{float(self.filesize) / 1024.0 / 1024.0}" def filesizehuman(self): if self.filesize < 1024: - return "%dB" % (self.filesize) + return f"{self.filesize} B" filesize_converted = float(self.filesize) / 1024.0 # to kiB if filesize_converted < 1024.0: - return "%.1fkiB" % (filesize_converted) + return f"{filesize_converted:.1f} kiB" filesize_converted = float(filesize_converted) / 1024.0 # to MiB if filesize_converted < 1024.0: - return "%.1fMiB" % (filesize_converted) + return f"{filesize_converted:.1f} MiB" filesize_converted = float(filesize_converted) / 1024.0 # to GiB - return "%.1fGiB" % (filesize_converted) + return f"{filesize_converted:.1f} GiB" class ReductionLogFile(GenericFile): @@ -83,13 +83,13 @@ def __init__(self, logfullname, eventfilename): self.__findMantidVersion() self.__findLongestDuration() - self.longestDuration = "%.1f" % self.longestDuration + self.longestDuration = f"{self.longestDuration:.1f}" self.__findLoadNexusTotal(eventfilename) - self.loadEventNexusDuration = "%.1f" % self.loadEventNexusDuration + self.loadEventNexusDuration = f"{self.loadEventNexusDuration:.1f}" self.__findLoadTotal() - self.loadDurationTotal = "%.1f" % self.loadDurationTotal + self.loadDurationTotal = f"{self.loadDurationTotal:.1f}" def durationToHuman(duration): (hours, minutes, seconds) = (0.0, 0.0, duration) @@ -99,7 +99,7 @@ def durationToHuman(duration): if minutes > 60: hours = int(minutes / 60) minutes = minutes % 60 - return "%dh%02dm%02ds" % (hours, minutes, int(seconds)) + return f"{hours:d}h{minutes:02d}m{int(seconds):02d}" def __findLoadNexusTotal(self, eventfilename): with open(self.filename, "r") as handle: @@ -338,11 +338,11 @@ def getPropDir(descr): # error check the result if not os.path.exists(fullpath): - raise RuntimeError("%s does not exist" % fullpath) + raise RuntimeError(f"{fullpath} does not exist") if not os.path.isdir(fullpath): - raise RuntimeError("%s is not a directory" % fullpath) + raise RuntimeError(f"{fullpath} is not a directory") if not (fullpath.startswith("/SNS/") and ("IPTS" in fullpath)): - raise RuntimeError("%s does not appear to be a proposal directory" % fullpath) + raise RuntimeError(f"{fullpath} does not appear to be a proposal directory") return fullpath @@ -367,7 +367,7 @@ def getRuns(propdir): def getOutFilename(propdir): (parent, prop) = os.path.split(propdir) (parten, inst) = os.path.split(parent) - return "%s-%s.csv" % (inst, prop) + return f"{inst}-{prop}.csv" if __name__ == "__main__": @@ -395,7 +395,7 @@ def getOutFilename(propdir): if runfile == propdir: runfile = None - print("Finding event nexus files in '%s'" % propdir) + print(f"Finding event nexus files in '{propdir}'") if runfile is not None: runs = [EventFile(*(os.path.split(runfile)))] else: @@ -406,7 +406,7 @@ def getOutFilename(propdir): outfile = getOutFilename(propdir) outfile = os.path.join(args.outputdir, outfile) - print("Writing results to '%s'" % outfile) + print(f"Writing results to '{outfile}'") total_runs = len(runs) total_reduced = 0 if runfile is None or (not os.path.exists(outfile)): @@ -422,4 +422,4 @@ def getOutFilename(propdir): if len(ar.reduxfiles) > 0: total_reduced += 1 handle.write(",".join(report) + "\n") - print("%d of %d files reduced" % (total_reduced, total_runs)) + print(f"{total_reduced} of {total_runs} files reduced") From 7bc36cb553a60f37a7aa17f798cba3f449353ebd Mon Sep 17 00:00:00 2001 From: "Kevin A. Tactac" Date: Mon, 18 Dec 2023 16:49:52 -0500 Subject: [PATCH 3/6] __main__ -> main() --- scripts/ar-report.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/ar-report.py b/scripts/ar-report.py index 46906cd..9256b2d 100755 --- a/scripts/ar-report.py +++ b/scripts/ar-report.py @@ -370,7 +370,8 @@ def getOutFilename(propdir): return f"{inst}-{prop}.csv" -if __name__ == "__main__": + +def main(): import argparse parser = argparse.ArgumentParser( @@ -423,3 +424,9 @@ def getOutFilename(propdir): total_reduced += 1 handle.write(",".join(report) + "\n") print(f"{total_reduced} of {total_runs} files reduced") + + + +if __name__ == "__main__": + main() + From 982c8fef951315c8e4894401ac5dceff31391492 Mon Sep 17 00:00:00 2001 From: "Kevin A. Tactac" Date: Mon, 18 Dec 2023 16:51:13 -0500 Subject: [PATCH 4/6] ar-report.py -> ar_report.py --- scripts/{ar-report.py => ar_report.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{ar-report.py => ar_report.py} (100%) diff --git a/scripts/ar-report.py b/scripts/ar_report.py similarity index 100% rename from scripts/ar-report.py rename to scripts/ar_report.py From 2e66819e1259c4e4db1e84d085f289abfb70dcd9 Mon Sep 17 00:00:00 2001 From: "Kevin A. Tactac" Date: Tue, 19 Dec 2023 14:09:59 -0500 Subject: [PATCH 5/6] fix pre-commit --- scripts/ar_report.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/ar_report.py b/scripts/ar_report.py index 9256b2d..e0c0f1c 100755 --- a/scripts/ar_report.py +++ b/scripts/ar_report.py @@ -370,7 +370,6 @@ def getOutFilename(propdir): return f"{inst}-{prop}.csv" - def main(): import argparse @@ -402,8 +401,9 @@ def main(): else: runs = getRuns(propdir) reducedir = os.path.join(propdir, "shared", "autoreduce") - shareddirlist = os.listdir(reducedir) - reduceloglist = os.listdir(os.path.join(reducedir, REDUCTION_LOG)) + + # shareddirlist = os.listdir(reducedir) + # reduceloglist = os.listdir(os.path.join(reducedir, REDUCTION_LOG)) outfile = getOutFilename(propdir) outfile = os.path.join(args.outputdir, outfile) @@ -426,7 +426,5 @@ def main(): print(f"{total_reduced} of {total_runs} files reduced") - if __name__ == "__main__": main() - From 61dd9f177c572ef43cef6a03c36c584d5cbf1c20 Mon Sep 17 00:00:00 2001 From: "Kevin A. Tactac" Date: Tue, 2 Jan 2024 13:21:28 -0500 Subject: [PATCH 6/6] bug fixed --- scripts/ar_report.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/ar_report.py b/scripts/ar_report.py index e0c0f1c..bf5823c 100755 --- a/scripts/ar_report.py +++ b/scripts/ar_report.py @@ -315,8 +315,9 @@ def __init__(self, direc, filename): with h5py.File(self.filename, "r") as handle: entry = handle.get("entry") - self.timeStart = entry.get("start_time").value[0].decode("utf-8")[:16] - self.timeStop = entry.get("end_time").value[0].decode("utf-8")[:16] + + self.timeStart = entry.get("start_time")[0].decode("utf-8")[:16] + self.timeStop = entry.get("end_time")[0].decode("utf-8")[:16] def __str__(self): return self.prefix