@ -0,0 +1,72 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"strconv" |
|||
"strings" |
|||
|
|||
"github.com/dghubble/go-twitter/twitter" |
|||
) |
|||
|
|||
var week = [7]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"} |
|||
|
|||
func printBar(n int) { |
|||
for i := 0; i < n; i++ { |
|||
fmt.Print("█") |
|||
} |
|||
fmt.Println(" ") |
|||
} |
|||
|
|||
func printDays(days map[string]int) { |
|||
for i := 0; i < len(week); i++ { |
|||
fmt.Print(week[i] + " - " + strconv.Itoa(days[week[i]])) |
|||
fmt.Print(" ") |
|||
printBar(days[week[i]]) |
|||
} |
|||
} |
|||
func analyzeDays(tweets []twitter.Tweet) { |
|||
var days = make(map[string]int) |
|||
for _, v := range tweets { |
|||
//fmt.Println(v.CreatedAt)
|
|||
day := strings.Split(v.CreatedAt, " ")[0] |
|||
if _, ok := days[day]; ok { |
|||
days[day] = days[day] + 1 |
|||
} else { |
|||
days[day] = 1 |
|||
} |
|||
} |
|||
printDays(days) |
|||
} |
|||
|
|||
func printHours(hours map[string]int) { |
|||
for i := 0; i < 24; i++ { |
|||
var h string |
|||
if i < 10 { |
|||
h = "0" + strconv.Itoa(i) |
|||
} else { |
|||
h = strconv.Itoa(i) |
|||
} |
|||
fmt.Print(h + "h - " + strconv.Itoa(hours[h]) + "tw") |
|||
fmt.Print(" ") |
|||
printBar(hours[h]) |
|||
} |
|||
} |
|||
func analyzeHours(tweets []twitter.Tweet) { |
|||
var hours = make(map[string]int) |
|||
for _, v := range tweets { |
|||
time := strings.Split(v.CreatedAt, " ")[3] |
|||
hour := strings.Split(time, ":")[0] |
|||
if _, ok := hours[hour]; ok { |
|||
hours[hour] = hours[hour] + 1 |
|||
} else { |
|||
hours[hour] = 1 |
|||
} |
|||
} |
|||
printHours(hours) |
|||
} |
|||
|
|||
func analyzeDates(tweets []twitter.Tweet) { |
|||
analyzeDays(tweets) |
|||
fmt.Println(" ") |
|||
analyzeHours(tweets) |
|||
} |
@ -0,0 +1,52 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"sort" |
|||
"strings" |
|||
|
|||
"github.com/dghubble/go-twitter/twitter" |
|||
) |
|||
|
|||
func sortMapWords(m map[string]int) map[int][]string { |
|||
n := map[int][]string{} |
|||
var a []int |
|||
for k, v := range m { |
|||
if v > minNumWords { |
|||
n[v] = append(n[v], k) |
|||
} |
|||
} |
|||
for k := range n { |
|||
a = append(a, k) |
|||
} |
|||
sort.Sort(sort.Reverse(sort.IntSlice(a))) |
|||
for _, k := range a { |
|||
for _, s := range n[k] { |
|||
fmt.Printf("%d - %s,\n", k, s) |
|||
} |
|||
} |
|||
return n |
|||
} |
|||
|
|||
func mapWords(text string, words map[string]int) { |
|||
s := strings.Split(text, " ") |
|||
|
|||
for _, v := range s { |
|||
if _, ok := words[v]; ok { |
|||
words[v] = words[v] + 1 |
|||
} else { |
|||
words[v] = 1 |
|||
} |
|||
} |
|||
} |
|||
func analyzeWords(tweets []twitter.Tweet) { |
|||
var words = make(map[string]int) |
|||
|
|||
for _, v := range tweets { |
|||
mapWords(v.Text, words) |
|||
} |
|||
|
|||
fmt.Println(len(words)) |
|||
//get sorted list of frequency words
|
|||
_ = sortMapWords(words) |
|||
} |
@ -1,26 +0,0 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"sort" |
|||
) |
|||
|
|||
func sortMap(m map[string]int) map[int][]string { |
|||
n := map[int][]string{} |
|||
var a []int |
|||
for k, v := range m { |
|||
if v > 2 { |
|||
n[v] = append(n[v], k) |
|||
} |
|||
} |
|||
for k := range n { |
|||
a = append(a, k) |
|||
} |
|||
sort.Sort(sort.Reverse(sort.IntSlice(a))) |
|||
for _, k := range a { |
|||
for _, s := range n[k] { |
|||
fmt.Printf("%s, %d\n", s, k) |
|||
} |
|||
} |
|||
return n |
|||
} |