Exemplo n.º 1
0
        //algorithm 0
        //for new algorthm need mimic bellow and replace GoogleMapHelper() to ur new function
        public void GoogleMap(int AlgorithmId)
        {
            while (true)
            {
                bool continue1 = startCheck();
                while (continue1)
                {
                    TwittersI ts = new Twitters();
                    ts.allTweets = database.loadBasicTweets(algorithmInfomations[AlgorithmId].lastMaxId + 1, this.TweetbnumberEachCycle);
                    if (ts.allTweets.Count != 0)//if nothing is loaded not run
                    {
                        //for new algorthm need to replace GoogleMapHelper() to ur new function
                        LocationHelper ghp = new GoogleMapHelper();


                        TwitterModel id = ghp.run(ts, AlgorithmId);
                        algorithmInfomations[AlgorithmId].lastMaxId = id.realTwitterId;
                        algorithmInfomations[AlgorithmId].lastDate  = id.createAt;
                        ts.saveLocationInTweets(AlgorithmId);
                        database.updateAlgorithmInfo(algorithmInfomations[AlgorithmId]);
                    }
                    else
                    {
                        continue1 = false;
                    }
                }
                Thread.Sleep(sleepInterval); // wait for sleepInterval, then continue
            }
        }
Exemplo n.º 2
0
        public List <TwitterModel> loadBasicTweets(long lastMaxId, int tweetCount)//load tweets but ignore location from location methods, lastMaxId means get tweets after that id, tweetcount means how many tweets to get
        {
            MySqlConnection conn     = connect();
            String          sentence = "select * from tweets   where realTwitterId >= " + lastMaxId + " ORDER BY realTwitterId limit " + tweetCount;
            MySqlCommand    cmd      = new MySqlCommand(sentence, conn);
            MySqlDataReader reader   = null;


            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                reader = cmd.ExecuteReader();
                List <TwitterModel> twitters = new List <TwitterModel>();
                while (reader.Read())
                {
                    List <double> las = new List <double>();
                    List <double> los = new List <double>();
                    for (int i = 1; i <= 4; i++)
                    {
                        var ordinalla = reader.GetOrdinal((String)("PlaceLa" + i));
                        if (reader.IsDBNull(ordinalla)) // if there is no PlaceLai just break
                        {
                            break;
                        }

                        las.Add((double)reader[(String)("PlaceLa" + i)]);
                        los.Add((double)reader[(String)("PlaceLo" + i)]);
                    }
                    TwitterModel tm = new TwitterModel((long)reader["realTwitterId"], (long)reader["APITwitterId"], (int)reader["searchId"], (long)reader["userId"], (String)reader["content"], (String)reader["profileLocationContent"], las, los, ( DateTime)reader["createAt"]);
                    twitters.Add(tm);
                }

                return(twitters);
            }
            catch (Exception ex)
            {
                if (config.debug)
                {
                    throw ex;
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                conn.Close();
            }
        }
Exemplo n.º 3
0
        public TwitterModel loadBasicTwitterByRealId(long realId)
        {
            MySqlConnection conn     = connect();
            String          sentence = "select * from tweets   where realTwitterId = " + realId + " ORDER BY realTwitterId limit " + 1;
            MySqlCommand    cmd      = new MySqlCommand(sentence, conn);
            MySqlDataReader reader   = null;


            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    List <double> las = new List <double>();
                    List <double> los = new List <double>();
                    for (int i = 1; i <= 4; i++)
                    {
                        var ordinalla = reader.GetOrdinal((String)("PlaceLa" + i));
                        if (reader.IsDBNull(ordinalla)) // if there is no PlaceLai just break
                        {
                            break;
                        }

                        las.Add((double)reader[(String)("PlaceLa" + i)]);
                        los.Add((double)reader[(String)("PlaceLo" + i)]);
                    }
                    TwitterModel tm = new TwitterModel((long)reader["realTwitterId"], (long)reader["APITwitterId"], (int)reader["searchId"], (long)reader["userId"], (String)reader["content"], (String)reader["profileLocationContent"], las, los, (DateTime)reader["createAt"]);
                    return(tm);
                }
                return(null);
            }
            catch (Exception ex)
            {
                if (config.debug)
                {
                    throw ex;
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                conn.Close();
            }
        }
Exemplo n.º 4
0
        public Twitters(TwitterSearchI tsi, ISearchResult ist, DBI database)//in search convert from Itweet to twitterModel
        {
            this.database = new MysqlHelper();

            foreach (ITweet it in ist.Tweets)
            {
                TwitterModel tm = new TwitterModel(it, tsi.searchInfomation.searchId);
                this.allTweets.Add(tm);
            }
        }