|
@@ -4,6 +4,7 @@ import (
|
|
|
"bytes"
|
|
|
"crypto/rand"
|
|
|
"encoding/json"
|
|
|
+ "fmt"
|
|
|
)
|
|
|
|
|
|
//topicPointer and textPointer should not be exported
|
|
@@ -53,11 +54,12 @@ func NewEntries(inputTweets []Tweet, whereTo int) {
|
|
|
//known tweet
|
|
|
//setting pointer for all other Topics
|
|
|
topic := tweet.Topics[index]
|
|
|
- tweet.TopicPointer = tweet.Topics[0]
|
|
|
- tweet.TextPointer = position
|
|
|
- tweet.Topics = nil
|
|
|
- tweet.Text = ""
|
|
|
- tmpdb[topic] = append(tmpdb[topic], tweet)
|
|
|
+ var pointerTweet Tweet
|
|
|
+ pointerTweet.TopicPointer = tweet.Topics[0]
|
|
|
+ pointerTweet.TextPointer = position
|
|
|
+ pointerTweet.Topics = nil
|
|
|
+ pointerTweet.Text = ""
|
|
|
+ tmpdb[topic] = append(tmpdb[topic], pointerTweet)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -70,12 +72,15 @@ func NewEntries(inputTweets []Tweet, whereTo int) {
|
|
|
|
|
|
//todo! add round to pirquery only get tweets that have been posted from that round onward
|
|
|
func GetTweets(pirQuery []byte, dataLength int, whereFrom int) []byte {
|
|
|
+ fmt.Println("pirQuery", pirQuery)
|
|
|
+ fmt.Println(dbR)
|
|
|
tmpdb := dbR
|
|
|
if whereFrom == 1 {
|
|
|
tmpdb = archive
|
|
|
}
|
|
|
minimumBlockSize = dataLength * maxTweetAmount(whereFrom)
|
|
|
var wantedTopics = getNamesForTopics(pirQuery, whereFrom)
|
|
|
+ fmt.Println("topicNames", wantedTopics)
|
|
|
tweetsToReturn := make([][]Tweet, len(wantedTopics))
|
|
|
for index, wantedTopic := range wantedTopics {
|
|
|
for _, tweet := range tmpdb[wantedTopic] {
|
|
@@ -92,6 +97,13 @@ func GetTweets(pirQuery []byte, dataLength int, whereFrom int) []byte {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ for _, row := range tweetsToReturn {
|
|
|
+ for _, tweet := range row {
|
|
|
+ fmt.Print(tweet.Text)
|
|
|
+ }
|
|
|
+ fmt.Println("")
|
|
|
+ }
|
|
|
return tweetsToByteArray(tweetsToReturn)
|
|
|
}
|
|
|
|
|
@@ -168,39 +180,41 @@ func GetTopicList(whereFrom int) ([]byte, int) {
|
|
|
|
|
|
//iterates through full dbR and moves old tweets to archive
|
|
|
func CleanUpdbR(round int) {
|
|
|
- var tweetsToArchive []Tweet
|
|
|
- for j := range dbR {
|
|
|
- tweets := dbR[j]
|
|
|
- for i := len(tweets) - 1; i >= 0; i-- {
|
|
|
- if round-roundsBeforeArchiving == tweets[i].RoundPosted {
|
|
|
- //only adds the tweet to the archive when there is text
|
|
|
- if tweets[i].Text != "" {
|
|
|
- tweetsToArchive = append(tweetsToArchive, tweets[i])
|
|
|
+
|
|
|
+ if roundsBeforeArchiving%round == 0 {
|
|
|
+ var tweetsToArchive []Tweet
|
|
|
+ for j := range dbR {
|
|
|
+ tweets := dbR[j]
|
|
|
+ for i := len(tweets) - 1; i >= 0; i-- {
|
|
|
+ if round-roundsBeforeArchiving == tweets[i].RoundPosted {
|
|
|
+ //only adds the tweet to the archive when there is text
|
|
|
+ if tweets[i].Text != "" {
|
|
|
+ tweetsToArchive = append(tweetsToArchive, tweets[i])
|
|
|
+ }
|
|
|
+ //delets the tweet from the array
|
|
|
+ tweets = append(tweets[:i], tweets[i+1:]...)
|
|
|
}
|
|
|
- //delets the tweet from the array
|
|
|
- tweets = append(tweets[:i], tweets[i+1:]...)
|
|
|
}
|
|
|
+ dbR[j] = tweets
|
|
|
}
|
|
|
- dbR[j] = tweets
|
|
|
- }
|
|
|
- NewEntries(tweetsToArchive, 1)
|
|
|
+ NewEntries(tweetsToArchive, 1)
|
|
|
|
|
|
- //redoes the whole dbR to correct pointers
|
|
|
- var tweetsToMain []Tweet
|
|
|
+ //redoes the whole dbR to correct pointers
|
|
|
+ var tweetsToMain []Tweet
|
|
|
|
|
|
- for i := range dbR {
|
|
|
- tweets := dbR[i]
|
|
|
- for _, tweet := range tweets {
|
|
|
- if tweet.Text != "" {
|
|
|
- tweetsToMain = append(tweetsToMain, tweet)
|
|
|
+ for i := range dbR {
|
|
|
+ tweets := dbR[i]
|
|
|
+ for _, tweet := range tweets {
|
|
|
+ if tweet.Text != "" {
|
|
|
+ tweetsToMain = append(tweetsToMain, tweet)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- dbR = nil
|
|
|
- dbR = make(map[string][]Tweet)
|
|
|
- topicList = nil
|
|
|
-
|
|
|
- NewEntries(tweetsToMain, 0)
|
|
|
+ dbR = nil
|
|
|
+ dbR = make(map[string][]Tweet)
|
|
|
+ topicList = nil
|
|
|
|
|
|
+ NewEntries(tweetsToMain, 0)
|
|
|
+ }
|
|
|
}
|