Skip to content

Commit

Permalink
Add GToolkit-Utility-Algorithms package and add it to baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve committed Mar 27, 2024
1 parent b5fd993 commit 8657643
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ BaselineOfGToolkitUtility >> baseline: spec [
package: 'GToolkit-Utility-GitHub';
package: 'GToolkit-Utility-ExtensionMethodsAnalysis';
package: 'GToolkit-Utility-Deprecation';
package: 'GToolkit-Utility-Algorithms';

package: 'GToolkit-Releaser-Logging-Analysis' with: [
spec requires: #('GToolkit-Utility-Logging' ). ];
Expand Down
98 changes: 98 additions & 0 deletions src/GToolkit-Utility-Algorithms/GtBurstAnalyzer.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Class {
#name : #GtBurstAnalyzer,
#superclass : #Object,
#instVars : [
'timeSeries',
'cutoff'
],
#category : #'GToolkit-Utility-Algorithms-Bursts'
}

{ #category : #accessing }
GtBurstAnalyzer >> cutoff [
^ cutoff
]

{ #category : #accessing }
GtBurstAnalyzer >> cutoff: anObject [
cutoff := anObject
]

{ #category : #accessing }
GtBurstAnalyzer >> ensureCutoff [
"default cutoff is double the standard deviation"
self cutoff ifNil: [
cutoff := timeSeries stdev * 2
]
]

{ #category : #accessing }
GtBurstAnalyzer >> gtViewBurstsFor: aView [
<gtView>
^ aView explicit
title: 'Bursts';
priority: 1;
stencil: [ | data maxLines scale chart outliers |
data := GtPlotterDataGroup new
values: (timeSeries collectWithIndex: [ :value :i | i -> value ]).
outliers := self run.
data := data
colored: [ :each |
(outliers anySatisfy: [ :anInterval | anInterval includes: each key ])
ifTrue: [ Color black ]
ifFalse: [ Color veryLightGray ] ].

maxLines := timeSeries max.
scale := GtPlotterLinearScale new domainFrom: 0 to: maxLines.

chart := GtPlotterVerticalBarChart new.
chart
barElement: [ :aGtPlotterContext |
BlElement new
aptitude: (BrGlamorousWithTooltipAptitude
content: [ BrLabel new
text: aGtPlotterContext originalValue value;
aptitude: (BrGlamorousLabelAptitude new padding: (BlInsets all: 1)) ]) ].
chart barHeightScale: scale.
chart barWidthScale constant: 20.
chart barHeightData: [ :eachValue | eachValue value ].
chart amountOfTicks: 10.
chart with: data]
]

{ #category : #accessing }
GtBurstAnalyzer >> run [
| average bursts idx upperBound lowerBound |
average := timeSeries average.
bursts := OrderedCollection new.
idx := 1.
self ensureCutoff.
upperBound := average + cutoff.
lowerBound := average - cutoff.

[ idx < timeSeries size ]
whileTrue: [ | value startIdx |
value := timeSeries at: idx.
startIdx := idx.
[ (value > upperBound or: [ value < lowerBound ])
and: [ idx < timeSeries size ] ]
whileTrue: [ idx := idx + 1.

value := timeSeries at: idx ].

idx > startIdx ifTrue: [ bursts add: (startIdx to: idx) ].

idx := idx + 1 ].

^ bursts
]

{ #category : #accessing }
GtBurstAnalyzer >> timeSeries [
^ timeSeries
]

{ #category : #accessing }
GtBurstAnalyzer >> timeSeries: anObject [
timeSeries := anObject
]
1 change: 1 addition & 0 deletions src/GToolkit-Utility-Algorithms/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'GToolkit-Utility-Algorithms' }

0 comments on commit 8657643

Please sign in to comment.