From ffb5756ad2ecb90669d61f9576f02d8a1385be79 Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Tue, 7 May 2024 16:56:40 +0200 Subject: [PATCH] Code refactoring, new collection of all watches when multiverse is created --- .../Sandblocks-Babylonian/Morph.extension.st | 6 +++ .../SBCorrelationView.class.st | 4 +- .../SBExampleWatch.class.st | 14 ------ .../SBExploriants.class.st | 8 +++- .../SBGridResultsView.class.st | 3 +- .../SBMultiverse.class.st | 27 ++++-------- .../SBPlainResultsView.class.st | 2 +- .../SBSwitchableResultsView.class.st | 2 +- .../Sandblocks-Babylonian/SBTrace.class.st | 4 +- .../Sandblocks-Core/Collection.extension.st | 6 +-- .../Sandblocks-Smalltalk/SBVariant.class.st | 12 +++--- .../SBVariantProxy.class.st | 23 ++++++++-- .../Sandblocks-Utils/SBPermutation.class.st | 43 +++++++++++++------ .../Sandblocks-Watch/SBLineChart.class.st | 6 +-- .../Sandblocks-Watch/SBWatchView.class.st | 4 +- 15 files changed, 96 insertions(+), 68 deletions(-) diff --git a/packages/Sandblocks-Babylonian/Morph.extension.st b/packages/Sandblocks-Babylonian/Morph.extension.st index e7970c36..6cea1b56 100644 --- a/packages/Sandblocks-Babylonian/Morph.extension.st +++ b/packages/Sandblocks-Babylonian/Morph.extension.st @@ -12,6 +12,12 @@ Morph class >> exampleObject [ ^ self new ] +{ #category : #'*Sandblocks-Babylonian' } +Morph >> isVariantProxy [ + + ^ false +] + { #category : #'*Sandblocks-Babylonian' } Morph >> listensToPermutations [ diff --git a/packages/Sandblocks-Babylonian/SBCorrelationView.class.st b/packages/Sandblocks-Babylonian/SBCorrelationView.class.st index 47937be3..65a3acaa 100644 --- a/packages/Sandblocks-Babylonian/SBCorrelationView.class.st +++ b/packages/Sandblocks-Babylonian/SBCorrelationView.class.st @@ -29,7 +29,7 @@ SBCorrelationView >> buildForExample: anExample watching: aWatch [ self containerRow listDirection: #topToBottom; addAllMorphsBack: { SBOwnTextMorph new contents: ( - '{1}{2}' format: {"anExample label" ''. + '{1}{2}' format: {anExample label. (aWatch cleanedExpression sourceString withoutLineEndings)}). self containerRow listDirection: #topToBottom; @@ -113,7 +113,7 @@ SBCorrelationView >> changeVariants [ SBCorrelationView >> collectAllPermutationsOfSelectedVariants [ | allPermutations | - selectedVariants ifEmpty: [^ {SBNilPermutation new referencedVariants: {}} asSet]. + selectedVariants ifEmpty: [^ {SBPermutation singularity} asSet]. allPermutations := Set new. groupedUniverses first do: [:aUniverseContainingSelected | | base | base := SBPermutation new referencedVariants: selectedVariants. diff --git a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st index 7856135e..2df882ec 100644 --- a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st @@ -82,7 +82,6 @@ SBExampleWatch class >> report: aValue for: aSymbol modifying: aBlock [ example := SBExecutionEnvironment value ifNil: [^ aValue]. watchers := self registry select: [:watcher | watcher notNil and: [watcher identifier = aSymbol] - and: [watcher ignoreReports not] and: [watcher isActive]]. watchers do: [:watcher | watcher reportValue: aValue asSBWatchValue for: example]. @@ -248,7 +247,6 @@ SBExampleWatch >> exampleFinished: anExample [ SBExampleWatch >> exampleStarting: anExample [ exampleToValues at: anExample put: OrderedCollection new. - self ignoreReports: false. (exampleToDisplay at: anExample ifAbsentPut: [self buildDefaultDisplayFor: anExample]) exampleStarting: anExample; @@ -326,18 +324,6 @@ SBExampleWatch >> identifier: aSymbol [ self world ifNotNil: [self class registerWatch: self] ] -{ #category : #accessing } -SBExampleWatch >> ignoreReports [ - - ^ ignoreReports -] - -{ #category : #accessing } -SBExampleWatch >> ignoreReports: aBoolean [ - - ignoreReports := aBoolean -] - { #category : #initialization } SBExampleWatch >> initialize [ diff --git a/packages/Sandblocks-Babylonian/SBExploriants.class.st b/packages/Sandblocks-Babylonian/SBExploriants.class.st index b213a77c..5ff7562e 100644 --- a/packages/Sandblocks-Babylonian/SBExploriants.class.st +++ b/packages/Sandblocks-Babylonian/SBExploriants.class.st @@ -112,6 +112,12 @@ SBExploriants >> evaluationReceiver [ ^ self object ] +{ #category : #accessing } +SBExploriants >> generationTimeout [ + + ^ 20 seconds +] + { #category : #accessing } SBExploriants >> ignoreUpdate [ @@ -221,7 +227,7 @@ SBExploriants >> updateInBackgroundOnTimeoutRevertTo: theOldMultiverse [ newMultiverse := SBMultiverse bigbangInEditorWithoutKaboom: self sandblockEditor. self namedBlocks do: [:aTab | aTab multiverse: newMultiverse]. [newMultiverse kaboom] - valueWithin: 20 seconds + valueWithin: self generationTimeout onTimeout: [newMultiverse cleanUp. self namedBlocks do: [:aTab | aTab multiverse: theOldMultiverse]]. updateProcess := nil. updateProcessRunning := false. diff --git a/packages/Sandblocks-Babylonian/SBGridResultsView.class.st b/packages/Sandblocks-Babylonian/SBGridResultsView.class.st index c1a41922..40fd8f57 100644 --- a/packages/Sandblocks-Babylonian/SBGridResultsView.class.st +++ b/packages/Sandblocks-Babylonian/SBGridResultsView.class.st @@ -54,5 +54,6 @@ SBGridResultsView >> newGridContainer [ SBGridResultsView >> visualize [ super visualize. - self concludeContainerWidth + self concludeContainerWidth. + ] diff --git a/packages/Sandblocks-Babylonian/SBMultiverse.class.st b/packages/Sandblocks-Babylonian/SBMultiverse.class.st index b981f182..1d0ad11a 100644 --- a/packages/Sandblocks-Babylonian/SBMultiverse.class.st +++ b/packages/Sandblocks-Babylonian/SBMultiverse.class.st @@ -116,10 +116,7 @@ SBMultiverse >> asyncKaboom [ SBMultiverse >> cleanUp [ watches do: #resumeGraphicalUpdates. - (watches select: [:anOpenWatch | anOpenWatch containingArtefact isNil]) copy do: #delete. - watches select: #isInEditor thenDo: [:aWatch | aWatch exampleToDisplay values do: #updateDisplay]. - allMethodBlocksContainingWatches do: [:aMethodBlock | - (aMethodBlock valueOfProperty: #originals) do: [:aWatch| aWatch ignoreReports: false]]. + watches reject: #isInEditor thenDo: [:aWatch | SBExampleWatch unregisterWatch: aWatch]. ] { #category : #collecting } @@ -174,16 +171,9 @@ SBMultiverse >> gatherVariants [ { #category : #'initialize-release' } SBMultiverse >> gatherWatches [ - allMethodBlocksContainingWatches := self findExistingOrConvertToBlocksMaintainingWatches: self allCompiledMethodsContainingExampleWatches. + allMethodBlocksContainingWatches := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches. - watches := (allMethodBlocksContainingWatches collect: [:aMethodBlock | | copies | - copies := aMethodBlock containedExampleWatches. - "Because the watches share the id, values would be reported to original too. Stop that" - (aMethodBlock valueOfProperty: #originals) do: [:aWatch| aWatch ignoreReports: true]. - (aMethodBlock valueOfProperty: #originals) withIndexDo: [:original :i | (copies at: i) copySelectedDisplayIndicesFrom: original]. - copies ]) flatten. - watches do: [:aWatch | activeExamples do: [:anExample | aWatch exampleStarting: anExample]]. - watches reject: #isInEditor thenDo: [:aWatch | aWatch hide. aWatch extent: 1@1] + watches := (allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten. ] @@ -198,15 +188,16 @@ SBMultiverse >> initialize [ { #category : #actions } SBMultiverse >> kaboom [ - | outOfWorldWatches permutations | - "Only open watches display values when examples are run. We want to show them too" - (outOfWorldWatches := watches reject: #isInEditor) do: [:aWatch | self sandblockEditor openMorph: aWatch]. - permutations := (SBPermutation allPermutationsOf: variants). + | permutations | watches do: #stopGraphicalUpdates. + watches reject: #isInEditor thenDo: [:aWatch | + SBExampleWatch registerWatch: aWatch. + activeExamples do: [:anExample | aWatch exampleStarting: anExample]]. + permutations := (SBPermutation allPermutationsOf: variants). "Running the active one last" (permutations sorted: [:a :b | a activeScore <= b activeScore ] ) do: [:aPermutation | - self runPermutation: aPermutation copyingWatches: watches ]. + self runPermutation: aPermutation copyingWatches: watches]. "but stay consistent of the permutation sequences for alignment in clusters" "sorting this is cheaper than running a permutation twice just to reset to prior state" diff --git a/packages/Sandblocks-Babylonian/SBPlainResultsView.class.st b/packages/Sandblocks-Babylonian/SBPlainResultsView.class.st index d22ff1b5..db52c0dc 100644 --- a/packages/Sandblocks-Babylonian/SBPlainResultsView.class.st +++ b/packages/Sandblocks-Babylonian/SBPlainResultsView.class.st @@ -24,5 +24,5 @@ SBPlainResultsView >> initialize [ super initialize. - self name: 'Watches' + self name: 'Probes' ] diff --git a/packages/Sandblocks-Babylonian/SBSwitchableResultsView.class.st b/packages/Sandblocks-Babylonian/SBSwitchableResultsView.class.st index a186cf87..33fe624a 100644 --- a/packages/Sandblocks-Babylonian/SBSwitchableResultsView.class.st +++ b/packages/Sandblocks-Babylonian/SBSwitchableResultsView.class.st @@ -58,7 +58,7 @@ SBSwitchableResultsView >> toggleViewButton [ ^ SBButton new icon: self toggleIcon - label: 'Group By Watches <> In Execution Order' + label: 'Group By Probes <> In Execution Order' do: [self toggleView]; cornerStyle: #squared ] diff --git a/packages/Sandblocks-Babylonian/SBTrace.class.st b/packages/Sandblocks-Babylonian/SBTrace.class.st index 84f0f4d5..5c9c80c0 100644 --- a/packages/Sandblocks-Babylonian/SBTrace.class.st +++ b/packages/Sandblocks-Babylonian/SBTrace.class.st @@ -60,8 +60,8 @@ SBTrace >> sortedWatchValuesFor: anExample givenWatches: aCollectionOfWatches [ | allValues | allValues := SortedCollection sortBlock: [:a :b | a tracePosition <= b tracePosition]. aCollectionOfWatches do: [:aWatch | - aWatch exampleToValues at: anExample - ifPresent: [:aCollectionOfWatchValues | allValues addAll: aCollectionOfWatchValues ] + aWatch exampleToDisplay at: anExample + ifPresent: [:aDisplay | allValues addAll: aDisplay value display watchValues ] ifAbsent: [{}]]. ^ allValues ] diff --git a/packages/Sandblocks-Core/Collection.extension.st b/packages/Sandblocks-Core/Collection.extension.st index af15603e..67f4ef19 100644 --- a/packages/Sandblocks-Core/Collection.extension.st +++ b/packages/Sandblocks-Core/Collection.extension.st @@ -5,7 +5,7 @@ Collection >> asBarChart: converter [ converter - if: [self isString not and: [self allSatisfy: SBBarChart supportedInterface]] + if: [self allSatisfy: SBBarChart supportedInterface] do: [SBBarChart newWithValues: self] ] @@ -23,7 +23,7 @@ Collection >> asLineChart: converter [ converter - if: [self isString not and: [self allSatisfy: SBLineChart supportedInterface]] + if: [self allSatisfy: SBLineChart supportedInterface] do: [SBLineChart newWithValues: self] ] @@ -32,7 +32,7 @@ Collection >> asRectangleChart: converter [ converter - if: [self isString not and: [self isDictionary not and: [self allSatisfy: SBRectangleChart supportedInterface]]] + if: [self allSatisfy: SBRectangleChart supportedInterface] do: [SBRectangleChart newWithValues: self] ] diff --git a/packages/Sandblocks-Smalltalk/SBVariant.class.st b/packages/Sandblocks-Smalltalk/SBVariant.class.st index 73b9a694..bcd767c3 100644 --- a/packages/Sandblocks-Smalltalk/SBVariant.class.st +++ b/packages/Sandblocks-Smalltalk/SBVariant.class.st @@ -181,11 +181,7 @@ SBVariant >> allPermutations: allPermutations currentPath: aPermutation [ ifEmpty: [allPermutations add: currentPath] ifNotEmpty: [:childVariants | | permutations nestedPermutations | nestedPermutations := childVariants collect: [:child | child allPermutations: OrderedCollection new currentPath: currentPath]. - permutations := nestedPermutations first. - (2 to: topLevelVariants size) do: [:index | | nestedPermutation | - nestedPermutation := nestedPermutations at: index. - permutations := permutations gather: [:aNestedPermutation | - nestedPermutation collect: [:aNestedNestedPermutation | SBPermutation newCombinedOf: aNestedPermutation and: aNestedNestedPermutation]]]. + permutations := SBPermutation combineAllIn: nestedPermutations. allPermutations addAll: permutations. permutations ]] ] @@ -263,6 +259,12 @@ SBVariant >> color [ ^ Color transparent ] +{ #category : #accessing } +SBVariant >> hasParent [ + + ^ self parentVariant isNil not +] + { #category : #accessing } SBVariant >> id [ ^ id diff --git a/packages/Sandblocks-Smalltalk/SBVariantProxy.class.st b/packages/Sandblocks-Smalltalk/SBVariantProxy.class.st index 51dd137c..ad38de5d 100644 --- a/packages/Sandblocks-Smalltalk/SBVariantProxy.class.st +++ b/packages/Sandblocks-Smalltalk/SBVariantProxy.class.st @@ -14,6 +14,12 @@ SBVariantProxy class >> for: aVariant [ ^ self new for: aVariant ] +{ #category : #accessing } +SBVariantProxy >> activeIndex [ + + ^ original activeIndex +] + { #category : #callbacks } SBVariantProxy >> artefactChanged: anArtefact [ @@ -60,6 +66,12 @@ SBVariantProxy >> for: aVariant [ self addMorphBack: original copyBlock. ] +{ #category : #accessing } +SBVariantProxy >> id [ + + ^ original id +] + { #category : #initialization } SBVariantProxy >> initialize [ @@ -79,6 +91,12 @@ SBVariantProxy >> isArtefact [ ^ true ] +{ #category : #testing } +SBVariantProxy >> isVariantProxy [ + + ^ true +] + { #category : #accessing } SBVariantProxy >> original [ @@ -106,12 +124,11 @@ SBVariantProxy >> updateOriginalWithOwnValues [ | variantThatNeedsChanging | variantThatNeedsChanging := self containedMethod detectVariant: original. - variantThatNeedsChanging ifNil: [^self delete]. original replaceBy: (original := self firstSubmorph copyBlock). - original isVariant - ifFalse: [ + "If a double click on the widget occured and it replaced itself with code or text" + original isVariant ifFalse: [ self containedMethod save. ^ self delete]. diff --git a/packages/Sandblocks-Utils/SBPermutation.class.st b/packages/Sandblocks-Utils/SBPermutation.class.st index 481021ca..be41683a 100644 --- a/packages/Sandblocks-Utils/SBPermutation.class.st +++ b/packages/Sandblocks-Utils/SBPermutation.class.st @@ -14,19 +14,32 @@ Class { { #category : #utils } SBPermutation class >> allPermutationsOf: aCollectionOfVariants [ - | permutations topLevelVariants nestedPermutations | - aCollectionOfVariants ifEmpty:[^{SBNilPermutation new referencedVariants: {}}]. - topLevelVariants := aCollectionOfVariants select: [:aVariant | aVariant parentVariant isNil]. + | topLevelVariants nestedPermutations | + aCollectionOfVariants ifEmpty:[^{SBPermutation singularity}]. + topLevelVariants := aCollectionOfVariants reject: #hasParent. nestedPermutations := topLevelVariants collect: #allPermutations. - permutations := nestedPermutations first. - (2 to: topLevelVariants size) do: [:i | | nestedPermutation | - nestedPermutation := (nestedPermutations at: i). - permutations := permutations gather: [:aPermutation | - nestedPermutation collect: [:aNestedPermutation | self newCombinedOf: aPermutation and: aNestedPermutation]]]. - - ^ permutations - + ^ SBPermutation combineAllIn: nestedPermutations. +] + +{ #category : #utils } +SBPermutation class >> combine: aPermutation withAll: aCollectionOfPermutations [ + + ^ aCollectionOfPermutations collect: [:anotherPermutation | + self newCombinedOf: aPermutation and: anotherPermutation] +] + +{ #category : #utils } +SBPermutation class >> combineAllIn: aCollectionOfNestedPermutations [ + + | combinedPermutations | + combinedPermutations := aCollectionOfNestedPermutations first. + (2 to: aCollectionOfNestedPermutations size) do: [:index | | aCollectionOfPermutations | + aCollectionOfPermutations := aCollectionOfNestedPermutations at: index. + combinedPermutations := combinedPermutations gather: [:aPermutation | + SBPermutation combine: aPermutation withAll: aCollectionOfPermutations]]. + + ^ combinedPermutations ] { #category : #utils } @@ -42,6 +55,12 @@ SBPermutation class >> newCombinedOf: onePermutation and: anotherPermutation [ ] +{ #category : #utils } +SBPermutation class >> singularity [ + + ^ SBNilPermutation new referencedVariants: {} +] + { #category : #accessing } SBPermutation >> activeScore [ @@ -151,7 +170,7 @@ SBPermutation >> copyRemovingVariants: aCollectionOfVariants [ | copy | copy := self class new. copy referencedVariants: (self referencedVariants reject: [:aVariant | aCollectionOfVariants includes: aVariant]). - copy referencedVariants ifEmpty: [^ SBNilPermutation new referencedVariants: {}]. + copy referencedVariants ifEmpty: [^ SBPermutation singularity]. "copy := self veryDeepCopy. copy referencedVariants: (copy referencedVariants difference: aCollectionOfVariants)." diff --git a/packages/Sandblocks-Watch/SBLineChart.class.st b/packages/Sandblocks-Watch/SBLineChart.class.st index e341c9ec..f07e4e7c 100644 --- a/packages/Sandblocks-Watch/SBLineChart.class.st +++ b/packages/Sandblocks-Watch/SBLineChart.class.st @@ -35,7 +35,7 @@ SBLineChart >> datapointDefaultColor [ { #category : #'visualization - constants' } SBLineChart >> datapointExtent [ - ^ 2@2 + ^ 3@3 sbScaled ] { #category : #geometry } @@ -60,7 +60,7 @@ SBLineChart >> lineColorFrom: aDataPoint1 to: aDataPoint2 [ { #category : #'visualization - constants' } SBLineChart >> lineWidth [ - ^ 2 + ^ 2 sbScaled ] { #category : #'visualization - constants' } @@ -166,7 +166,7 @@ SBLineChart >> positiveGradientColor [ { #category : #'visualization - constants' } SBLineChart >> spaceBetweenPoints [ - ^ 6 + ^ 6 sbScaled ] { #category : #visualization } diff --git a/packages/Sandblocks-Watch/SBWatchView.class.st b/packages/Sandblocks-Watch/SBWatchView.class.st index da79ce91..2fabfc8c 100644 --- a/packages/Sandblocks-Watch/SBWatchView.class.st +++ b/packages/Sandblocks-Watch/SBWatchView.class.st @@ -263,7 +263,7 @@ SBWatchView >> layoutCommands [ { #category : #layout } SBWatchView >> maxWidth [ - ^ 350 + ^ 350 sbScaled ] { #category : #'object interface' } @@ -309,7 +309,7 @@ SBWatchView >> reportValues: aCollectionOfWatchValues sized: aMorphResizer [ SBWatchView >> resetOnlyValues [ "Private" - count contents: '0'. + shouldUpdateDisplay ifTrue: [count contents: '0']. watchValues := LinkedList new. ]