colour added to chart (lowest and highest values)
arnaucode idoctnef@openmailbox.org
Sun, 16 Apr 2017 18:27:50 +0200
6 files changed,
45 insertions(+),
9 deletions(-)
M
analyzeDates.go
→
analyzeDates.go
@@ -2,6 +2,7 @@ package main
import ( "fmt" + "sort" "strconv" "strings"@@ -10,18 +11,49 @@ )
var week = [7]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"} -func printBar(n int) { - for i := 0; i < n; i++ { +func printBar(n int, lowest int, highest int) { + bar := int((float64(n) / float64(highest)) * 50) + + if n == lowest { + fmt.Print("\x1b[36;1m") + } + if n == highest { + fmt.Print("\x1b[31;1m") + } + + for i := 0; i < bar; i++ { fmt.Print("█") } + + if bar == 0 && n > 0 { + fmt.Print("█") + } + if n == lowest { + fmt.Print(" lowest") + } + if n == highest { + fmt.Print(" highest") + } + fmt.Print("\x1b[0m") fmt.Println(" ") } +func getHigherValueOfMap(m map[string]int) (int, int) { + var values []int + for _, v := range m { + values = append(values, v) + } + sort.Ints(values) + //returns lower, higher values + return values[0], values[len(values)-1] +} func printDays(days map[string]int) { + lowest, highest := getHigherValueOfMap(days) + for i := 0; i < len(week); i++ { fmt.Print(week[i] + " - " + strconv.Itoa(days[week[i]]) + "tw") fmt.Print(" ") - printBar(days[week[i]]) + printBar(days[week[i]], lowest, highest) } } func analyzeDays(tweets []twitter.Tweet) {@@ -39,6 +71,8 @@ printDays(days)
} func printHours(hours map[string]int) { + lowest, highest := getHigherValueOfMap(hours) + for i := 0; i < 24; i++ { var h string if i < 10 {@@ -48,7 +82,7 @@ h = strconv.Itoa(i)
} fmt.Print(h + "h - " + strconv.Itoa(hours[h]) + "tw") fmt.Print(" ") - printBar(hours[h]) + printBar(hours[h], lowest, highest) } } func analyzeHours(tweets []twitter.Tweet) {
M
getUser.go
→
getUserTweets.go
@@ -26,10 +26,9 @@ tweets = append(tweets, v)
} } - fmt.Println("total of " + strconv.Itoa(len(tweets)) + " tweets") return tweets } -func getUser(client *twitter.Client) { +func getUserTweets(client *twitter.Client) { newcommand := bufio.NewReader(os.Stdin) fmt.Print("enter username: @") username, _ := newcommand.ReadString('\n')@@ -39,7 +38,7 @@
fmt.Println("-----------------------") //get tweets - tweets := getTweets(client, username, 2) + tweets := getTweets(client, username, iterationsCount) //now analyze words and dates fmt.Println("word count")@@ -60,6 +59,8 @@ fmt.Println(tweets[len(tweets)-1].CreatedAt)
fmt.Print("last tweet analyzed: ") fmt.Println(tweets[0].CreatedAt) + fmt.Println(" ") + fmt.Println("total of " + strconv.Itoa(len(tweets)) + " tweets") fmt.Println(" ") fmt.Println("User @" + username + " analysis finished") }
M
main.go
→
main.go
@@ -8,10 +8,11 @@ "strings"
) const minNumWords = 10 +const iterationsCount = 3 func main() { fmt.Println("---------------") - fmt.Println("mgoTweetsAnalyze initialized") + fmt.Println("goTweetsAnalyze initialized") fmt.Println("Reading twitterConfig.json file") client := readConfigTokensAndConnect()@@ -30,7 +31,7 @@
switch option { case "1": fmt.Println("selected 1 - Analyze username") - getUser(client) + getUserTweets(client) break case "2": fmt.Println("selected 2 - Delete all Favs")