Skip to content

Commit a1a2f07

Browse files
authored
Merge pull request #60 from NathanPB/feat/analytics-hooks
2 parents f1225dd + 85a7a0e commit a1a2f07

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

pythia/analytics.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pythia.analytic_functions
99
import pythia.io
1010
import pythia.util
11+
import pythia.plugin
1112
from contextlib import _GeneratorContextManager
1213

1314

@@ -250,13 +251,21 @@ def collate_outputs(config, run):
250251
def execute(config, plugins):
251252
runs = config.get("runs", [])
252253
analytics_config = config.get("analytics_setup", None)
254+
255+
if not analytics_config or len(runs) == 0:
256+
logging.warning("Skipping analytics: no configuration or runs found.")
257+
return
258+
259+
pythia.plugin.run_plugin_functions(
260+
pythia.plugin.PluginHook.pre_analytics,
261+
plugins,
262+
config=config,
263+
)
264+
253265
run_outputs = []
254266
calculated = None
255267
filtered = None
256-
if not analytics_config:
257-
return
258-
if len(runs) == 0:
259-
return
268+
260269
for run in runs:
261270
run_outputs.append(collate_outputs(config, run))
262271
# Apply all the filters first
@@ -272,3 +281,12 @@ def execute(config, plugins):
272281
combine_outputs(config, filtered)
273282
else:
274283
final_outputs(config, filtered)
284+
285+
pythia.plugin.run_plugin_functions(
286+
pythia.plugin.PluginHook.post_analytics,
287+
plugins,
288+
config=config,
289+
run_outputs=run_outputs,
290+
calculated=calculated,
291+
filtered=filtered,
292+
)

pythia/plugin.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ class PluginHook(Enum):
1818
post_run_pixel_success = 650
1919
post_run_pixel_failed = 651
2020
post_run_all = 700
21-
pre_analysis = 800
22-
analyze_file = 900
23-
analyze_pixel = 1000
24-
post_analysis = 1100
21+
pre_analytics = 800
22+
post_analytics = 900
2523

2624

2725
def register_plugin_function(hook, fun, config, plugins):

pythia/tests/plugin_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ def test_register_with_invalid_hook():
1515
def test_register_with_invalid_fun():
1616
plugins = {}
1717
plugins1 = register_plugin_function(
18-
PluginHook.analyze_file, "not a function", "", plugins
18+
PluginHook.pre_analytics, "not a function", "", plugins
1919
)
2020
assert plugins1 == {}
2121

2222

2323
def test_register_with_invalid_config():
2424
plugins = {}
2525
plugins1 = register_plugin_function(
26-
PluginHook.post_analysis, sample_function, "", plugins
26+
PluginHook.post_analytics, sample_function, "", plugins
2727
)
2828
assert plugins1 == {}
2929

@@ -33,13 +33,13 @@ def test_register_twice():
3333
plugins1 = {}
3434
plugins2 = {}
3535
plugins1 = register_plugin_function(
36-
PluginHook.analyze_file, sample_function, {}, plugins
36+
PluginHook.pre_analytics, sample_function, {}, plugins
3737
)
3838
plugins2 = register_plugin_function(
39-
PluginHook.analyze_file, sample_function, {"a": 1}, plugins1
39+
PluginHook.pre_analytics, sample_function, {"a": 1}, plugins1
4040
)
4141
assert plugins1 == {
42-
PluginHook.analyze_file: [{"fun": sample_function, "config": {}}]
42+
PluginHook.pre_analytics: [{"fun": sample_function, "config": {}}]
4343
}
4444
assert plugins1 == plugins2
4545

0 commit comments

Comments
 (0)