Esempio n. 1
0
        public SmallTweetNode getAt(int i)
        {
            if (count < i + 1 || i < 0)
            {
                return(null);
            }
            SmallTweetNode temp = start;

            for (int j = 0; j < i; j++)
            {
                temp = temp.next;
            }
            return(temp);
        }
Esempio n. 2
0
        public void move()
        {
            if (count == 0)
            {
                return;
            }
            SmallTweetNode temp1   = start;
            SmallTweetNode tstart1 = start;
            SmallTweetNode tend1   = null;
            SmallTweetNode tstart2 = null;
            SmallTweetNode tend2   = null;

            while (temp1.hasNext)
            {
                SmallTweetNode temp2 = temp1.next;
                if (temp2.value.ApiTwitterId > temp1.value.ApiTwitterId) //if reach the interval end
                {
                    if (tstart2 == null)                                 //first interval complete
                    {
                        tend1      = temp1;
                        tstart2    = temp2;
                        tend1.next = null;
                    }
                    else
                    {
                        tend2      = temp1;
                        tend2.next = tstart1;
                        tstart1    = tstart2;
                        tstart2    = temp2;
                    }
                }

                temp1 = temp2;
            }
            if (tstart2 == null)
            {
                return;
            }
            else
            {
                tend2      = temp1;
                tend2.next = tstart1;
                tstart1    = tstart2;
            }

            start = tstart1;
            end   = tend1;
        }
Esempio n. 3
0
        public void push(SmallTweet value)
        {
            SmallTweetNode node = new SmallTweetNode(value);

            if (count == 0)
            {
                start = node;
                end   = node;
            }
            else
            {
                end.next = node;
                end      = node;
            }

            count++;
        }
Esempio n. 4
0
        public List <long> loadTweetsCountNew(List <DateTime> times, Double[] startLaLo, Double[] endLaLo, int searchId, int algorithmId = 0)
        {
            MySqlDataReader reader = null;
            MySqlConnection conn = connect();
            String          La = "La" + algorithmId;
            String          Lo = "Lo" + algorithmId;
            double          minLa = endLaLo[0], maxLa = startLaLo[0];
            double          minLo = endLaLo[1], maxLo = startLaLo[1];

            if (startLaLo[0] < endLaLo[0])
            {
                minLa = startLaLo[0];
                maxLa = endLaLo[0];
            }
            if (startLaLo[1] < endLaLo[1])
            {
                minLo = startLaLo[1];
                maxLo = endLaLo[1];
            }
            long[] arr;
            arr = new long[times.Count - 1];

            String       sentence = "select " + La + ", " + Lo + ", APITwitterId, createAt" + " from tweets where " + " searchId = " + searchId + " and " + La + " is not null and " + Lo + " is not null";
            MySqlCommand cmd      = new MySqlCommand(sentence, conn);

            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                reader = cmd.ExecuteReader();
                SmallTweets       st  = new SmallTweets();
                List <SmallTweet> st2 = new List <SmallTweet>();
                while (reader.Read())
                {
                    List <double> tt  = new List <double>();
                    SmallTweet    stt = new SmallTweet((double)reader["La" + algorithmId], (double)reader["Lo" + algorithmId], (DateTime)reader["createAt"], (long)reader["APITwitterId"]);
                    st.push(stt);
                    st2.Add(stt);
                }

                st.move();//desc order
                SmallTweetNode temps;
                long           hello;

                int index = arr.Length - 1;
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = 0;
                }
                if (st.Count != 0)
                {
                    temps = st.smallStart;
                    hello = temps.value.ApiTwitterId;
                }
                else
                {
                    return(arr.ToList());
                }
                while (temps.hasNext)
                {
                    if (temps.next.value.ApiTwitterId > hello)
                    {
                        Console.WriteLine("error" + temps.value.ApiTwitterId + "  " + temps.next.value.ApiTwitterId);
                    }
                    temps = temps.next;
                    hello = temps.value.ApiTwitterId;
                }

                SmallTweetNode temp       = st.smallStart;
                DateTime       oldestDate = times.Last();
                for (; temp.hasNext;)
                {
                    if (temp.value.createAt <= oldestDate)
                    {
                        break;
                    }
                    temp = temp.next;
                }
                for (; temp.hasNext;)
                {
                    if (temp.value.createAt >= times[index])
                    {
                        if (checkedLaLo(temp.value, minLa, minLo, maxLa, maxLo))
                        {
                            arr[index]++;
                        }
                    }
                    else
                    {
                        index--;
                        if (index == -1)
                        {
                            return(arr.ToList());
                        }
                        while (temp.value.createAt < times[index])
                        {
                            index--;
                            if (index == -1)
                            {
                                return(arr.ToList());
                            }
                        }
                        if (checkedLaLo(temp.value, minLa, minLo, maxLa, maxLo))
                        {
                            arr[index]++;
                        }
                    }
                    temp = temp.next;
                }
                return(arr.ToList());
            }
            catch (Exception e)
            {
                if (config.debug)
                {
                    System.Diagnostics.Debug.WriteLine("error " + e.Message);
                    throw (e);
                }
                else
                {
                    return(arr.ToList());
                }
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                conn.Close();
            }
        }