Skip to content

Commit bbbc7eb

Browse files
committed
feat(history): add an API to get scrolling periods
1 parent e3c7c65 commit bbbc7eb

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

DebuggingSpy-Tests/DSRecordHistoryTest.class.st

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,55 @@ DSRecordHistoryTest >> testBuildWindows [
295295
self assert: (windows at: 8) first name equals: 'StDebugger'.
296296
]
297297

298+
{ #category : 'tests' }
299+
DSRecordHistoryTest >> testCollectScrollingPeriods [
300+
301+
| scrollList |
302+
history records: {
303+
(DSMouseEnterWindowRecord new
304+
dateTime: '2026-03-25T10:01:17' asDateAndTime;
305+
windowId: 1).
306+
(DSScrollingRecord new
307+
dateTime: '2026-03-25T10:02:44' asDateAndTime;
308+
windowId: 1).
309+
(DSScrollingRecord new
310+
dateTime: '2026-03-25T10:06:08' asDateAndTime;
311+
windowId: 1).
312+
(DSScrollingRecord new
313+
dateTime: '2026-03-25T10:09:23' asDateAndTime;
314+
windowId: 1).
315+
(DSScrollingRecord new
316+
dateTime: '2026-03-25T10:13:41' asDateAndTime;
317+
windowId: 1).
318+
(DSMouseLeaveWindowRecord new
319+
dateTime: '2026-03-25T10:20:16' asDateAndTime;
320+
windowId: 1).
321+
(DSMouseEnterWindowRecord new
322+
dateTime: '2026-03-25T10:21:41' asDateAndTime;
323+
windowId: 2).
324+
(DSDoItRecord new
325+
dateTime: '2026-03-25T10:26:09' asDateAndTime;
326+
windowId: 2).
327+
(DSScrollingRecord new
328+
dateTime: '2026-03-25T10:13:41' asDateAndTime;
329+
windowId: 2).
330+
(DSStepIntoRecord new
331+
dateTime: '2026-03-25T10:14:01' asDateAndTime;
332+
windowId: 2) }.
333+
334+
scrollList := history collectScrollingPeriods.
335+
336+
self assert: scrollList size equals: 2.
337+
self assert: scrollList first key equals: {
338+
'2026-03-25T10:02:44' asDateAndTime.
339+
'2026-03-25T10:13:41' asDateAndTime }.
340+
self assert: scrollList first value equals: 1.
341+
self assert: scrollList second key equals: {
342+
'2026-03-25T10:13:41' asDateAndTime.
343+
'2026-03-25T10:13:41' asDateAndTime }.
344+
self assert: scrollList second value equals: 2
345+
]
346+
298347
{ #category : 'tests' }
299348
DSRecordHistoryTest >> testCollectTimeDiscrepancies [
300349

@@ -638,6 +687,56 @@ DSRecordHistoryTest >> testFixWindowRecordKeysNames [
638687
self assert: (windowsHistory keys detect: [ :k | k windowId = 2 ]) windowName isNil
639688
]
640689

690+
{ #category : 'tests' }
691+
DSRecordHistoryTest >> testGetSumOfScrollingPeriods [
692+
693+
| scrollList |
694+
history records: {
695+
(DSMouseEnterWindowRecord new
696+
dateTime: '2026-03-25T10:01:17' asDateAndTime;
697+
windowId: 1).
698+
(DSScrollingRecord new
699+
dateTime: '2026-03-25T10:02:44' asDateAndTime;
700+
windowId: 1).
701+
(DSScrollingRecord new
702+
dateTime: '2026-03-25T10:06:08' asDateAndTime;
703+
windowId: 1).
704+
(DSScrollingRecord new
705+
dateTime: '2026-03-25T10:09:23' asDateAndTime;
706+
windowId: 1).
707+
(DSScrollingRecord new
708+
dateTime: '2026-03-25T10:13:41' asDateAndTime;
709+
windowId: 1).
710+
(DSMouseLeaveWindowRecord new
711+
dateTime: '2026-03-25T10:20:16' asDateAndTime;
712+
windowId: 1).
713+
(DSMouseEnterWindowRecord new
714+
dateTime: '2026-03-25T10:21:41' asDateAndTime;
715+
windowId: 2).
716+
(DSDoItRecord new
717+
dateTime: '2026-03-25T10:26:09' asDateAndTime;
718+
windowId: 2).
719+
(DSScrollingRecord new
720+
dateTime: '2026-03-25T10:13:41' asDateAndTime;
721+
windowId: 2).
722+
(DSStepIntoRecord new
723+
dateTime: '2026-03-25T10:14:01' asDateAndTime;
724+
windowId: 2).
725+
(DSScrollingRecord new
726+
dateTime: '2026-03-25T10:26:35' asDateAndTime;
727+
windowId: 1).
728+
(DSScrollingRecord new
729+
dateTime: '2026-03-25T10:27:39' asDateAndTime;
730+
windowId: 1) }.
731+
732+
733+
scrollList := history getSumOfScrollingPeriods.
734+
735+
self assert: scrollList size equals: 2.
736+
self assert: (scrollList at: 1) equals: (Duration seconds: 721).
737+
self assert: (scrollList at: 2) equals: (Duration seconds: 0)
738+
]
739+
641740
{ #category : 'tests' }
642741
DSRecordHistoryTest >> testMergeContinuousEvents [
643742

DebuggingSpy/DSRecordHistory.class.st

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ DSRecordHistory >> buildWindows [
119119
((w respondsTo: #type) and: [ #( 'Finish' 'Post-task' 'Survey' ) includes: w type ]) or: [ w windowId = -1 ] ] ]
120120
]
121121

122+
{ #category : 'API-history' }
123+
DSRecordHistory >> collectScrollingPeriods [
124+
125+
| i scrollingPeriods |
126+
i := 1.
127+
scrollingPeriods := OrderedCollection new.
128+
129+
[ i <= records size ] whileTrue: [
130+
(records at: i) class = DSScrollingRecord ifTrue: [
131+
| start stop |
132+
start := (records at: i) dateTime.
133+
stop := (records at: i) dateTime.
134+
i := i + 1.
135+
[ i <= records size and: [ (records at: i) class = DSScrollingRecord ] ] whileTrue: [
136+
stop := (records at: i) dateTime.
137+
i := i + 1 ].
138+
scrollingPeriods add: {
139+
start.
140+
stop } -> (records at: i - 1) windowId ].
141+
i := i + 1 ].
142+
143+
^ scrollingPeriods
144+
]
145+
122146
{ #category : 'private - history' }
123147
DSRecordHistory >> collectTimeDiscrepancies [
124148
"Returns a dictionary which contains all delta between two records above than 5s"
@@ -339,6 +363,21 @@ DSRecordHistory >> fixWindowRecordKeysNames [
339363
(self findWindowRecordKeyForID: id) windowName: name ]
340364
]
341365

366+
{ #category : 'API-history' }
367+
DSRecordHistory >> getSumOfScrollingPeriods [
368+
369+
| scrollingPeriods |
370+
scrollingPeriods := self collectScrollingPeriods.
371+
scrollingPeriods := scrollingPeriods collect: [ :association |
372+
association key second - association key first -> association value ].
373+
374+
scrollingPeriods := scrollingPeriods groupedBy: [ :association | association value ].
375+
376+
scrollingPeriods := scrollingPeriods collect: [ :array | array collect: [ :association | association key ] ].
377+
378+
^ scrollingPeriods collect: [ :value | value sum ]
379+
]
380+
342381
{ #category : 'API-history' }
343382
DSRecordHistory >> haltAnalysisMap [
344383

0 commit comments

Comments
 (0)