colour added to chart (lowest and highest values)

This commit is contained in:
arnaucode
2017-04-16 18:27:50 +02:00
parent 48656e5b16
commit ccfc1f6edc
6 changed files with 45 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"sort"
"strconv" "strconv"
"strings" "strings"
@@ -10,18 +11,49 @@ import (
var week = [7]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"} var week = [7]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}
func printBar(n int) { func printBar(n int, lowest int, highest int) {
for i := 0; i < n; i++ { 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("█") 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(" ") 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) { func printDays(days map[string]int) {
lowest, highest := getHigherValueOfMap(days)
for i := 0; i < len(week); i++ { for i := 0; i < len(week); i++ {
fmt.Print(week[i] + " - " + strconv.Itoa(days[week[i]]) + "tw") fmt.Print(week[i] + " - " + strconv.Itoa(days[week[i]]) + "tw")
fmt.Print(" ") fmt.Print(" ")
printBar(days[week[i]]) printBar(days[week[i]], lowest, highest)
} }
} }
func analyzeDays(tweets []twitter.Tweet) { func analyzeDays(tweets []twitter.Tweet) {
@@ -39,6 +71,8 @@ func analyzeDays(tweets []twitter.Tweet) {
} }
func printHours(hours map[string]int) { func printHours(hours map[string]int) {
lowest, highest := getHigherValueOfMap(hours)
for i := 0; i < 24; i++ { for i := 0; i < 24; i++ {
var h string var h string
if i < 10 { if i < 10 {
@@ -48,7 +82,7 @@ func printHours(hours map[string]int) {
} }
fmt.Print(h + "h - " + strconv.Itoa(hours[h]) + "tw") fmt.Print(h + "h - " + strconv.Itoa(hours[h]) + "tw")
fmt.Print(" ") fmt.Print(" ")
printBar(hours[h]) printBar(hours[h], lowest, highest)
} }
} }
func analyzeHours(tweets []twitter.Tweet) { func analyzeHours(tweets []twitter.Tweet) {

Binary file not shown.

View File

@@ -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 return tweets
} }
func getUser(client *twitter.Client) { func getUserTweets(client *twitter.Client) {
newcommand := bufio.NewReader(os.Stdin) newcommand := bufio.NewReader(os.Stdin)
fmt.Print("enter username: @") fmt.Print("enter username: @")
username, _ := newcommand.ReadString('\n') username, _ := newcommand.ReadString('\n')
@@ -39,7 +38,7 @@ func getUser(client *twitter.Client) {
fmt.Println("-----------------------") fmt.Println("-----------------------")
//get tweets //get tweets
tweets := getTweets(client, username, 2) tweets := getTweets(client, username, iterationsCount)
//now analyze words and dates //now analyze words and dates
fmt.Println("word count") fmt.Println("word count")
@@ -60,6 +59,8 @@ func getUser(client *twitter.Client) {
fmt.Print("last tweet analyzed: ") fmt.Print("last tweet analyzed: ")
fmt.Println(tweets[0].CreatedAt) fmt.Println(tweets[0].CreatedAt)
fmt.Println(" ")
fmt.Println("total of " + strconv.Itoa(len(tweets)) + " tweets")
fmt.Println(" ") fmt.Println(" ")
fmt.Println("User @" + username + " analysis finished") fmt.Println("User @" + username + " analysis finished")
} }

View File

@@ -8,10 +8,11 @@ import (
) )
const minNumWords = 10 const minNumWords = 10
const iterationsCount = 3
func main() { func main() {
fmt.Println("---------------") fmt.Println("---------------")
fmt.Println("mgoTweetsAnalyze initialized") fmt.Println("goTweetsAnalyze initialized")
fmt.Println("Reading twitterConfig.json file") fmt.Println("Reading twitterConfig.json file")
client := readConfigTokensAndConnect() client := readConfigTokensAndConnect()
@@ -30,7 +31,7 @@ option to select: `
switch option { switch option {
case "1": case "1":
fmt.Println("selected 1 - Analyze username") fmt.Println("selected 1 - Analyze username")
getUser(client) getUserTweets(client)
break break
case "2": case "2":
fmt.Println("selected 2 - Delete all Favs") fmt.Println("selected 2 - Delete all Favs")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 60 KiB