Refactoring histograms data calculation and exporters.
This commit is contained in:
parent
4d439283b1
commit
ff38d34dc4
@ -0,0 +1,9 @@
|
||||
accessing
|
||||
exportEmptyHistogramNamed: aDictionary
|
||||
|
||||
| histogram |
|
||||
histogram := RSChart new.
|
||||
histogram extent: (aDictionary at: 'extent').
|
||||
histogram build.
|
||||
histogram canvas exportAsFileNamed: (aDictionary at: 'messagesType'), '-histogram' into: self folder.
|
||||
^ self
|
@ -0,0 +1,30 @@
|
||||
accessing
|
||||
exportHistogramFor: aDictionary By: aTypeString
|
||||
"TODO: quotes and retweets"
|
||||
| messagesByTimeSpan histogram diagram tempMessages |
|
||||
tempMessages := self perform: (aDictionary at: 'messagesType') asSymbol.
|
||||
tempMessages ifEmpty: [ self exportEmptyHistogramNamed:
|
||||
(aDictionary at: 'messagesType'), '-histogram' ].
|
||||
aTypeString isNumber ifTrue: [ messagesByTimeSpan := tempMessages splitBytimeSpansOf: aTypeString ].
|
||||
(aTypeString = 'day' or: [ aTypeString = 'days' ])
|
||||
ifTrue: [ messagesByTimeSpan := tempMessages splitByDays ].
|
||||
(aTypeString = 'week' or: [ aTypeString = 'weeks' ])
|
||||
ifTrue: [ messagesByTimeSpan := tempMessages splitByWeeks ].
|
||||
|
||||
histogram := RSChart new.
|
||||
histogram extent: (aDictionary at: 'extent').
|
||||
diagram := RSBarPlot new
|
||||
y: (messagesByTimeSpan values collect: [ :collection | collection size ]).
|
||||
"diagram color: (Color r:(91/255) g:(131/255) b:(222/255))."
|
||||
diagram color: (aDictionary at: 'color').
|
||||
histogram addPlot: diagram.
|
||||
histogram addDecoration: (RSHorizontalTick new
|
||||
fromNames: messagesByTimeSpan keys;
|
||||
labelRotation: 0;
|
||||
fontSize: 68 /messagesByTimeSpan size;
|
||||
yourself).
|
||||
histogram addDecoration: (RSVerticalTick new
|
||||
integer;
|
||||
fontSize: 68 /messagesByTimeSpan size).
|
||||
histogram build.
|
||||
^ histogram canvas exportAsFileNamed: (aDictionary at: 'messagesType'), '-histogram' into: self folder
|
@ -14,7 +14,7 @@ exportQuotesHistogram
|
||||
export.
|
||||
^ self
|
||||
].
|
||||
quotesOccurrences := self quotesSortedByOccurrences.
|
||||
quotesOccurrences := self quotes asMessagesUserNamesSortedByOccurrences.
|
||||
labels := quotesOccurrences keys.
|
||||
labels := labels collect: [ :profiles | ('@', profiles) ].
|
||||
quotesHistogram := RSChart new.
|
||||
|
@ -2,7 +2,7 @@ accessing
|
||||
exportQuotesHistogramWithBars: aNumberOfBars
|
||||
|
||||
| keysToRemove quotes labels quotesHistogram diagram |
|
||||
quotes := self quotesSortedByOccurrences.
|
||||
quotes := self quotes asMessagesUserNamesSortedByOccurrences.
|
||||
(aNumberOfBars > quotes size) ifTrue: [ ^ self exportQuotesHistogram ].
|
||||
keysToRemove := OrderedCollection new.
|
||||
1 to: quotes size - aNumberOfBars do:
|
||||
|
@ -1,44 +1,10 @@
|
||||
accessing
|
||||
exportRepliesHistogramWithBars: aNumberOfBars
|
||||
|
||||
| tweetsByTimeSpan subtotals tweetsHistogram diagram |
|
||||
|
||||
self replies ifEmpty: [
|
||||
tweetsHistogram := RSChart new.
|
||||
tweetsHistogram extent: 800@200.
|
||||
tweetsHistogram build.
|
||||
tweetsHistogram canvas pdfExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'replies-histogram.pdf')fullName;
|
||||
export.
|
||||
^ self
|
||||
].
|
||||
tweetsByTimeSpan := self collectMessages: [ self replies ] byTimeSpanSplits: aNumberOfBars.
|
||||
subtotals := tweetsByTimeSpan values collect: [ :collection | collection size ].
|
||||
tweetsHistogram := RSChart new.
|
||||
tweetsHistogram extent: 800@200.
|
||||
diagram := RSBarPlot new
|
||||
y:subtotals.
|
||||
diagram color: (Color r:(246/255) g:(185/255) b:(46/255)).
|
||||
tweetsHistogram addPlot: diagram.
|
||||
tweetsHistogram addDecoration: (RSHorizontalTick new
|
||||
fromNames: tweetsByTimeSpan keys;
|
||||
labelRotation: 0;
|
||||
fontSize: 72 /aNumberOfBars;
|
||||
yourself).
|
||||
tweetsHistogram addDecoration: (RSVerticalTick new
|
||||
asFloat: 2;
|
||||
fontSize: 72 /aNumberOfBars).
|
||||
tweetsHistogram build.
|
||||
tweetsHistogram canvas pngExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'replies-histogram.png')fullName;
|
||||
export.
|
||||
tweetsHistogram canvas pdfExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'replies-histogram.pdf')fullName;
|
||||
export.
|
||||
^ self folder / 'replies-histogram.png'
|
||||
| repliesDict |
|
||||
repliesDict := {
|
||||
'messagesType' -> 'replies'.
|
||||
'extent' -> (800@200).
|
||||
'color' -> (Color r:(246/255) g:(185/255) b:(46/255))
|
||||
} asDictionary.
|
||||
^ self exportHistogramFor: repliesDict By: aNumberOfBars
|
@ -3,7 +3,7 @@ exportRetweetsHistogram
|
||||
|
||||
| retweetsOccurrences labels retweetColor diagram retweetsHistogram |
|
||||
|
||||
retweetsOccurrences := self retweetsSortedByOccurrences.
|
||||
retweetsOccurrences := self retweets asMessagesUserNamesSortedByOccurrences.
|
||||
retweetColor := (Color r:(217/255) g:(56/255) b: (124/255)).
|
||||
labels := retweetsOccurrences keys.
|
||||
labels := labels collect: [ :profiles | ('@', profiles) ].
|
||||
|
@ -2,7 +2,7 @@ accessing
|
||||
exportRetweetsHistogramWithBars: aNumberOfBars
|
||||
|
||||
| keysToRemove retweets labels retweetsHistogram diagram |
|
||||
retweets := self retweetsSortedByOccurrences.
|
||||
retweets := self retweets asMessagesUserNamesSortedByOccurrences.
|
||||
(aNumberOfBars > retweets size) ifTrue: [ ^ self exportRetweetsHistogram ].
|
||||
keysToRemove := OrderedCollection new.
|
||||
1 to: retweets size - aNumberOfBars do:
|
||||
|
@ -1,35 +1,10 @@
|
||||
accessing
|
||||
exportTweetsHistogramWithBars: aNumberOfBars
|
||||
|
||||
| tweetsByTimeSpan subtotals tweetsHistogram diagram |
|
||||
|
||||
self tweets ifEmpty: [
|
||||
tweetsHistogram := RSChart new.
|
||||
tweetsHistogram extent: 800@200.
|
||||
tweetsHistogram build.
|
||||
tweetsHistogram canvas pdfExporter
|
||||
zoomToShapes;
|
||||
noFixedShapes;
|
||||
fileName: (self folder / 'tweets-histogram.pdf')fullName;
|
||||
export.
|
||||
^ {self. 'self tweets is empty'}
|
||||
].
|
||||
|
||||
tweetsByTimeSpan := self collectMessages: [ self tweets] byTimeSpanSplits: aNumberOfBars.
|
||||
subtotals := tweetsByTimeSpan values collect: [ :collection | collection size ].
|
||||
tweetsHistogram := RSChart new.
|
||||
tweetsHistogram extent: 800@200.
|
||||
diagram := RSBarPlot new
|
||||
y:subtotals.
|
||||
diagram color: (Color r:(91/255) g:(131/255) b:(222/255)).
|
||||
tweetsHistogram addPlot: diagram.
|
||||
tweetsHistogram addDecoration: (RSHorizontalTick new
|
||||
fromNames: tweetsByTimeSpan keys;
|
||||
labelRotation: 0;
|
||||
fontSize: 72 /aNumberOfBars;
|
||||
yourself).
|
||||
tweetsHistogram addDecoration: (RSVerticalTick new
|
||||
integer;
|
||||
fontSize: 72 /aNumberOfBars).
|
||||
tweetsHistogram build.
|
||||
^ tweetsHistogram canvas exportAsFileNamed: 'tweets-histogram' into: self folder
|
||||
| tweetsDict |
|
||||
tweetsDict := {
|
||||
'messagesType' -> 'tweets'.
|
||||
'extent' -> (800@200).
|
||||
'color' -> (Color r:(91/255) g:(131/255) b:(222/255))
|
||||
} asDictionary.
|
||||
^ self exportHistogramFor: tweetsDict By: aNumberOfBars
|
@ -2,7 +2,7 @@ accessing
|
||||
quotesReportData
|
||||
|
||||
| tempDict labels xAxis |
|
||||
tempDict := self quotesSortedByOccurrences.
|
||||
tempDict := self quotes asMessagesUserNamesSortedByOccurrences.
|
||||
|
||||
tempDict size > 10 ifTrue: [
|
||||
tempDict := (tempDict associations copyFrom: 1 to: 10) asOrderedDictionary ].
|
||||
|
@ -1,9 +0,0 @@
|
||||
accessing
|
||||
quotesSortedByOccurrences
|
||||
|
||||
| response quotesUserOccurrences |
|
||||
quotesUserOccurrences := (self quotes messages collect: [ :tweet | ((tweet metadata at: 'quote') splitOn: '/') first ]) asBag contents asDictionary.
|
||||
response := OrderedDictionary new.
|
||||
(quotesUserOccurrences associations asSortedCollection: [:x :y | x value > y value])
|
||||
collect: [:assoc | response at: assoc key put:assoc value].
|
||||
^ response
|
@ -2,7 +2,7 @@ accessing
|
||||
retweetsReportData
|
||||
|
||||
| tempDict labels xAxis |
|
||||
tempDict := self retweetsSortedByOccurrences.
|
||||
tempDict := self retweets asMessagesUserNamesSortedByOccurrences.
|
||||
|
||||
tempDict size > 10 ifTrue: [
|
||||
tempDict := (tempDict associations copyFrom: 1 to: 10) asOrderedDictionary ].
|
||||
|
@ -1,9 +0,0 @@
|
||||
accessing
|
||||
retweetsSortedByOccurrences
|
||||
|
||||
| response retweetsOccurrences |
|
||||
retweetsOccurrences := (self retweets messages collect: [ :tweet | tweet user userName ]) asBag contents asDictionary.
|
||||
response := OrderedDictionary new.
|
||||
(retweetsOccurrences associations asSortedCollection: [:x :y | x value > y value])
|
||||
collect: [:assoc | response at: assoc key put:assoc value].
|
||||
^ response
|
@ -0,0 +1,9 @@
|
||||
accessing
|
||||
asMessagesUserNamesSortedByOccurrences
|
||||
|
||||
| response messagesOccurrences |
|
||||
messagesOccurrences := (self collect: [ :tweet | tweet user userName ]) asBag contents asDictionary.
|
||||
response := OrderedDictionary new.
|
||||
(messagesOccurrences associations asSortedCollection: [:x :y | x value > y value])
|
||||
collect: [:assoc | response at: assoc key put:assoc value].
|
||||
^ response
|
Loading…
Reference in New Issue
Block a user