示例#1
0
 private bool checkedLaLo(SmallTweet st, double minLa, double minLo, double maxLa, double maxLo)
 {
     if (minLa <= st.la && st.la <= maxLa && minLo <= st.lo && maxLo >= st.lo)
     {
         return(true);
     }
     return(false);
 }
示例#2
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++;
        }
示例#3
0
 public SmallTweetNode(SmallTweet value)
 {
     this.value = value;
 }
示例#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();
            }
        }