arnaucube
arnaucube/argosPublic Self-hosted repository
argos/analyzeDates.go
analyzeDates.goRaw
 1package main
 2
 3import (
 4	"fmt"
 5	"strconv"
 6	"strings"
 7
 8	"github.com/dghubble/go-twitter/twitter"
 9)
10
11var week = [7]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}
12
13func printBar(n int) {
14	for i := 0; i < n; i++ {
15		fmt.Print("█")
16	}
17	fmt.Println(" ")
18}
19
20func printDays(days map[string]int) {
21	for i := 0; i < len(week); i++ {
22		fmt.Print(week[i] + " - " + strconv.Itoa(days[week[i]]))
23		fmt.Print("	")
24		printBar(days[week[i]])
25	}
26}
27func analyzeDays(tweets []twitter.Tweet) {
28	var days = make(map[string]int)
29	for _, v := range tweets {
30		//fmt.Println(v.CreatedAt)
31		day := strings.Split(v.CreatedAt, " ")[0]
32		if _, ok := days[day]; ok {
33			days[day] = days[day] + 1
34		} else {
35			days[day] = 1
36		}
37	}
38	printDays(days)
39}
40
41func printHours(hours map[string]int) {
42	for i := 0; i < 24; i++ {
43		var h string
44		if i < 10 {
45			h = "0" + strconv.Itoa(i)
46		} else {
47			h = strconv.Itoa(i)
48		}
49		fmt.Print(h + "h	-	" + strconv.Itoa(hours[h]) + "tw")
50		fmt.Print("	")
51		printBar(hours[h])
52	}
53}
54func analyzeHours(tweets []twitter.Tweet) {
55	var hours = make(map[string]int)
56	for _, v := range tweets {
57		time := strings.Split(v.CreatedAt, " ")[3]
58		hour := strings.Split(time, ":")[0]
59		if _, ok := hours[hour]; ok {
60			hours[hour] = hours[hour] + 1
61		} else {
62			hours[hour] = 1
63		}
64	}
65	printHours(hours)
66}
67
68func analyzeDates(tweets []twitter.Tweet) {
69	analyzeDays(tweets)
70	fmt.Println(" ")
71	analyzeHours(tweets)
72}