argos/analyzeDates.go
analyzeDates.goRaw
1package main
2
3import (
4 "fmt"
5 "sort"
6 "strconv"
7 "strings"
8
9 "github.com/dghubble/go-twitter/twitter"
10)
11
12var week = [7]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}
13
14func printBar(n int, lowest int, highest int) {
15 bar := int((float64(n) / float64(highest)) * 40)
16
17 if n == lowest {
18 fmt.Print("\x1b[36;1m") //cyan
19 }
20 if n == highest {
21 fmt.Print("\x1b[31;1m") //red
22 }
23
24 for i := 0; i < bar; i++ {
25 fmt.Print("█")
26 }
27
28 if bar == 0 && n > 0 {
29 fmt.Print("█")
30 }
31 if n == lowest {
32 fmt.Print(" lowest")
33 }
34 if n == highest {
35 fmt.Print(" highest")
36 }
37 fmt.Print("\x1b[0m") //defaultColor
38 fmt.Println(" ")
39}
40func printBarRetweets(n int, lowest int, highest int) {
41 bar := int((float64(n) / float64(highest)) * 40)
42
43 if n == lowest {
44 fmt.Print("\x1b[36;1m") //cyan
45 }
46 if n == highest {
47 fmt.Print("\x1b[31;1m") //red
48 }
49
50 for i := 0; i < bar; i++ {
51 fmt.Print("█")
52 }
53
54 if bar == 0 && n > 0 {
55 fmt.Print("█")
56 }
57 if n == lowest {
58 //fmt.Print(" lowest")
59 }
60 if n == highest {
61 fmt.Print(" possible bots")
62 }
63 fmt.Print("\x1b[0m") //defaultColor
64 fmt.Println(" ")
65}
66func getHigherValueOfMap(m map[string]int) (int, int) {
67 var values []int
68 for _, v := range m {
69 values = append(values, v)
70 }
71 sort.Ints(values)
72 //returns lower, higher values
73 return values[0], values[len(values)-1]
74}
75
76func printDays(days map[string]int) {
77 lowest, highest := getHigherValueOfMap(days)
78
79 for i := 0; i < len(week); i++ {
80 fmt.Print(week[i] + " - " + strconv.Itoa(days[week[i]]) + "tw")
81 fmt.Print(" ")
82 printBar(days[week[i]], lowest, highest)
83 }
84}
85func analyzeDays(tweets []twitter.Tweet) {
86 var days = make(map[string]int)
87 for _, v := range tweets {
88 day := strings.Split(v.CreatedAt, " ")[0]
89 if _, ok := days[day]; ok {
90 days[day] = days[day] + 1
91 } else {
92 days[day] = 1
93 }
94 }
95 printDays(days)
96}
97
98func printHours(hours map[string]int) {
99 lowest, highest := getHigherValueOfMap(hours)
100
101 for i := 0; i < 24; i++ {
102 var h string
103 if i < 10 {
104 h = "0" + strconv.Itoa(i)
105 } else {
106 h = strconv.Itoa(i)
107 }
108 fmt.Print(h + "h - " + strconv.Itoa(hours[h]) + "tw")
109 fmt.Print(" ")
110 printBar(hours[h], lowest, highest)
111 }
112}
113func analyzeHours(tweets []twitter.Tweet) {
114 var hours = make(map[string]int)
115 for _, v := range tweets {
116 time := strings.Split(v.CreatedAt, " ")[3]
117 hour := strings.Split(time, ":")[0]
118 /*if _, ok := hours[hour]; ok {
119 hours[hour] = hours[hour] + 1
120 } else {
121 hours[hour] = 1
122 }*/
123 hours[hour]++
124 }
125 printHours(hours)
126}
127
128func analyzeDates(tweets []twitter.Tweet) {
129 fmt.Println("Weekly activity distribution (per day)")
130 analyzeDays(tweets)
131 fmt.Println(" ")
132 fmt.Println("Daily activity distribution (per hour)")
133 analyzeHours(tweets)
134}
135
136func printTimeRetweets(dates map[string]int) {
137 lowest, highest := getHigherValueOfMap(dates)
138
139 for k, v := range dates {
140 fmt.Print(k + " - " + strconv.Itoa(v) + "tw")
141 fmt.Print(" ")
142 printBarRetweets(v, lowest, highest)
143 }
144}
145
146func analyzeTimeRetweets(tweets []twitter.Tweet) {
147 var dates = make(map[string]int)
148 for _, v := range tweets {
149 /*time := strings.Split(v.CreatedAt, " ")[3]
150 hour := strings.Split(time, ":")[0]*/
151 dates[v.CreatedAt]++
152 }
153 printTimeRetweets(dates)
154 //printSortedMapStringInt(dates, 0)
155}