Refactoring quotes and retweets histograms.

This commit is contained in:
ruidajo 2022-06-21 13:20:46 -05:00
parent ff38d34dc4
commit 485572a81e
5 changed files with 46 additions and 132 deletions

View File

@ -1,30 +1,49 @@
accessing accessing
exportHistogramFor: aDictionary By: aTypeString exportHistogramFor: aDictionary By: aTypeString
"TODO: quotes and retweets" "TODO: quotes and retweets"
| messagesByTimeSpan histogram diagram tempMessages | | messagesDict histogram diagram tempMessages labels subtotals |
tempMessages := self perform: (aDictionary at: 'messagesType') asSymbol. tempMessages := self perform: (aDictionary at: 'messagesType') asSymbol.
tempMessages ifEmpty: [ self exportEmptyHistogramNamed: tempMessages ifEmpty: [ self exportEmptyHistogramNamed:
(aDictionary at: 'messagesType'), '-histogram' ]. (aDictionary at: 'messagesType'), '-histogram' ].
aTypeString isNumber ifTrue: [ messagesByTimeSpan := tempMessages splitBytimeSpansOf: aTypeString ].
((((aDictionary at: 'messagesType') = 'tweets') or: [(aDictionary at: 'messagesType') = 'replies'])
and: aTypeString isNumber)
ifTrue: [ messagesDict := tempMessages splitBytimeSpansOf: aTypeString ].
(aTypeString = 'day' or: [ aTypeString = 'days' ]) (aTypeString = 'day' or: [ aTypeString = 'days' ])
ifTrue: [ messagesByTimeSpan := tempMessages splitByDays ]. ifTrue: [ messagesDict := tempMessages splitByDays ].
(aTypeString = 'week' or: [ aTypeString = 'weeks' ]) (aTypeString = 'week' or: [ aTypeString = 'weeks' ])
ifTrue: [ messagesByTimeSpan := tempMessages splitByWeeks ]. ifTrue: [ messagesDict := tempMessages splitByWeeks ].
(((aDictionary at: 'messagesType') = 'retweets') or: [ (aDictionary at: 'messagesType') = 'quotes' ])
ifTrue: [
messagesDict := tempMessages asMessagesUserNamesSortedByOccurrences.
((aTypeString > messagesDict size) or: [ aTypeString = 1 ])
ifFalse: [ | keysToRemove |
keysToRemove := OrderedCollection new.
1 to: messagesDict size - aTypeString do:
[ :i | keysToRemove add: (messagesDict keys at: i + aTypeString) ].
messagesDict removeKeys: keysToRemove. ].
labels := messagesDict keys.
labels := labels collect: [ :profiles | ('@', profiles) ].
subtotals := messagesDict values
]
ifFalse: [ labels := messagesDict keys.
subtotals := (messagesDict values collect: [ :collection | collection size ])].
histogram := RSChart new. histogram := RSChart new.
histogram extent: (aDictionary at: 'extent'). histogram extent: (aDictionary at: 'extent').
diagram := RSBarPlot new diagram := RSBarPlot new
y: (messagesByTimeSpan values collect: [ :collection | collection size ]). y: subtotals.
"diagram color: (Color r:(91/255) g:(131/255) b:(222/255))."
diagram color: (aDictionary at: 'color'). diagram color: (aDictionary at: 'color').
histogram addPlot: diagram. histogram addPlot: diagram.
histogram addDecoration: (RSHorizontalTick new histogram addDecoration: (RSHorizontalTick new
fromNames: messagesByTimeSpan keys; fromNames: labels;
labelRotation: 0; labelRotation: 0;
fontSize: 68 /messagesByTimeSpan size; fontSize: 68 /messagesDict size;
yourself). yourself).
histogram addDecoration: (RSVerticalTick new histogram addDecoration: (RSVerticalTick new
integer; integer;
fontSize: 68 /messagesByTimeSpan size). fontSize: 68 /messagesDict size).
histogram build. histogram build.
^ histogram canvas exportAsFileNamed: (aDictionary at: 'messagesType'), '-histogram' into: self folder ^ histogram canvas exportAsFileNamed: (aDictionary at: 'messagesType'), '-histogram' into: self folder

View File

@ -1,46 +0,0 @@
accessing
exportQuotesHistogram
| quotesOccurrences labels diagram quotesHistogram |
self quotes ifEmpty: [
quotesHistogram := RSChart new.
quotesHistogram extent: 800@200.
quotesHistogram build.
quotesHistogram canvas pdfExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'quotes-histogram.pdf')fullName;
export.
^ self
].
quotesOccurrences := self quotes asMessagesUserNamesSortedByOccurrences.
labels := quotesOccurrences keys.
labels := labels collect: [ :profiles | ('@', profiles) ].
quotesHistogram := RSChart new.
quotesHistogram extent: 800@200.
diagram := RSBarPlot new
y: quotesOccurrences values.
diagram color: (Color r:(89/255) g:(217/255) b:(95/255)).
quotesHistogram addPlot: diagram.
quotesHistogram addDecoration: (RSHorizontalTick new
fromNames: labels;
labelRotation: 0;
fontSize: 72 /quotesOccurrences size;
yourself).
quotesHistogram addDecoration: (RSVerticalTick new
asFloat: 2;
fontSize: 72 /quotesOccurrences size).
quotesHistogram build.
quotesHistogram canvas pdfExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'quotes-histogram.pdf')fullName;
export.
quotesHistogram canvas pngExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'quotes-histogram.png')fullName;
export.
^ self folder / 'quotes-histogram.png'

View File

@ -1,7 +1,16 @@
accessing accessing
exportQuotesHistogramWithBars: aNumberOfBars exportQuotesHistogramWithBars: aNumberOfBars
| keysToRemove quotes labels quotesHistogram diagram | | quotesDict |
quotesDict := {
'messagesType' -> 'quotes'.
'extent' -> (800@200).
'color' -> (Color r:(89/255) g:(217/255) b:(95/255))
} asDictionary.
^ self exportHistogramFor: quotesDict By: aNumberOfBars
"| keysToRemove quotes labels quotesHistogram diagram |
quotes := self quotes asMessagesUserNamesSortedByOccurrences. quotes := self quotes asMessagesUserNamesSortedByOccurrences.
(aNumberOfBars > quotes size) ifTrue: [ ^ self exportQuotesHistogram ]. (aNumberOfBars > quotes size) ifTrue: [ ^ self exportQuotesHistogram ].
keysToRemove := OrderedCollection new. keysToRemove := OrderedCollection new.
@ -37,4 +46,4 @@ exportQuotesHistogramWithBars: aNumberOfBars
noFixedShapes; noFixedShapes;
fileName: (self folder / 'quotes-histogram.png')fullName; fileName: (self folder / 'quotes-histogram.png')fullName;
export. export.
^ self folder / 'quotes-histogram.png' ^ self folder / 'quotes-histogram.png'"

View File

@ -1,37 +0,0 @@
accessing
exportRetweetsHistogram
| retweetsOccurrences labels retweetColor diagram retweetsHistogram |
retweetsOccurrences := self retweets asMessagesUserNamesSortedByOccurrences.
retweetColor := (Color r:(217/255) g:(56/255) b: (124/255)).
labels := retweetsOccurrences keys.
labels := labels collect: [ :profiles | ('@', profiles) ].
retweetsHistogram := RSChart new.
retweetsHistogram extent: 800@200.
diagram := RSBarPlot new
x: (1 to: retweetsOccurrences size)
y: retweetsOccurrences values.
diagram color: retweetColor.
retweetsHistogram addPlot: diagram.
retweetsHistogram addDecoration: (RSHorizontalTick new
fromNames: labels;
labelRotation: 0;
fontSize: 72 /retweetsOccurrences size;
yourself).
retweetsHistogram addDecoration: (RSVerticalTick new
integer;
fontSize: 72 /retweetsOccurrences size).
retweetsHistogram build.
retweetsHistogram canvas pdfExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'retweets-histogram.pdf')fullName;
export.
retweetsHistogram canvas pngExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'retweets-histogram.png')fullName;
export.
^ self folder / 'retweets-histogram.png'

View File

@ -1,41 +1,10 @@
accessing accessing
exportRetweetsHistogramWithBars: aNumberOfBars exportRetweetsHistogramWithBars: aNumberOfBars
| keysToRemove retweets labels retweetsHistogram diagram | | retweetsDict |
retweets := self retweets asMessagesUserNamesSortedByOccurrences. retweetsDict := {
(aNumberOfBars > retweets size) ifTrue: [ ^ self exportRetweetsHistogram ]. 'messagesType' -> 'retweets'.
keysToRemove := OrderedCollection new. 'extent' -> (800@200).
1 to: retweets size - aNumberOfBars do: 'color' -> (Color r:(217/255) g:(56/255) b: (124/255))
[ :i | keysToRemove add: (retweets keys at: i + aNumberOfBars) ]. } asDictionary.
retweets removeKeys: keysToRemove. ^ self exportHistogramFor: retweetsDict By: aNumberOfBars
labels := retweets keys.
labels := labels collect: [ :profiles | ('@', profiles) ].
retweetsHistogram := RSChart new.
retweetsHistogram extent: 800@200.
diagram := RSBarPlot new
x: (1 to: retweets size)
y: retweets values.
diagram color: (Color r:(217/255) g:(56/255) b: (124/255)).
retweetsHistogram addPlot: diagram.
retweetsHistogram addDecoration: (RSHorizontalTick new
fromNames: labels;
labelRotation: 0;
fontSize: 72 /retweets size;
yourself).
retweetsHistogram addDecoration: (RSVerticalTick new
integer;
fontSize: 72 /retweets size).
retweetsHistogram build.
retweetsHistogram canvas pdfExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'retweets-histogram.pdf')fullName;
export.
retweetsHistogram canvas pngExporter
zoomToShapes;
noFixedShapes;
fileName: (self folder / 'retweets-histogram.png')fullName;
export.
^ self folder / 'retweets-histogram.png'