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.
|
export.
|
||||||
^ self
|
^ self
|
||||||
].
|
].
|
||||||
quotesOccurrences := self quotesSortedByOccurrences.
|
quotesOccurrences := self quotes asMessagesUserNamesSortedByOccurrences.
|
||||||
labels := quotesOccurrences keys.
|
labels := quotesOccurrences keys.
|
||||||
labels := labels collect: [ :profiles | ('@', profiles) ].
|
labels := labels collect: [ :profiles | ('@', profiles) ].
|
||||||
quotesHistogram := RSChart new.
|
quotesHistogram := RSChart new.
|
||||||
|
@ -2,7 +2,7 @@ accessing
|
|||||||
exportQuotesHistogramWithBars: aNumberOfBars
|
exportQuotesHistogramWithBars: aNumberOfBars
|
||||||
|
|
||||||
| keysToRemove quotes labels quotesHistogram diagram |
|
| keysToRemove quotes labels quotesHistogram diagram |
|
||||||
quotes := self quotesSortedByOccurrences.
|
quotes := self quotes asMessagesUserNamesSortedByOccurrences.
|
||||||
(aNumberOfBars > quotes size) ifTrue: [ ^ self exportQuotesHistogram ].
|
(aNumberOfBars > quotes size) ifTrue: [ ^ self exportQuotesHistogram ].
|
||||||
keysToRemove := OrderedCollection new.
|
keysToRemove := OrderedCollection new.
|
||||||
1 to: quotes size - aNumberOfBars do:
|
1 to: quotes size - aNumberOfBars do:
|
||||||
|
@ -1,44 +1,10 @@
|
|||||||
accessing
|
accessing
|
||||||
exportRepliesHistogramWithBars: aNumberOfBars
|
exportRepliesHistogramWithBars: aNumberOfBars
|
||||||
|
|
||||||
| tweetsByTimeSpan subtotals tweetsHistogram diagram |
|
| repliesDict |
|
||||||
|
repliesDict := {
|
||||||
self replies ifEmpty: [
|
'messagesType' -> 'replies'.
|
||||||
tweetsHistogram := RSChart new.
|
'extent' -> (800@200).
|
||||||
tweetsHistogram extent: 800@200.
|
'color' -> (Color r:(246/255) g:(185/255) b:(46/255))
|
||||||
tweetsHistogram build.
|
} asDictionary.
|
||||||
tweetsHistogram canvas pdfExporter
|
^ self exportHistogramFor: repliesDict By: aNumberOfBars
|
||||||
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'
|
|
@ -3,7 +3,7 @@ exportRetweetsHistogram
|
|||||||
|
|
||||||
| retweetsOccurrences labels retweetColor diagram retweetsHistogram |
|
| retweetsOccurrences labels retweetColor diagram retweetsHistogram |
|
||||||
|
|
||||||
retweetsOccurrences := self retweetsSortedByOccurrences.
|
retweetsOccurrences := self retweets asMessagesUserNamesSortedByOccurrences.
|
||||||
retweetColor := (Color r:(217/255) g:(56/255) b: (124/255)).
|
retweetColor := (Color r:(217/255) g:(56/255) b: (124/255)).
|
||||||
labels := retweetsOccurrences keys.
|
labels := retweetsOccurrences keys.
|
||||||
labels := labels collect: [ :profiles | ('@', profiles) ].
|
labels := labels collect: [ :profiles | ('@', profiles) ].
|
||||||
|
@ -2,7 +2,7 @@ accessing
|
|||||||
exportRetweetsHistogramWithBars: aNumberOfBars
|
exportRetweetsHistogramWithBars: aNumberOfBars
|
||||||
|
|
||||||
| keysToRemove retweets labels retweetsHistogram diagram |
|
| keysToRemove retweets labels retweetsHistogram diagram |
|
||||||
retweets := self retweetsSortedByOccurrences.
|
retweets := self retweets asMessagesUserNamesSortedByOccurrences.
|
||||||
(aNumberOfBars > retweets size) ifTrue: [ ^ self exportRetweetsHistogram ].
|
(aNumberOfBars > retweets size) ifTrue: [ ^ self exportRetweetsHistogram ].
|
||||||
keysToRemove := OrderedCollection new.
|
keysToRemove := OrderedCollection new.
|
||||||
1 to: retweets size - aNumberOfBars do:
|
1 to: retweets size - aNumberOfBars do:
|
||||||
|
@ -1,35 +1,10 @@
|
|||||||
accessing
|
accessing
|
||||||
exportTweetsHistogramWithBars: aNumberOfBars
|
exportTweetsHistogramWithBars: aNumberOfBars
|
||||||
|
|
||||||
| tweetsByTimeSpan subtotals tweetsHistogram diagram |
|
| tweetsDict |
|
||||||
|
tweetsDict := {
|
||||||
self tweets ifEmpty: [
|
'messagesType' -> 'tweets'.
|
||||||
tweetsHistogram := RSChart new.
|
'extent' -> (800@200).
|
||||||
tweetsHistogram extent: 800@200.
|
'color' -> (Color r:(91/255) g:(131/255) b:(222/255))
|
||||||
tweetsHistogram build.
|
} asDictionary.
|
||||||
tweetsHistogram canvas pdfExporter
|
^ self exportHistogramFor: tweetsDict By: aNumberOfBars
|
||||||
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
|
|
@ -2,7 +2,7 @@ accessing
|
|||||||
quotesReportData
|
quotesReportData
|
||||||
|
|
||||||
| tempDict labels xAxis |
|
| tempDict labels xAxis |
|
||||||
tempDict := self quotesSortedByOccurrences.
|
tempDict := self quotes asMessagesUserNamesSortedByOccurrences.
|
||||||
|
|
||||||
tempDict size > 10 ifTrue: [
|
tempDict size > 10 ifTrue: [
|
||||||
tempDict := (tempDict associations copyFrom: 1 to: 10) asOrderedDictionary ].
|
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
|
retweetsReportData
|
||||||
|
|
||||||
| tempDict labels xAxis |
|
| tempDict labels xAxis |
|
||||||
tempDict := self retweetsSortedByOccurrences.
|
tempDict := self retweets asMessagesUserNamesSortedByOccurrences.
|
||||||
|
|
||||||
tempDict size > 10 ifTrue: [
|
tempDict size > 10 ifTrue: [
|
||||||
tempDict := (tempDict associations copyFrom: 1 to: 10) asOrderedDictionary ].
|
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