Skip to content

Commit

Permalink
write audits to machine_vars. backport #914
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed May 7, 2017
1 parent 68e4c9c commit 06ca2a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mpf/plugins/auditor.py
Expand Up @@ -98,6 +98,10 @@ def _initialize(self, **kwargs):
# Add the switches monitor
self.machine.switch_controller.add_monitor(self.audit_switch)

for category, audits in self.current_audits.items():
for name, value in audits.items():
self.machine.create_machine_var("audits_{}_{}".format(category, name), value)

def audit(self, audit_class, event, **kwargs):
"""Called to log an auditable event.
Expand All @@ -117,6 +121,7 @@ def audit(self, audit_class, event, **kwargs):
self.current_audits[audit_class][event] = 0

self.current_audits[audit_class][event] += 1
self.machine.create_machine_var("audits_{}_{}".format(audit_class, event), self.current_audits[audit_class][event])

def audit_switch(self, change: MonitoredSwitchChange):
"""Record switch change."""
Expand Down
4 changes: 4 additions & 0 deletions mpf/tests/test_Auditor.py
Expand Up @@ -32,6 +32,7 @@ def test_auditor_switches(self):
self.advance_time_and_run(1)

self.assertEqual(0, auditor.current_audits['switches']['s_test'])
self.assertMachineVarEqual(0, "audits_switches_s_test")

# start a game
self.machine.switch_controller.process_switch("s_start", 1)
Expand All @@ -53,13 +54,15 @@ def test_auditor_switches(self):
self.assertEqual(None, self.machine.game)

self.assertEqual(1, auditor.current_audits['switches']['s_test'])
self.assertMachineVarEqual(1, "audits_switches_s_test")

self.machine.switch_controller.process_switch("s_test", 1)
self.advance_time_and_run(1)
self.machine.switch_controller.process_switch("s_test", 0)
self.advance_time_and_run(1)

self.assertEqual(1, auditor.current_audits['switches']['s_test'])
self.assertMachineVarEqual(1, "audits_switches_s_test")

auditor.enable()

Expand All @@ -69,6 +72,7 @@ def test_auditor_switches(self):
self.advance_time_and_run(1)

self.assertEqual(2, auditor.current_audits['switches']['s_test'])
self.assertMachineVarEqual(2, "audits_switches_s_test")

# should not crash on unknown switch
self.machine.switch_controller.process_switch_by_num(123123123123, 1, self.machine.default_platform)
Expand Down

0 comments on commit 06ca2a3

Please sign in to comment.