|
1 | 1 | import random |
2 | 2 | import unittest |
3 | 3 | from datetime import date, datetime, timedelta, timezone |
| 4 | +from unittest.mock import patch |
4 | 5 |
|
5 | 6 | from pm4py.util.business_hours import ( |
6 | 7 | BusinessHours, |
@@ -58,6 +59,49 @@ def test_performance_dfg_uses_business_days_in_labels(self): |
58 | 59 |
|
59 | 60 | self.assertIn('label="4D"', graph.source) |
60 | 61 |
|
| 62 | + def test_discovered_performance_dfg_retains_business_hour_slots(self): |
| 63 | + import pm4py |
| 64 | + from pm4py.discovery import discover_performance_dfg |
| 65 | + from pm4py.objects.log.obj import Event, EventLog, Trace |
| 66 | + |
| 67 | + slots = weekday_slots(8, 16) |
| 68 | + trace = Trace( |
| 69 | + [ |
| 70 | + Event( |
| 71 | + { |
| 72 | + "concept:name": "start", |
| 73 | + "time:timestamp": datetime(2025, 1, 7, 8), |
| 74 | + } |
| 75 | + ), |
| 76 | + Event( |
| 77 | + { |
| 78 | + "concept:name": "finish", |
| 79 | + "time:timestamp": datetime(2025, 1, 10, 16), |
| 80 | + } |
| 81 | + ), |
| 82 | + ] |
| 83 | + ) |
| 84 | + |
| 85 | + dfg, start_activities, end_activities = discover_performance_dfg( |
| 86 | + EventLog([trace]), |
| 87 | + business_hours=True, |
| 88 | + business_hour_slots=slots, |
| 89 | + perf_aggregation_key="median", |
| 90 | + ) |
| 91 | + with patch("pm4py.visualization.dfg.visualizer.view") as view: |
| 92 | + pm4py.view_performance_dfg( |
| 93 | + dfg, |
| 94 | + start_activities, |
| 95 | + end_activities, |
| 96 | + aggregation_measure="median", |
| 97 | + ) |
| 98 | + graph = view.call_args.args[0] |
| 99 | + |
| 100 | + self.assertIsInstance(dfg, dict) |
| 101 | + self.assertEqual(4 * 8 * 60 * 60, dfg[("start", "finish")]) |
| 102 | + self.assertEqual(tuple(slots), dfg.business_hour_slots) |
| 103 | + self.assertIn('label="4D"', graph.source) |
| 104 | + |
61 | 105 | def test_variant_duration_uses_configured_working_day(self): |
62 | 106 | from pm4py.visualization.variants_duration.variants.classic import ( |
63 | 107 | _format_duration, |
|
0 commit comments