Beispiel #1
0
func TweetToTextTesting() {
	// Connectin to the local mongo database
	session, err := mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}
	// We defer the session closing so we don't forget later
	defer session.Close()

	a := session.DB("timelines").C("conurls")
	//profiles.GetTimelineToDB(*a, "manupruebas", 5) // 2, 9, 25, 30, 40....
	var tweets []twittertypes.Tweet
	err = a.Find(nil).All(&tweets)
	if err != nil {
		panic(err)
	}
	wordsResult, doubleWordsResult := trendings.ParseTweetsAll(tweets, "")
	fmt.Println("Num Words:", len(wordsResult))
	for i := 0; i < len(wordsResult); i++ {
		fmt.Printf("-->%s<--,%d\n", wordsResult[i].Word, wordsResult[i].Value)
	}
	fmt.Println("Num Double Words:", len(doubleWordsResult))
	for i := 0; i < len(doubleWordsResult); i++ {
		fmt.Printf("-->%s<--,%d\n", doubleWordsResult[i].Word, doubleWordsResult[i].Value)
	}
	return
}
Beispiel #2
0
func InterestsTesting() {
	// Connectin to the local mongo database
	session, err := mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}
	// We defer the session closing so we don't forget later
	defer session.Close()

	var twitterProfile string
	// twitterProfile = "nexocargo"
	// twitterProfile = "enrimr"
	// twitterProfile = "548017" // wences
	// twitterProfile = "alvjimcesar"
	// twitterProfile = "daniel_prol"
	// twitterProfile = "saracaan"
	// twitterProfile = "irenetaule"
	// twitterProfile = "la_terminal_"
	// twitterProfile = "sonosara_mk"
	// twitterProfile = "alberto_s_h"
	//twitterProfile = "srbuhito"
	twitterProfile = "steamkhemia"
	c := session.DB("timelines").C(twitterProfile)
	profiles.GetTimelineToDB(*c, twitterProfile, 2000)
	todosLosTweets := trendings.GetTweetsAll(*c)
	listaPalabras, listaDoblesPalabras := trendings.ParseTweetsAll(todosLosTweets, "")

	resultados := make([]int, len(profiles.TopicsList))
	profiles.LoadTopics()
	for i := 0; i < len(listaPalabras); i++ {
		for j := 0; j < len(profiles.TopicsList); j++ {
			value, exists := profiles.TopicsDB[profiles.TopicsList[j]][listaPalabras[i].Word]
			if exists == true {
				resultados[j] = resultados[j] + (listaPalabras[i].Value * value)
				fmt.Println(listaPalabras[i].Word, listaPalabras[i].Value)
			}
		}
	}
	for i := 0; i < len(listaDoblesPalabras); i++ {
		for j := 0; j < len(profiles.TopicsList); j++ {
			value, exists := profiles.TopicsDB[profiles.TopicsList[j]][listaDoblesPalabras[i].Word]
			if exists == true {
				resultados[j] = resultados[j] + (listaDoblesPalabras[i].Value * value)
				fmt.Println(listaDoblesPalabras[i].Word, listaDoblesPalabras[i].Value)
			}
		}
	}

	fmt.Println("")
	for i := 0; i < len(resultados); i++ {
		fmt.Println(profiles.TopicsList[i], ":", resultados[i])
	}

	err = c.DropCollection()
	if err != nil {
		panic(err)
	}
	return
}
Beispiel #3
0
func DataBaseTestAndParsing() {
	// Connectin to the local mongo database
	session, err := mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}
	// We defer the session closing so we don't forget later
	defer session.Close()

	//a := session.DB("twitter").C("becasep")
	a := session.DB("twitter").C("championstve")
	//a := session.DB("timelines").C("conurls")

	todosLosTweets = trendings.GetTweetsAll(*a)
	fmt.Println("=============================")
	fmt.Println("Tweets sin filtrar")
	fmt.Println("=============================")
	fmt.Println("Num tweets:", len(todosLosTweets))
	// for i:=0; i<len(todosLosTweets); i++ {
	// fmt.Println(i, todosLosTweets[i].Epoch, todosLosTweets[i].Created_at)
	// }

	fmt.Println("============================================")
	fmt.Println("Cuenta de Palabras SIN Keyword sobre TODOS")
	fmt.Println("============================================")

	listaPalabras, listaDoblesPalabras = trendings.ParseTweetsAll(todosLosTweets, "#championstve")
	fmt.Println("Num palabras:", len(listaPalabras))
	fmt.Println("Num dobles:", len(listaDoblesPalabras))
	//fmt.Println(listaPalabras)
	//return
	fmt.Println("============================================")
	fmt.Println("Cuenta de Palabras CON Keyword sobre TODOS")
	fmt.Println("============================================")

	listaPalabrasKeyword, listaDoblesPalabrasKeyword = trendings.ParseTweetsKeyword(todosLosTweets, "ramos", "#championstve")
	fmt.Println("Num palabras:", len(listaPalabrasKeyword))
	fmt.Println("Num dobles:", len(listaDoblesPalabrasKeyword))
	//fmt.Println(listaPalabrasKeyword)
	//return
	// start, err := time.Parse(time.RubyDate, "Thu Apr 24 10:13:37 +0000 2014")
	// end, err := time.Parse(time.RubyDate,"Thu Apr 24 10:15:28 +0000 2014")
	// Primera parte del partido
	start, err := time.Parse(time.RubyDate, "Tue Apr 29 20:45:00 +0200 2014")
	end, err := time.Parse(time.RubyDate, "Tue Apr 29 21:45:00 +0200 2014")
	tweetsFiltrados = trendings.GetTweetsRange(*a, start, end)
	fmt.Println("=============================")
	fmt.Println("Twets filtrados por")
	fmt.Println("=============================")
	fmt.Println("Inicio", start.Unix())
	fmt.Println("Fin", end.Unix())
	fmt.Println("=============================")
	fmt.Println("Num Tweets:", len(tweetsFiltrados))
	// for i:=0; i<len(tweetsFiltrados); i++ {
	// fmt.Println(i, tweetsFiltrados[i].Epoch, tweetsFiltrados[i].Created_at)
	// }
	listaPalabrasRango1, listaDoblesPalabrasRango1 = trendings.ParseTweetsAll(tweetsFiltrados, "#championstve")
	// Segunda parte del partido
	start, err = time.Parse(time.RubyDate, "Tue Apr 29 21:45:01 +0200 2014")
	end, err = time.Parse(time.RubyDate, "Tue Apr 29 22:35:00 +0200 2014")
	tweetsFiltrados = trendings.GetTweetsRange(*a, start, end)
	fmt.Println("=============================")
	fmt.Println("Twets filtrados por")
	fmt.Println("=============================")
	fmt.Println("Inicio", start /*.Unix()*/)
	fmt.Println("Fin", end /*.Unix()*/)
	fmt.Println("=============================")
	fmt.Println("Num Tweets:", len(tweetsFiltrados))
	// for i:=0; i<len(tweetsFiltrados); i++ {
	// fmt.Println(i, tweetsFiltrados[i].Epoch, tweetsFiltrados[i].Created_at)
	// }
	listaPalabrasRango2, listaDoblesPalabrasRango2 = trendings.ParseTweetsAll(tweetsFiltrados, "#championstve")

	mergedList = trendings.MergeTrendings(listaPalabras, listaDoblesPalabras)
	// Guardamos los pares [palabra, valor] en la BD
	g := session.DB("twitter").C("resultado1")
	for i := 0; i < len(listaPalabras); i++ {
		//fmt.Println(listaPalabras[i].Value, listaPalabras[i].Word)
		err = g.Insert(listaPalabras[i])
		if err != nil {
			panic(err)
		}
	}

	// for i:=0; i<len(todosLosTweets); i++ {
	// fmt.Println(todosLosTweets[i].Text)
	// }
}