Skip to content

Commit b94e11f

Browse files
committed
Add filter support for event name
1 parent b32b652 commit b94e11f

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

preciceprofiling/common.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,17 @@ def makeData(s):
115115
def participants(self):
116116
return [name for (name,) in self._cur.execute("SELECT name FROM participants")]
117117

118-
def toDataFrame(self, participant=None):
118+
def events(self):
119+
return [name for (name,) in self._cur.execute("SELECT name FROM names")]
120+
121+
def toDataFrame(self, participant=None, event=None):
119122
query = "SELECT * FROM full_events"
120-
if participant:
123+
if participant and event:
124+
query += f" WHERE participant = '{participant}' and event = '{event}'"
125+
elif participant:
121126
query += f" WHERE participant = '{participant}'"
127+
elif event:
128+
query += f" WHERE event = '{event}'"
122129

123130
return (
124131
pl.read_database(

preciceprofiling/histogram.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from preciceprofiling.common import Run
1+
from preciceprofiling.common import Run, ns_to_unit_factor
22
import matplotlib.pyplot as plt
33
import polars as pl
44
import argparse
@@ -55,15 +55,15 @@ def runHistogram(ns):
5555

5656
def histogramCommand(profilingfile, outfile, participant, event, rank, bins, unit="us"):
5757
run = Run(profilingfile)
58-
df = run.toDataFrame()
5958

6059
# Check user input
61-
assert df.select(
62-
pl.col("participant").is_in([participant]).any()
63-
).item(), f"Given participant {participant} doesn't exist."
64-
assert df.select(
65-
pl.col("eid").is_in([event]).any()
66-
).item(), f"Given event {event} doesn't exist."
60+
assert (
61+
participant in run.participants()
62+
), f"Given participant {participant} doesn't exist."
63+
assert event in run.events(), f"Given event {event} doesn't exist."
64+
65+
df = run.toDataFrame(participant=participant, event=event)
66+
6767
if not rank is None:
6868
assert df.select(
6969
pl.col("rank").is_in([rank]).any()

0 commit comments

Comments
 (0)