30 lines
958 B
Plaintext
30 lines
958 B
Plaintext
def groupJournalByPathAndState(events):
|
|
"""
|
|
Creates a summary list of dicts with displayPath, eventState, and occurrence count.
|
|
|
|
Returns list sorted by displayPath (alphabetical), then by eventState.
|
|
"""
|
|
if not events:
|
|
return []
|
|
|
|
groups = {} # outer: source → {eventState: count}
|
|
|
|
for event in events:
|
|
|
|
es = event.get('eventState')
|
|
source = event.get('source')
|
|
|
|
# Get or create inner dict
|
|
inner = groups.setdefault(source, {})
|
|
# Increment count (inner.setdefault would also work, but +1 is clearer)
|
|
inner[es] = inner.get(es, 0) + 1
|
|
|
|
# Build flat list of result dictionaries
|
|
result = []
|
|
|
|
for source in sorted(groups.keys()): # sort displayPath alphabetically
|
|
for es in sorted(groups[source].keys()): # sort eventState within each path
|
|
|
|
result.append([source, es, groups[source][es]])
|
|
|
|
return system.dataset.toDataSet(["source", "eventState", "count"], result) |