Esempio n. 1
0
        protected override void OnStartUp()
        {
            dbConn.Open();

            using (MySqlCommand command = new MySqlCommand(query, dbConn))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (reader.GetString(2).Contains("PM") || reader.GetString(2).Contains("AM"))
                        {
                            //Print(reader.GetString(1));
                            EconomicData data = new EconomicData()
                            {
                                Id        = reader.GetUInt32(0),
                                Timestamp = DateTime.Parse(reader.GetString(1) + " " + reader.GetString(2)),
                                Currency  = reader.GetString(3),
                                Impact    = reader.GetString(4),
                                Event     = reader.GetString(5),
                                Actual    = reader.GetString(6),
                                Forecast  = reader.GetString(7),
                                Previous  = reader.GetString(8)
                            };


                            if (!dictEvent.ContainsKey(reader.GetString(1))) //if it does not contain date
                            {
                                //Print(string.Format("{0}  |  {1}  |  {2}  |  {3}  |  {4}  |  {5}  |   {6}  |   {7} ", data.Id, data.Timestamp, data.Currency, data.Impact, data.Event, data.Actual, data.Forecast, data.Previous));

                                List <EconomicData> evenStats = new List <EconomicData>();
                                evenStats.Add(data);
                                dictEvent.Add(data.Timestamp.ToShortDateString(), evenStats);
                            }
                            else //if it contains the key, append the data
                            {
                                dictEvent[data.Timestamp.ToShortDateString()].Add(data);
                            }
                        }
                    }
                }
            }
            dbConn.Close();



            #region Yellen test case

            //TO DO: The database time is written in the current timezone. Therefore use the lastupdate time to verify the isDst and modifity the code accordingly.

            dbConn.Open();
            using (MySqlCommand command = new MySqlCommand(queryYellenSpeaks, dbConn))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (reader.GetString(0).Contains("PM") || reader.GetString(0).Contains("AM"))
                        {
                            //if (BarsPeriod.Id == PeriodType.Minute) && (BarsPeriod.Value == 5))
                            //{
                            //Convert Time to EST.
                            DateTime AddOnTime    = DateTime.Now.AddHours(1);
                            DateTime SubtractTime = DateTime.Now.AddHours(-1);

                            //Print(String.Format("{0}      {1}     {2}", DateTime.Now, AddOnTime, SubtractTime));

                            DateTime sqlTime      = DateTime.Parse(reader.GetString(0));
                            DateTime subtractTime = sqlTime.AddHours(-1);
                            DateTime modifiedTime =
                                (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Parse(reader.GetString(0))) ==
                                 true)
                                    ? sqlTime
                                    : subtractTime;

                            //DateTime dstModifiedTime = (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Parse(reader.GetString(0))) == true) ? DateTime.Parse(reader.GetString(0)).AddHours(1) : DateTime.Parse(reader.GetString(0)).AddHours(2);
                            //Print("SQL|EST " + sqlTime + "     " + modifiedTime + "     isDST     " + TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Parse(reader.GetString(0))));
                            //Print("");
                            //}

                            YellenSpeaksTime.Add(modifiedTime);
                        }
                    }
                }
            }

            using (MySqlCommand command = new MySqlCommand(queryEmploymentChange, dbConn))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (reader.GetString(0).Contains("PM") || reader.GetString(0).Contains("AM"))
                        {
                            //if (BarsPeriod.Id == PeriodType.Minute) && (BarsPeriod.Value == 5))
                            //{
                            //Convert Time to EST.
                            DateTime AddOnTime    = DateTime.Now.AddHours(1);
                            DateTime SubtractTime = DateTime.Now.AddHours(-1);

                            //Print(String.Format("{0}      {1}     {2}", DateTime.Now, AddOnTime, SubtractTime));

                            DateTime sqlTime      = DateTime.Parse(reader.GetString(0));
                            DateTime subtractTime = sqlTime.AddHours(-1);
                            DateTime modifiedTime =
                                (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Parse(reader.GetString(0))) ==
                                 true)
                                    ? sqlTime
                                    : subtractTime;

                            //DateTime dstModifiedTime = (TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Parse(reader.GetString(0))) == true) ? DateTime.Parse(reader.GetString(0)).AddHours(1) : DateTime.Parse(reader.GetString(0)).AddHours(2);
                            //Print("SQL|EST " + sqlTime + "     " + modifiedTime + "     isDST     " + TimeZoneInfo.Local.IsDaylightSavingTime(DateTime.Parse(reader.GetString(0))));
                            //Print("");
                            //}

                            nonFarmTime.Add(modifiedTime);
                        }
                    }
                }
            }
            dbConn.Close();

            #endregion


            #region Yellen test case 2


            foreach (DateTime time in YellenSpeaksTime)
            {
                YellenSpeaksTimeHour.Add(
                    DateTime.Parse(time.ToShortDateString() + " " + time.Hour + ":00:00 " + time.ToString("tt")));
                YellenSpeaksTimeDaily.Add(time.ToShortDateString());
                //YellenSpeaksTimeDaily.Add();
            }

            foreach (DateTime time in nonFarmTime)
            {
                nonFarmTimeHour.Add(
                    DateTime.Parse(time.ToShortDateString() + " " + time.Hour + ":00:00 " + time.ToString("tt")));
                nonFarmTimeDaily.Add(time.ToShortDateString());
                //YellenSpeaksTimeDaily.Add();
            }

            #endregion
        }
        protected override void OnStartUp()
        {
            string queryDate = "select datenum from eventprintscreen order by datenum asc";

            dbConn.Open();
            using (MySqlCommand command = new MySqlCommand(queryDate, dbConn))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        listDateSaved.Add(reader.GetString(0));
                    }
                }
            }

            dbConn.Close();

            dbConn.Open();
            using (MySqlCommand command = new MySqlCommand(query, dbConn))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (reader.GetString(2).Contains("PM") || reader.GetString(2).Contains("AM"))
                        {
                            DateTime sqlTime      = DateTime.Parse(reader.GetString(1) + " " + reader.GetString(2));
                            DateTime subtractTime = sqlTime.AddHours(-1);
                            DateTime modifiedTime = (TimeZoneInfo.Local.IsDaylightSavingTime(sqlTime) == true) ? sqlTime : subtractTime;

                            EconomicData data = new EconomicData()
                            {
                                Id        = reader.GetUInt32(0),
                                Timestamp = modifiedTime,
                                Currency  = reader.GetString(3),
                                Impact    = reader.GetString(4),
                                Event     = reader.GetString(5),
                                Actual    = reader.GetString(6),
                                Forecast  = reader.GetString(7),
                                Previous  = reader.GetString(8)
                            };

                            if (!timeClusteredEvents.ContainsKey(modifiedTime)) //if it does not contain date
                            {
                                List <EconomicData> eventData = new List <EconomicData>();
                                eventData.Add(data);
                                timeClusteredEvents.Add(modifiedTime, eventData);
                            }
                            else //if it contains the key, append the data
                            {
                                timeClusteredEvents[modifiedTime].Add(data);
                            }
                        }
                    }
                }
            }
            dbConn.Close();


            foreach (KeyValuePair <DateTime, List <EconomicData> > valuePair in timeClusteredEvents)
            {
                //Print(valuePair.Key);
                string hastag      = "";
                string currentDate = valuePair.Key.ToShortDateString();
                foreach (EconomicData data in valuePair.Value)
                {
                    if (data.Currency == "USD" &&
                        (data.Impact == "High" || data.Impact == "Medium" || data.Impact == "Low"))
                    {
                        hastag = hastag + string.Format("{0},", data.Event.Trim());
                    }


                    //Print(currentDate);
                }

                if (hastag != "")
                {
                    if (distPntScrn.ContainsKey(currentDate) == true)
                    {
                        distPntScrn[currentDate] = distPntScrn[currentDate] + hastag;
                    }
                    else
                    {
                        distPntScrn.Add(currentDate, hastag);
                    }
                }
            }

            foreach (KeyValuePair <string, string> pair in distPntScrn)
            {
                //Print(pair.Key + " | " + pair.Value.Remove(pair.Value.Length -1));
                SaveDataToDatabase(pair.Key, pair.Value.Remove(pair.Value.Length - 1));
            }
        }