Пример #1
0
        public static void Add_Event_Notification(ConfigFiles jsonConfigPaths, Event_Notification eventNotification)
        {
            MySql.Data.MySqlClient.MySqlConnection conn;

            conn = new MySql.Data.MySqlClient.MySqlConnection();

            MySqlConnectionStringBuilder conn_string_builder = new MySqlConnectionStringBuilder();
            string json = System.IO.File.ReadAllText(jsonConfigPaths.mysqlCredentialsInsert_JsonFile);

            conn = new MySqlConnection(conn_string_builder.ToString());
            try
            {
                conn.Open();
            }
            catch (Exception erro)
            {
                Console.WriteLine(erro);
            }

            try
            {
                MySqlCommand cmd = conn.CreateCommand();
                cmd.Connection = conn;

                cmd.CommandText = "INSERT INTO `geo_data`.`geo_events` (`geo_event_agency`,`geo_event_title`,`geo_event_url`,`geo_event_starttime`,`geo_event_category`,`geo_event_type`,`geo_event_ident`,`geo_event_location_latitude`,`geo_event_location_longitude`,`geo_event_notify`) VALUES (@event_notification_agency,@event_notification_title,@event_notification_url,FROM_UNIXTIME(@event_notification_datetime),@event_notification_category,@event_notification_type,@event_notification_ident,@event_notification_latitude,@event_notification_longitude,1);";
                cmd.Parameters.AddWithValue("@event_notification_agency", eventNotification.eventNotification_Agency);
                cmd.Parameters.AddWithValue("@event_notification_title", eventNotification.eventNotification_Title);
                cmd.Parameters.AddWithValue("@event_notification_url", eventNotification.eventNotification_URL);
                cmd.Parameters.AddWithValue("@event_notification_datetime", eventNotification.eventNotification_DatetimeEpoch);
                cmd.Parameters.AddWithValue("@event_notification_category", eventNotification.eventNotification_Category);
                cmd.Parameters.AddWithValue("@event_notification_type", eventNotification.eventNotification_Type);
                cmd.Parameters.AddWithValue("@event_notification_ident", eventNotification.eventNotification_UniqueID);
                cmd.Parameters.AddWithValue("@event_notification_latitude", eventNotification.eventNotification_Latitude);
                cmd.Parameters.AddWithValue("@event_notification_longitude", eventNotification.eventNotification_Longitude);

                cmd.ExecuteNonQuery();

                cmd.Dispose();
            }
            catch (MySqlException ex)
            {
                int errorcode = ex.Number;
                if (errorcode != 1062)
                {
                    Console.WriteLine("Notification Error:\t" + ex.Message);
                    Console.Read();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            conn.Close();
        }
Пример #2
0
        public static void Process_Applicable_Notification(ConfigFiles jsonConfigPaths, FeaturesItem earthquake)
        {
            List <Event_Notification> eventNotificationList = new List <Event_Notification>();
            List <UserSite>           userSiteList          = new List <UserSite>();

            string json = System.IO.File.ReadAllText(jsonConfigPaths.userSites_JsonFile);

            userSiteList = JsonConvert.DeserializeObject <List <UserSite> >(json);

            foreach (UserSite user_site in userSiteList)
            {
                double earthquake_latitude  = earthquake.geometry.coordinates[1];
                double earthquake_longitude = earthquake.geometry.coordinates[0];

                double hq_distance = GetDistance(earthquake_latitude, earthquake_longitude, user_site.coordinates.latitude, user_site.coordinates.longitude);

                double magnitude = earthquake.properties.mag;

                if (((hq_distance < 50) || (earthquake.properties.tsunami.Equals(1)) || (magnitude >= 2 && hq_distance < 100) || (magnitude >= 3 && hq_distance < 250) || (magnitude >= 4 && hq_distance < 500) || (magnitude >= 5 && hq_distance < 1500) || (magnitude >= 6)))
                {
                    if (earthquake.properties.tsunami.Equals(1))
                    {
                        string notify_place = earthquake.properties.place + " Tsunami Evaluation Available";
                        earthquake.properties.place = notify_place;
                    }

                    Event_Notification eventNotification = new Event_Notification();
                    eventNotification.eventNotification_Agency        = "48941";
                    eventNotification.eventNotification_Title         = earthquake.properties.title;
                    eventNotification.eventNotification_URL           = earthquake.properties.url;
                    eventNotification.eventNotification_DatetimeEpoch = (earthquake.properties.time / 1000);
                    eventNotification.eventNotification_Category      = "Earthquake";
                    eventNotification.eventNotification_Type          = "Earthquake";
                    eventNotification.eventNotification_UniqueID      = earthquake.id;
                    eventNotification.eventNotification_Latitude      = earthquake.geometry.coordinates[1];
                    eventNotification.eventNotification_Longitude     = earthquake.geometry.coordinates[0];
                    Add_Event_Notification(jsonConfigPaths, eventNotification);
                }
            }
        }
Пример #3
0
        public static void Process_Storage_Report()
        {
            EIA_Storage_Data_Report StorageReport = new EIA_Storage_Data_Report();
            string url = "https://ir.eia.gov/wpsr/table1.csv";

            string reportText = Download_Report_Text(url);

            string[] reportLinesArray;

            reportLinesArray = reportText.Split('\n');

            int  counter         = 0;
            bool continue_status = true;

            List <EIA_Storage_Data_Values> dataList = new List <EIA_Storage_Data_Values>();

            foreach (string item in reportLinesArray)
            {
                if (continue_status == true)
                {
                    if (counter > 0)
                    {
                        String[] dataArray = item.Split("\",\"");

                        string reportStubString = dataArray[0].Replace("\"", "");

                        if (reportStubString.Replace("\"", "").Contains("STUB_1"))
                        {
                            continue_status = false;
                        }
                        else
                        {
                            EIA_Storage_Data_Values dataItem = new EIA_Storage_Data_Values();
                            dataItem.ReportStub = reportStubString;

                            dataItem.CurrentWeek              = dataArray[1].Replace("\"", "");
                            dataItem.WeekAgo                  = dataArray[2].Replace("\"", "");
                            dataItem.WeekAgo_Difference       = Double.Parse(dataArray[3].Replace("\"", "").Replace(",", "").Trim());
                            dataItem.WeekAgo_PercentageChange = Double.Parse(dataArray[4].Replace("\"", "").Replace(",", "").Trim());
                            dataItem.YearAgo                  = dataArray[5].Replace("\"", "");
                            dataItem.YearAgo_DifferenceAmount = Double.Parse(dataArray[6].Replace("\"", "").Replace(",", "").Trim());
                            dataItem.YearAgo_PercentChange    = Double.Parse(dataArray[7].Replace("\"", "").Replace(",", "").Trim());

                            dataList.Add(dataItem);
                            StorageReport.Values = dataList;
                        }
                    }
                    else
                    {
                        String[] headerArray = item.Split("\",\"");

                        EIA_Storage_Data header = new EIA_Storage_Data();
                        header.ReportStub               = headerArray[0].Replace("\"", "");
                        header.CurrentWeek              = headerArray[1].Replace("\"", "");
                        header.WeekAgo                  = headerArray[2].Replace("\"", "");
                        header.WeekAgo_Difference       = headerArray[3].Replace("\"", "");
                        header.WeekAgo_PercentageChange = headerArray[4].Replace("\"", "");
                        header.YearAgo                  = headerArray[5].Replace("\"", "");
                        header.YearAgo_DifferenceAmount = headerArray[6].Replace("\"", "");
                        header.YearAgo_PercentChange    = headerArray[7].Replace("\"", "");

                        StorageReport.Header_Data = header;
                    }
                }
                counter++;
            }

            List <Event_Notification> notifications = new List <Event_Notification>();

            Console.WriteLine("Weekly Report\t " + StorageReport.Header_Data.WeekAgo_Difference + "\t" + StorageReport.Header_Data.WeekAgo_PercentageChange);

            foreach (EIA_Storage_Data_Values storageColumnData in StorageReport.Values)
            {
                if (storageColumnData.ReportStub.Equals("Crude Oil"))
                {
                    Event_Notification energyNotification = new Event_Notification();
                    string             title;
                    if (storageColumnData.WeekAgo_Difference < 0)
                    {
                        title = "Storage Drop Week Over Week";
                        Console.WriteLine(title);
                    }
                    else
                    {
                        title = "Storage Gain Week Over Week";
                        Console.WriteLine(title);
                    }

                    long unixTimestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    energyNotification.eventNotification_Agency        = "48970";
                    energyNotification.eventNotification_Title         = title;
                    energyNotification.eventNotification_DatetimeEpoch = unixTimestamp;
                    energyNotification.eventNotification_Latitude      = 35.9860348;
                    energyNotification.eventNotification_Longitude     = -96.7892684;
                    energyNotification.eventNotification_Category      = "Energy";
                    energyNotification.eventNotification_Type          = "Economic Data";
                    notifications.Add(energyNotification);
                    Console.WriteLine(storageColumnData.ReportStub + "\t" + storageColumnData.WeekAgo_Difference + "\t" + storageColumnData.WeekAgo_PercentageChange);
                }
            }

            string configFilePaths = "filePaths.json";
            bool   exists          = File.Exists(configFilePaths);
            string json            = null;

            try
            {
                json = System.IO.File.ReadAllText(configFilePaths, System.Text.Encoding.UTF8);
            }
            catch (Exception json_read)
            {
                Console.WriteLine(json_read.Message);
            }

            if (json != null) // Check That JSON String Read Above From File Contains Data
            {
                ConfigFiles jsonConfigPaths = new ConfigFiles();
                jsonConfigPaths = JsonConvert.DeserializeObject <ConfigFiles>(json);
                Add_Event_Notifications(jsonConfigPaths, notifications);
            }
        }
        public static void Process_NHC_Feed(ConfigFiles jsonConfigPaths, string basin, List <Coordinates> shorelineCoordinatesList)
        {
            string feedURL = "https://www.nhc.noaa.gov/gis-" + basin + ".xml";

            XNamespace nhcNS = "https://www.nhc.noaa.gov";

            string Title, pubDate, Description;

            var responseXml = XDocument.Load(feedURL);

            try
            {
                Title = responseXml.Element("rss").Element("channel").Element("title").Value.ToString();
                Console.WriteLine(Title);

                pubDate = responseXml.Element("rss").Element("channel").Element("pubDate").Value.ToString();
                Console.WriteLine(pubDate);
            }
            catch (Exception e)
            {
                // Console.Read();
            }

            try
            {
                Description = responseXml.Element("rss").Element("channel").Element("description").Value.ToString();

                if (Description.Length < 1)
                {
                    Description = responseXml.Element("rss").Element("channel").Element("description").Value.ToString();
                    //  Description = responseXml.Element("rss").Element("channel").Element(ns + "summary").Value.ToString();

                    Console.WriteLine(Description);
                }

                Console.WriteLine(Description);
            }
            catch (Exception e)
            {
                // Console.Read();
            }


            foreach (var item in responseXml.Descendants("item"))
            {
                NHC_Item    Cyclone_Feed_Item = new NHC_Item();
                NHC_Cyclone Cyclone_Details   = new NHC_Cyclone();

                Cyclone_Feed_Item.Title = item.Element("title").Value.ToString();
                Console.WriteLine(Cyclone_Feed_Item.Title);

                Cyclone_Feed_Item.Description = item.Element("description").Value.ToString();
                Console.WriteLine(Cyclone_Feed_Item.Description);

                Cyclone_Feed_Item.pubDate = item.Element("pubDate").Value.ToString();
                Console.WriteLine(Cyclone_Feed_Item.pubDate);

                Cyclone_Feed_Item.Link = item.Element("link").Value.ToString();
                Console.WriteLine(Cyclone_Feed_Item.Link);

                Cyclone_Feed_Item.GUID = item.Element("guid").Value.ToString();
                Console.WriteLine(Cyclone_Feed_Item.GUID);

                Cyclone_Feed_Item.Author = item.Element("author").Value.ToString();
                Console.WriteLine(Cyclone_Feed_Item.Author);

                var descElements = item.Elements(nhcNS + "Cyclone");

                foreach (XElement nhcElement in item.Descendants(nhcNS + "Cyclone"))
                {
                    try
                    {
                        Cyclone_Details.Center = nhcElement.Element(nhcNS + "center").Value.ToString();
                    }
                    catch (Exception nhcElement_parse)
                    {
                    }

                    try
                    {
                        Cyclone_Details.Type = nhcElement.Element(nhcNS + "type").Value.ToString();
                    }
                    catch (Exception nhcElement_parse)
                    {
                    }

                    try
                    {
                        Cyclone_Details.Name = nhcElement.Element(nhcNS + "name").Value.ToString();
                    }
                    catch (Exception nhcElement_parse)
                    {
                    }

                    try
                    {
                        Cyclone_Details.Wallet = nhcElement.Element(nhcNS + "wallet").Value.ToString();
                    }
                    catch (Exception nhcElement_parse)
                    {
                    }

                    try
                    {
                        Cyclone_Details.ATCF = nhcElement.Element(nhcNS + "atcf").Value.ToString();
                    }
                    catch (Exception nhcElement_parse)
                    {
                    }

                    try
                    {
                        Cyclone_Details.Datetime = nhcElement.Element(nhcNS + "datetime").Value.ToString();
                    }
                    catch (Exception nhcElement_parse)
                    {
                    }

                    try
                    {
                        Cyclone_Details.Wind = nhcElement.Element(nhcNS + "wind").Value.ToString();
                    }
                    catch (Exception nhcElement_parse)
                    {
                    }

                    try
                    {
                        Cyclone_Details.Headline = nhcElement.Element(nhcNS + "headline").Value.ToString();
                    }
                    catch (Exception nhcElement_parse)
                    {
                    }
                }

                if (Cyclone_Details.Center != null)
                {
                    Cyclone_Feed_Item.Cyclone_Details = Cyclone_Details;
                    string NHC_Feed_Item_Json = JsonConvert.SerializeObject(Cyclone_Feed_Item);

                    string[] centerCoordinatesArray = Cyclone_Feed_Item.Cyclone_Details.Center.Split(",");
                    double   centerLatitude         = Double.Parse(centerCoordinatesArray[0].Trim());
                    double   centerLongitude        = Double.Parse(centerCoordinatesArray[1].Trim());

                    Coordinates currentLocation = new Coordinates();
                    currentLocation.Latitude  = centerLatitude;
                    currentLocation.Longitude = centerLongitude;

                    Coordinates nearestShorelineCoordinates = Nearest_Shoreline_Coordinates(currentLocation, shorelineCoordinatesList);
                    Console.WriteLine("Nearest Shoreline Coordinate:\t" + nearestShorelineCoordinates.Latitude + "," + nearestShorelineCoordinates.Longitude);

                    DateTime dateValue = DateTime.ParseExact(Cyclone_Feed_Item.pubDate, "ddd, dd MMM yyyy HH:mm:ss GMT", CultureInfo.InvariantCulture).ToUniversalTime();

                    string unique_id_string = centerLatitude.ToString() + "," + centerLongitude.ToString();
                    Console.WriteLine(unique_id_string);
                    Event_Notification eventNotification = new Event_Notification();
                    eventNotification.eventNotification_Agency    = "48945";
                    eventNotification.eventNotification_Category  = "NHCAdvisory";
                    eventNotification.eventNotification_Type      = "NHCAdvisory";
                    eventNotification.eventNotification_Title     = Cyclone_Feed_Item.Title;
                    eventNotification.eventNotification_Latitude  = centerLatitude;
                    eventNotification.eventNotification_Longitude = centerLongitude;
                    eventNotification.eventNotification_UniqueID  = Cyclone_Feed_Item.Cyclone_Details.ATCF + " " + unique_id_string;
                    TimeSpan t             = dateValue - new DateTime(1970, 1, 1);
                    long     dateTimeEpoch = (long)t.TotalSeconds;

                    eventNotification.eventNotification_DatetimeEpoch = dateTimeEpoch;
                    if (basin.Equals("at"))
                    {
                        eventNotification.eventNotification_ImageURL = "https://www.nhc.noaa.gov/xgtwo/two_atl_5d0.png";
                    }
                    if (basin.Equals("ep"))
                    {
                        eventNotification.eventNotification_ImageURL = "https://www.nhc.noaa.gov/xgtwo/two_pac_5d0.png";
                    }
                    if (basin.Equals("cp"))
                    {
                        eventNotification.eventNotification_ImageURL = "https://www.nhc.noaa.gov/xgtwo/two_cpac_5d0.png";
                    }

                    Add_Event_Notification(jsonConfigPaths, eventNotification);
                }
            }
        }