示例#1
0
        private DateTime?getMinDate(String[] ids, DemoI nn)
        {
            bool     first = true;
            DateTime?dt    = null;

            for (int i = 8; (Double)i <= (Double)(ids.Count()) / 2 + 3; i++)
            {
                int            Id         = Convert.ToInt32(ids[(i - 4) * 2]); //get searchIds
                TwitterSearchI tempSearch = nn.getSearch(Id);

                if (tempSearch != null)
                {
                    DateTime temp = (DateTime)(tempSearch.searchInfomation.finishedLastTwitterDate);
                    if (first)
                    {
                        dt    = temp;
                        first = false;
                    }
                    else if (temp < dt)
                    {
                        dt = temp;
                    }
                }
            }
            return(dt);
        }
示例#2
0
        public ActionResult ViewSearch()
        {
            int searchId = 0;

            try
            {
                searchId = Convert.ToInt32(Request.Form["searchSelector"]);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                Response.Redirect("/search/demo");
            }
            var            mm = System.Web.HttpContext.Current.Application["demo"];
            DemoI          nn = (DemoI)mm;
            TwitterSearchI ts = nn.getSearch(searchId);

            if (ts == null)
            {
                Response.Redirect("/Search/demo");
                return(View("Demo"));
            }
            ViewBag.ts = ts;
            return(View());
        }
示例#3
0
        public ActionResult NewSearch()
        {
            var   mm = System.Web.HttpContext.Current.Application["demo"];
            DemoI nn = (DemoI)mm;

            if (Request.Form["back"] != null)
            {
                String         title   = Request.Unvalidated.Form["searchTitle"];
                String         include = Request.Unvalidated.Form["include"];
                String         exclude = Request.Unvalidated.Form["exclude"];
                TwitterSearchI s       = nn.createSearch(include, exclude, title);
                if (nn.addSearch(s))
                {
                    Response.Redirect("/Search/demo");
                    return(View("Demo"));
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
示例#4
0
        public List <object> loadTweetsForAnalyze(string[] ids, int algorithmId = 0)
        {
            if (ids.Count() < 8)
            {
                return(null);
            }

            String[] a = ids;
            DateTime startDate;
            DateTime endDate;

            if (ids[0] == "-1" && ids[4] == "-1")//if it is the first time load tweets
            {
                DateTime?startDatet = getMaxDate(ids, this);
                DateTime?endDatet   = getMinDate(ids, this);
                if (startDatet == null || endDatet == null)
                {
                    return(null);
                }
                startDate = (DateTime)startDatet;
                endDate   = (DateTime)endDatet;
                if ((endDate - startDate) <= TimeSpan.FromHours(1))  // if there is no valid intersection return null
                {
                    return(null);
                }
            }
            else// if not first time
            {
                startDate = ConvertDate(ids[0], ids[1], ids[2], ids[3]);
                endDate   = ConvertDate(ids[4], ids[5], ids[6], ids[7]);
            }

            IEnumerable <List <double> > tts = new List <List <double> >();

            for (int i = 8; i <= (Double)(ids.Count()) / 2 + 3; i++)
            {
                TwitterSearchI        tsi     = getSearch(Convert.ToInt32(ids[((i - 4) * 2)]));
                int                   colorId = Convert.ToInt32(ids[((i - 4) * 2 + 1)]);
                List <List <double> > temp    = tsi.loadTinyTweets(startDate, endDate, colorId, algorithmId);
                tts = tts.Concat(temp);
            }

            List <object>         finalList = new List <object>();
            List <List <double> > mm        = tts.ToArray().ToList();

            finalList.Add(mm);

            if (ids[0] == "-1" && ids[4] == "-1")//if it is the first time load tweets
            {
                List <long>   tempInterval = new List <long>();
                List <long[]> tempDmap     = generateDateMap(startDate, endDate, ref tempInterval);
                finalList.Add(tempDmap);
                finalList.Add(tempInterval);
            }
            return(finalList);
        }
示例#5
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);
            }
        }
示例#6
0
 public bool addSearch(TwitterSearchI ts)
 {
     mu.WaitOne();
     runningSearch.Add(ts);  // will mutex
     if (runningPoint <= -1) //if at the rest status no work
     {
         runningPoint = runningSearchR.Count - 1;
     }
     mu.ReleaseMutex();
     return(true);
 }
示例#7
0
        public List <List <double> > loadTinyTweets(TwitterSearchI tsi, DateTime start, DateTime end, int colorId, int algorithmId = 0)
        {
            MySqlConnection conn     = connect();
            String          sentence = "select * from tweets where La" + algorithmId + " is not null and  @start <= createAt   and createAt <= @end and searchId = " + tsi.searchInfomation.searchId + " ORDER BY rand() limit " + config.analyzeTwitterLoaderCount;
            MySqlCommand    cmd      = new MySqlCommand(sentence, conn);

            cmd.Parameters.AddWithValue("@start", start.ToString("yyyy-MM-dd HH:mm:ss"));
            cmd.Parameters.AddWithValue("@end", end.ToString("yyyy-MM-dd HH:mm:ss"));

            MySqlDataReader reader = null;
            Random          rd     = new Random();

            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                reader = cmd.ExecuteReader();
                List <List <double> > tts = new List <List <double> >();
                while (reader.Read())
                {
                    List <double> tt = new List <double>();

                    tt.Add((double)reader["La" + algorithmId] + ((double)rd.Next(0, 100) - 50) / 50);
                    tt.Add((double)reader["Lo" + algorithmId] + ((double)rd.Next(0, 100) - 50) / 50);
                    tt.Add(colorId);
                    tts.Add(tt);
                }

                return(tts);
            }
            catch (Exception ex)
            {
                if (config.debug)
                {
                    throw ex;
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                conn.Close();
            }
        }
示例#8
0
        public TwitterSearchI getSearch(int id)
        {
            mu.WaitOne();
            TwitterSearchI tts = null;

            foreach (TwitterSearchI ts in runningSearch)
            {
                if (ts.searchInfomation.searchId == id)
                {
                    tts = ts;
                }
            }
            mu.ReleaseMutex();
            return(tts);
        }
示例#9
0
        public bool updateSearchOnResume(TwitterSearchI s)// when resume and detected did not save search normally need to get information
        {
            MySqlConnection conn   = connect();
            MySqlCommand    cmd    = new MySqlCommand("select * from tweets     where searchId =" + s.searchInfomation.searchId + " ORDER BY realTwitterId DESC limit 1", conn);
            MySqlDataReader reader = null;

            s.searchInfomation.needResume = true;

            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    if (s.searchInfomation.finishedLastTwitterId < (long)reader["realTwitterId"]) // means new twitter is stroed in database in this running search
                    {
                        s.searchInfomation.maxIdOnResume = (long)reader["APITwitterId"];
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                if (config.debug)
                {
                    throw ex;
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                conn.Close();
            }
        }
示例#10
0
        private void runSearch()
        {
            while (true)
            {
                bool finished = true;

                mu.WaitOne();
                //when the status is waiting and there are searches in list, we need to check i the first search finished waiting the time interval
                if (checkDate() != -1)
                {
                    finished     = false;
                    runningPoint = checkDate();
                }
                if (runningPoint != -1) // it means there is new added search xxxxx
                {
                    finished = false;
                }
                mu.ReleaseMutex();
                while (!finished)
                {
                    mu.WaitOne();
                    if (runningPoint >= runningSearch.Count) //check if end
                    {
                        finished     = true;
                        runningPoint = -1;
                    }
                    if (runningPoint >= 0) //if delete the first search when there is only one search in list and it occured before this critical section, it will cause problem
                    {
                        TwitterSearchI temps = runningSearch[runningPoint];
                        runningPoint++;
                        mu.ReleaseMutex();
                        temps.run();
                    }
                    else
                    {
                        finished = true;
                        mu.ReleaseMutex();
                    }
                }
                System.Diagnostics.Debug.WriteLine("Demo waiting");
                Thread.Sleep(timeSleep);
            }
        }
示例#11
0
        //return a list of search Names
        private List <String> getNames(List <int> searcheIds)
        {
            List <String> names = new List <string>();

            names.Add("Date");
            for (int i = 0; i < searcheIds.Count; i++)
            {
                TwitterSearchI tempSearch = getSearch(searcheIds[i]);
                if (tempSearch != null)
                {
                    names.Add(tempSearch.searchInfomation.searchTitle);
                }
                else
                {
                    names.Add("deleted");
                }
            }
            return(names);
        }
示例#12
0
        public bool updateSearchStatus(TwitterSearchI s)
        {
            MySqlConnection conn = connect();

            if (conn == null)
            {
                return(false);
            }
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                string       cmdText = @"update search set searchStatus = " + s.searchInfomation.status + " where searchId = " + s.searchInfomation.searchId;
                MySqlCommand command = new MySqlCommand(cmdText, conn);
                int          i       = command.ExecuteNonQuery();
                if (i == 1)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                if (config.debug)
                {
                    throw e;
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                conn.Close();
            }
        }
示例#13
0
        public int getSearchStatus(TwitterSearchI s)
        {
            MySqlConnection conn   = connect();
            MySqlCommand    cmd    = new MySqlCommand("select searchStatus from search where searchId = " + s.searchInfomation.searchId, conn);
            MySqlDataReader reader = null;

            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    return(Int32.Parse(reader[0].ToString()));
                }
                return(-1);
            }
            catch (Exception ex) {
                if (config.debug)
                {
                    throw ex;
                }
                else
                {
                    return(-2);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                conn.Close();
            }
        }
示例#14
0
        /*
         * based on each search's first tweet's date;
         **/
        private DateTime?getMaxDate(String[] ids, DemoI nn)
        {
            bool     first = true;
            DateTime?dt    = null;

            for (int i = 8; i <= (Double)(ids.Count()) / 2 + 3; i++)
            {
                TwitterSearchI tempSearch = nn.getSearch(Convert.ToInt32(ids[(i - 4) * 2]));
                if (tempSearch != null)
                {
                    DateTime temp = (DateTime)tempSearch.searchInfomation.firstTwitterDate;
                    if (first)
                    {
                        dt    = temp;
                        first = false;
                    }
                    else if (temp > dt)
                    {
                        dt = temp;
                    }
                }
            }
            return(dt);
        }
示例#15
0
 public DateTime?loadLatestLocationEffectiveDate(TwitterSearchI search, int algorithmId = 0)
 {
     return(dataBase.loadLatestLocationEffectiveDate(this, 0));
 }
示例#16
0
        public int saveNewSearch(TwitterSearchI s)
        {
            MySqlConnection conn = connect();

            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                string       cmdText = @"INSERT INTO search (searchTitle ,deleted,searchStatus,include ,exclude,startDate ,endDate ,firstTwitterDate ,tempLastTwitterDate ,tempLastTwitterId ,finishedLastTwitterDate, finishedLastTwitterId ) VALUES (@searchTitle ,@deleted,@searchStatus,@include ,@exclude,@startDate ,@endDate ,@firstTwitterDate ,@tempLastTwitterDate ,@tempLastTwitterId ,@finishedLastTwitterDate,@finishedLastTwitterId )";
                MySqlCommand command = new MySqlCommand(cmdText, conn);

                command.Parameters.AddWithValue("@searchTitle", s.searchInfomation.searchTitle);
                command.Parameters.AddWithValue("@deleted", s.searchInfomation.deleted);
                command.Parameters.AddWithValue("@searchStatus", s.searchInfomation.status);
                String tempI = null;
                String tempE = null;
                foreach (String i in s.searchInfomation.include)
                {
                    if (tempI != null)
                    {
                        tempI += '\n';
                    }
                    tempI += i;
                }
                foreach (String i in s.searchInfomation.exclude)
                {
                    if (tempE != null)
                    {
                        tempE += '\n';
                    }
                    tempE += i;
                }
                command.Parameters.AddWithValue("@include", tempI);
                command.Parameters.AddWithValue("@exclude", tempE);
                command.Parameters.AddWithValue("@startDate", s.searchInfomation.startDate.ToString("yyyy-MM-dd HH:mm:ss"));
                if (s.searchInfomation.endDate != null)
                {
                    command.Parameters.AddWithValue("@endDate", ((DateTime)s.searchInfomation.endDate).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    command.Parameters.AddWithValue("@endDate", null);
                }
                if (s.searchInfomation.firstTwitterDate != null)
                {
                    command.Parameters.AddWithValue("@firstTwitterDate", ((DateTime)s.searchInfomation.firstTwitterDate).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    command.Parameters.AddWithValue("@firstTwitterDate", null);
                }
                if (s.searchInfomation.tempLastTwitterDate != null)
                {
                    command.Parameters.AddWithValue("@tempLastTwitterDate", ((DateTime)s.searchInfomation.tempLastTwitterDate).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    command.Parameters.AddWithValue("@tempLastTwitterDate", null);
                }
                if (s.searchInfomation.finishedLastTwitterDate != null)
                {
                    command.Parameters.AddWithValue("@finishedLastTwitterDate", ((DateTime)s.searchInfomation.finishedLastTwitterDate).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    command.Parameters.AddWithValue("@finishedLastTwitterDate", null);
                }
                command.Parameters.AddWithValue("@tempLastTwitterId", s.searchInfomation.tempLastTwitterId);
                command.Parameters.AddWithValue("@finishedLastTwitterId", s.searchInfomation.finishedLastTwitterId);
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                command.ExecuteNonQuery();
                int id = (int)command.LastInsertedId;
                return(id);
            }
            catch (Exception e)
            {
                if (config.debug)
                {
                    throw e;
                }
                else
                {
                    return(-1);
                }
            }
            finally
            {
                conn.Close();
            }
        }
示例#17
0
        public bool updateSearch(TwitterSearchI s)
        {
            MySqlConnection conn = connect();

            if (conn == null)
            {
                return(false);
            }
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                string       cmdText = @"update  search set searchStatus = @searchStatus, firstTwitterDate = @firstTwitterDate , finishedLastTwitterDate = @finishedLastTwitterDate , finishedLastTwitterId= @finishedLastTwitterId  , tempLastTwitterId =@tempLastTwitterId ,  tempLastTwitterDate = @tempLastTwitterDate where searchId = @searchId";
                MySqlCommand command = new MySqlCommand(cmdText, conn);
                command.Parameters.AddWithValue("@searchStatus", s.searchInfomation.status);
                if (s.searchInfomation.firstTwitterDate != null)
                {
                    command.Parameters.AddWithValue("@firstTwitterDate", ((DateTime)s.searchInfomation.firstTwitterDate).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    command.Parameters.AddWithValue("@firstTwitterDate", null);
                }
                if (s.searchInfomation.finishedLastTwitterDate != null)
                {
                    command.Parameters.AddWithValue("@finishedLastTwitterDate", ((DateTime)s.searchInfomation.finishedLastTwitterDate).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    command.Parameters.AddWithValue("@finishedLastTwitterDate", null);
                }
                if (s.searchInfomation.tempLastTwitterDate != null)
                {
                    command.Parameters.AddWithValue("@tempLastTwitterDate", ((DateTime)s.searchInfomation.tempLastTwitterDate).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    command.Parameters.AddWithValue("@tempLastTwitterDate", null);
                }
                command.Parameters.AddWithValue("@tempLastTwitterId", s.searchInfomation.tempLastTwitterId);
                command.Parameters.AddWithValue("@finishedLastTwitterId", s.searchInfomation.finishedLastTwitterId);
                command.Parameters.AddWithValue("@searchId", s.searchInfomation.searchId);
                command.ExecuteNonQuery();
                command.Parameters.Clear();
                return(true);
            }
            catch (Exception e)
            {
                if (config.debug)
                {
                    throw e;
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                conn.Close();
            }
        }
示例#18
0
        public DateTime?loadLatestLocationEffectiveDate(TwitterSearchI tsi, int algorithmId = 0)
        {
            AlgorithmInfo al = loadAlgorithmInfo(algorithmId);
            TwitterModel  tm;

            if (al == null || al.lastMaxId < 0)
            {
                return(null);
            }
            else
            {
                tm = loadBasicTwitterByRealId(al.lastMaxId);
                if (tm == null)
                {
                    return(null);
                }
                if (tsi.searchInfomation.finishedLastTwitterDate == null)
                {
                    return(null);
                }
                if (tsi.searchInfomation.finishedLastTwitterDate <= tm.createAt)
                {
                    return(tm.createAt);
                }
            }
            MySqlConnection conn   = connect();
            MySqlCommand    cmd    = new MySqlCommand("select createAt from tweets where searchId = " + tsi.searchInfomation.searchId + " and realTwitterId < " + al.lastMaxId + " and APITwitterId < " + tm.APITwitterId + " ORDER BY APITwitterId DESC limit 1", conn);
            MySqlDataReader reader = null;


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

                if (reader.Read())
                {
                    DateTime?h = reader["createAt"] as DateTime?;
                    return(h);
                }

                return(null);
            }
            catch (Exception ex)
            {
                if (config.debug)
                {
                    throw ex;
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                conn.Close();
            }
        }