Browse Source

colour added to chart (lowest and highest values)

master
arnaucode 7 years ago
parent
commit
ccfc1f6edc
6 changed files with 45 additions and 9 deletions
  1. +38
    -4
      analyzeDates.go
  2. BIN
      build/goTweetsAnalyze
  3. +4
    -3
      getUserTweets.go
  4. +3
    -2
      main.go
  5. BIN
      screen2.png
  6. BIN
      screen3.png

+ 38
- 4
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) {

BIN
build/goTweetsAnalyze


getUser.go → 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")
}

+ 3
- 2
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")

BIN
screen2.png

Before After
Width: 411  |  Height: 920  |  Size: 51 KiB Width: 615  |  Height: 958  |  Size: 80 KiB

BIN
screen3.png

Before After
Width: 442  |  Height: 861  |  Size: 44 KiB Width: 612  |  Height: 748  |  Size: 60 KiB

Loading…
Cancel
Save