Skip to content

Commit 0de7a53

Browse files
committed
Saved files as PD frame for GE
1 parent 896c2be commit 0de7a53

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# E X A M P L E 6
2+
# Make a pandas DataFrame of the configuration/log files saved for runs:
3+
# rows = the last 10 runs
4+
# columns = every file path seen across those runs
5+
# cells = the file's sha256 hash for that run, or NaN if the run has no such file
6+
7+
import pandas as pd
8+
9+
# import RCDB
10+
from rcdb.provider import RCDBProvider
11+
from rcdb.model import Run
12+
13+
# connect to DB
14+
db = RCDBProvider("mysql://rcdb@hallddb.jlab.org/rcdb2")
15+
16+
# the last 10 runs (highest run numbers)
17+
runs = db.session.query(Run).order_by(Run.number.desc()).limit(10).all()
18+
19+
# for each run map every saved file path -> its hash
20+
# (run.files is the list of ConfigurationFile objects attached to the run)
21+
file_hashes = {run.number: {f.path: f.sha256 for f in run.files} for run in runs}
22+
23+
# build the DataFrame: file paths as columns, run number as the index.
24+
# from_dict fills missing files with NaN, so a cell is the hash if the file
25+
# exists for that run and NaN otherwise.
26+
df = pd.DataFrame.from_dict(file_hashes, orient="index").sort_index()
27+
df.index.name = "run"
28+
29+
# P R I N T O U T
30+
print("{} runs x {} distinct files".format(df.shape[0], df.shape[1]))
31+
print(df)

0 commit comments

Comments
 (0)