138 lines
3.1 KiB
Smalltalk
138 lines
3.1 KiB
Smalltalk
"
|
|
I represent the general stats for the kind of messages a given profile
|
|
account, being them: twets, retweets and replies.
|
|
|
|
I'm useful for general overviews of a twitter account in a given period of
|
|
time or in general.
|
|
"
|
|
Class {
|
|
#name : #TPMessages,
|
|
#superclass : #Object,
|
|
#instVars : [
|
|
'tweets',
|
|
'retweets',
|
|
'replies'
|
|
],
|
|
#category : #'Dataviz-Twitter'
|
|
}
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> asAssociations [
|
|
| d |
|
|
d := Dictionary new.
|
|
d
|
|
at: 'tweets' put: self tweetsSize;
|
|
at: 'retweets' put: self retweetsSize;
|
|
at: 'replies' put: self repliesSize.
|
|
^ d associations.
|
|
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> asDictionary [
|
|
| d |
|
|
d := Dictionary new.
|
|
d
|
|
at: 'tweets' put: self tweetsSize;
|
|
at: 'retweets' put: self retweetsSize;
|
|
at: 'replies' put: self repliesSize.
|
|
^ d.
|
|
|
|
]
|
|
|
|
{ #category : #initialization }
|
|
TPMessages >> initialize [
|
|
super initialize.
|
|
]
|
|
|
|
{ #category : #'data queries' }
|
|
TPMessages >> mentionedProfilesByFrequency [
|
|
| words builder mentions allScreenNames |
|
|
self replies ifNil: [ ^ self ].
|
|
words := ''.
|
|
mentions := self replies collect: [:reply |
|
|
((reply at: 'entities') at: 'user_mentions') ].
|
|
allScreenNames := mentions collect: [:mention |
|
|
mention size > 0
|
|
ifTrue: [(mention collect: [:each | each at: 'screen_name' ])]].
|
|
allScreenNames do: [ :each | each ifNotNil: [ each do: [:e | words := words, ' ',e ]]].
|
|
builder := RTNameCloud new.
|
|
builder dictionary: "RTEnglishDictionary new unnecessaryWords," self class new.
|
|
builder addString: words.
|
|
^ builder sortedAssociations
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> replies [
|
|
^ replies
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> replies: anOrderedCollection [
|
|
replies := anOrderedCollection
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> repliesSize [
|
|
self replies ifNotNil: [ ^ self replies size ] ifNil: [ ^ 0 ].
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> retweets [
|
|
^ retweets
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> retweets: anOrderedCollection [
|
|
retweets := anOrderedCollection
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> retweetsSize [
|
|
^ self retweets size
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> tweets [
|
|
^ tweets
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> tweets: anOrderedCollection [
|
|
tweets := anOrderedCollection
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
TPMessages >> tweetsSize [
|
|
^ self tweets size.
|
|
]
|
|
|
|
{ #category : #utility }
|
|
TPMessages >> visualWordsFrom: aWordsCollection colored: aColor [
|
|
"I take a collection of words and turn them into visual words that can be put into a canvas"
|
|
| visualWords |
|
|
visualWords := OrderedCollection new.
|
|
aWordsCollection do: [ :each | | label |
|
|
label := TRRotatedLabelShape new
|
|
text: each asString;
|
|
color: aColor.
|
|
visualWords add: label].
|
|
^ visualWords
|
|
|
|
|
|
]
|
|
|
|
{ #category : #'data queries' }
|
|
TPMessages >> wordsByFrequencyInTweets [
|
|
| words builder |
|
|
self tweets ifNil: [ ^ self ].
|
|
words := ''.
|
|
self tweets do: [ :tweet |
|
|
words := words, ' ', (tweet message).
|
|
].
|
|
builder := RTNameCloud new.
|
|
builder dictionary: "RTEnglishDictionary new unnecessaryWords," self class new.
|
|
builder addString: words.
|
|
^ builder sortedAssociations
|
|
]
|