Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Aggregate events with the same data to display
Browse files Browse the repository at this point in the history
  • Loading branch information
2e3s committed Sep 4, 2019
1 parent f1384b8 commit 535f5d8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

## UI

- (1) Aggregate events by data
- (2) Icon should change depending on the current project
- (4) Projects should be added, removed and edited in a separated UI rather than a config
- (3) Change tray icon depending on a project and its completion
Expand Down
3 changes: 3 additions & 0 deletions spytrack/analyze/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def __init__(self, event: ParentEvent, bucket_type: BucketType) -> None:
super().__init__(event.id, event.timestamp, event.duration, event.data)
self.type = bucket_type

def has_equal_data(self, event: 'Event') -> bool:
return self.stringify_data() == event.stringify_data()

def stringify_data(self) -> str:
result = ''
if 'url' in self.data:
Expand Down
5 changes: 2 additions & 3 deletions spytrack/analyze/matched_event.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from .event import Event


class MatchedEvent:
class MatchedEvent(Event):
project: str
rule_id: str
event: Event

def __init__(self, project: str, rule_id: str, event: Event) -> None:
super().__init__(event, event.type)
self.rule_id = rule_id
self.event = event
self.project = project
2 changes: 1 addition & 1 deletion spytrack/analyze/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self) -> None:
def count_event(self, event: MatchedEvent) -> None:
if event.project not in self.data:
self.data[event.project] = 0
self.data[event.project] += event.event.duration.total_seconds()
self.data[event.project] += event.duration.total_seconds()


def get_pie_chart(matched_events: List[MatchedEvent]) -> PieChartData:
Expand Down
30 changes: 20 additions & 10 deletions spytrack/gui/main_page_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,27 @@ def _update_project_events(self) -> None:
selected_project = selected_items[0].data(Qt.UserRole)
i = 0
items = []
for event in self.last_matched_events[::-1]:
items_duration: Dict[str, float] = {}
selected_events: List[MatchedEvent] = []

for event in reversed(self.last_matched_events):
if event.project == selected_project:
text = ', '.join(["{}={}".format(key, value)
for key, value
in event.event.data.items()])
duration = int(event.event.duration.total_seconds())
text = '{}: {}'.format(duration, text)
items.append(text)
i += 1
if i > 500:
break
data_hash = event.stringify_data()
if data_hash not in items_duration:
items_duration[data_hash] = 0
selected_events.append(event)
items_duration[data_hash] += event.duration.total_seconds()

for event in selected_events:
text = ', '.join(["{}={}".format(key, value)
for key, value
in event.data.items()])
duration = int(items_duration[event.stringify_data()])
text = '{}: {}'.format(duration, text)
items.append(text)
i += 1
if i > 500:
break
self.ui.projectEventsList.addItems(items)

def _run_projects(self, chart_data: PieChartData) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_events_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def test_analyze_events(self) -> None:
matched_check = check_matched_events[i]
matched_event = matched_events[i]
self.assertEqual(matched_check[0],
matched_event.event.data['title'])
matched_event.data['title'])

# Work with a cache with the same result
matched_events = analyzer.match(events, projects)
for i in range(0, len(check_matched_events)):
matched_check = check_matched_events[i]
matched_event = matched_events[i]
self.assertEqual(matched_check[0],
matched_event.event.data['title'])
matched_event.data['title'])

0 comments on commit 535f5d8

Please sign in to comment.