diff --git a/analyzeDates.go b/analyzeDates.go index 5057214..5c7464c 100644 --- a/analyzeDates.go +++ b/analyzeDates.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "sort" "strconv" "strings" @@ -10,18 +11,49 @@ import ( 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 @@ func analyzeDays(tweets []twitter.Tweet) { } 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 @@ func printHours(hours map[string]int) { } fmt.Print(h + "h - " + strconv.Itoa(hours[h]) + "tw") fmt.Print(" ") - printBar(hours[h]) + printBar(hours[h], lowest, highest) } } func analyzeHours(tweets []twitter.Tweet) { diff --git a/build/goTweetsAnalyze b/build/goTweetsAnalyze index 0a655b0..b796c09 100755 Binary files a/build/goTweetsAnalyze and b/build/goTweetsAnalyze differ diff --git a/getUser.go b/getUserTweets.go similarity index 92% rename from getUser.go rename to getUserTweets.go index cc61728..c37ea0f 100644 --- a/getUser.go +++ b/getUserTweets.go @@ -26,10 +26,9 @@ func getTweets(client *twitter.Client, username string, iterations int) []twitte } } - 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 @@ func getUser(client *twitter.Client) { 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 @@ func getUser(client *twitter.Client) { 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") } diff --git a/main.go b/main.go index 0634894..cb1b2bc 100644 --- a/main.go +++ b/main.go @@ -8,10 +8,11 @@ import ( ) 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 @@ option to select: ` switch option { case "1": fmt.Println("selected 1 - Analyze username") - getUser(client) + getUserTweets(client) break case "2": fmt.Println("selected 2 - Delete all Favs") diff --git a/screen2.png b/screen2.png index 98455f5..57cee8b 100644 Binary files a/screen2.png and b/screen2.png differ diff --git a/screen3.png b/screen3.png index 72d2fb1..6066f7e 100644 Binary files a/screen3.png and b/screen3.png differ