From 485572a81eddfb96f70d60bf5767c7193ff0f11d Mon Sep 17 00:00:00 2001 From: ruidajo Date: Tue, 21 Jun 2022 13:20:46 -0500 Subject: [PATCH] Refactoring quotes and retweets histograms. --- .../instance/exportHistogramFor.By..st | 37 +++++++++++---- .../instance/exportQuotesHistogram.st | 46 ------------------- .../exportQuotesHistogramWithBars..st | 13 +++++- .../instance/exportRetweetsHistogram.st | 37 --------------- .../exportRetweetsHistogramWithBars..st | 45 +++--------------- 5 files changed, 46 insertions(+), 132 deletions(-) delete mode 100644 Socialmetrica.package/NitterUser.class/instance/exportQuotesHistogram.st delete mode 100644 Socialmetrica.package/NitterUser.class/instance/exportRetweetsHistogram.st diff --git a/Socialmetrica.package/NitterUser.class/instance/exportHistogramFor.By..st b/Socialmetrica.package/NitterUser.class/instance/exportHistogramFor.By..st index 469ed68..993fca0 100644 --- a/Socialmetrica.package/NitterUser.class/instance/exportHistogramFor.By..st +++ b/Socialmetrica.package/NitterUser.class/instance/exportHistogramFor.By..st @@ -1,30 +1,49 @@ accessing exportHistogramFor: aDictionary By: aTypeString "TODO: quotes and retweets" - | messagesByTimeSpan histogram diagram tempMessages | + | messagesDict histogram diagram tempMessages labels subtotals | tempMessages := self perform: (aDictionary at: 'messagesType') asSymbol. + tempMessages ifEmpty: [ self exportEmptyHistogramNamed: (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' ]) - ifTrue: [ messagesByTimeSpan := tempMessages splitByDays ]. + ifTrue: [ messagesDict := tempMessages splitByDays ]. (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 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))." + y: subtotals. diagram color: (aDictionary at: 'color'). histogram addPlot: diagram. histogram addDecoration: (RSHorizontalTick new - fromNames: messagesByTimeSpan keys; + fromNames: labels; labelRotation: 0; - fontSize: 68 /messagesByTimeSpan size; + fontSize: 68 /messagesDict size; yourself). histogram addDecoration: (RSVerticalTick new integer; - fontSize: 68 /messagesByTimeSpan size). + fontSize: 68 /messagesDict size). histogram build. ^ histogram canvas exportAsFileNamed: (aDictionary at: 'messagesType'), '-histogram' into: self folder \ No newline at end of file diff --git a/Socialmetrica.package/NitterUser.class/instance/exportQuotesHistogram.st b/Socialmetrica.package/NitterUser.class/instance/exportQuotesHistogram.st deleted file mode 100644 index f738f0e..0000000 --- a/Socialmetrica.package/NitterUser.class/instance/exportQuotesHistogram.st +++ /dev/null @@ -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' \ No newline at end of file diff --git a/Socialmetrica.package/NitterUser.class/instance/exportQuotesHistogramWithBars..st b/Socialmetrica.package/NitterUser.class/instance/exportQuotesHistogramWithBars..st index 6060ce7..3305cda 100644 --- a/Socialmetrica.package/NitterUser.class/instance/exportQuotesHistogramWithBars..st +++ b/Socialmetrica.package/NitterUser.class/instance/exportQuotesHistogramWithBars..st @@ -1,7 +1,16 @@ accessing 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. (aNumberOfBars > quotes size) ifTrue: [ ^ self exportQuotesHistogram ]. keysToRemove := OrderedCollection new. @@ -37,4 +46,4 @@ exportQuotesHistogramWithBars: aNumberOfBars noFixedShapes; fileName: (self folder / 'quotes-histogram.png')fullName; export. - ^ self folder / 'quotes-histogram.png' \ No newline at end of file + ^ self folder / 'quotes-histogram.png'" \ No newline at end of file diff --git a/Socialmetrica.package/NitterUser.class/instance/exportRetweetsHistogram.st b/Socialmetrica.package/NitterUser.class/instance/exportRetweetsHistogram.st deleted file mode 100644 index a068910..0000000 --- a/Socialmetrica.package/NitterUser.class/instance/exportRetweetsHistogram.st +++ /dev/null @@ -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' \ No newline at end of file diff --git a/Socialmetrica.package/NitterUser.class/instance/exportRetweetsHistogramWithBars..st b/Socialmetrica.package/NitterUser.class/instance/exportRetweetsHistogramWithBars..st index 3c51f52..4c3252f 100644 --- a/Socialmetrica.package/NitterUser.class/instance/exportRetweetsHistogramWithBars..st +++ b/Socialmetrica.package/NitterUser.class/instance/exportRetweetsHistogramWithBars..st @@ -1,41 +1,10 @@ accessing exportRetweetsHistogramWithBars: aNumberOfBars - | keysToRemove retweets labels retweetsHistogram diagram | - retweets := self retweets asMessagesUserNamesSortedByOccurrences. - (aNumberOfBars > retweets size) ifTrue: [ ^ self exportRetweetsHistogram ]. - keysToRemove := OrderedCollection new. - 1 to: retweets size - aNumberOfBars do: - [ :i | keysToRemove add: (retweets keys at: i + aNumberOfBars) ]. - retweets removeKeys: keysToRemove. - - 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' \ No newline at end of file + | retweetsDict | + retweetsDict := { + 'messagesType' -> 'retweets'. + 'extent' -> (800@200). + 'color' -> (Color r:(217/255) g:(56/255) b: (124/255)) + } asDictionary. + ^ self exportHistogramFor: retweetsDict By: aNumberOfBars \ No newline at end of file