Exemple #1
0
        public List <Earthquake> EarthquakeTrans(object earthquakeEvent, Earthquake.DataSource dataSource,
                                                 string Domain, string LatLng, string Time, string Intensity)
        {
            this.Domain    = Domain;
            this.LatLng    = LatLng;
            this.Time      = Time;
            this.Intensity = Intensity;
            eqList.Clear();

            if (earthquakeEvent == null)
            {
                return(null);
            }

            switch (dataSource)
            {
            case Earthquake.DataSource.PALERT:
                List <Palert> palertEventList = JsonConvert.DeserializeObject <List <Palert> >((string)earthquakeEvent);
                foreach (Palert palertEvent in palertEventList)
                {
                    Earthquake eq = palertTrans(palertEvent);
                    eqList.Add(eq);
                }
                return(eqList);

            case Earthquake.DataSource.CWB:
                cwbTrans((string)earthquakeEvent);
                return(eqList);

            case Earthquake.DataSource.CKAN:
                JObject ckanlist = JObject.Parse((string)earthquakeEvent);
                ckanTrans(ckanlist);

                return(eqList);

            default:
                break;
            }

            // DEBUG
            return(null);
        }
Exemple #2
0
        public List <Earthquake> EarthquakeTrans(object earthquakeEvent, Earthquake.DataSource dataSource,
                                                 string startTime, string endTime)
        {
            eqList.Clear();
            this.startTime = startTime;
            this.endTime   = endTime;

            if (earthquakeEvent == null)
            {
                return(null);
            }

            switch (dataSource)
            {
            case Earthquake.DataSource.PALERT:
                List <Palert> palertEventList = JsonConvert.DeserializeObject <List <Palert> >((string)earthquakeEvent);
                foreach (Palert palertEvent in palertEventList)
                {
                    Earthquake eq = palertTrans(palertEvent);
                    eqList.Add(eq);
                }
                return(eqList);

            case Earthquake.DataSource.CWB:
                cwbTrans((string)earthquakeEvent);
                return(eqList);

            case Earthquake.DataSource.CKAN:
                JObject ckanlist = JObject.Parse((string)earthquakeEvent);
                ckanTrans(ckanlist);

                return(eqList);

            default:
                break;
            }

            // DEBUG
            return(null);
        }
Exemple #3
0
        //
        // Transform palert object to earthquake object
        //
        private Earthquake palertTrans(Palert palertEvent)
        {
            // The time string format of palert : YYYYMMDDhhmmss
            // We only need YYYYMMDDhhmm
            // The time format in P-alert is UTC, we need to convert it into GMT+8
            string   timeString_   = palertEvent.Timestring;
            DateTime timeString_dt = new DateTime(int.Parse(timeString_.Substring(0, 4)), int.Parse(timeString_.Substring(4, 2)),
                                                  int.Parse(timeString_.Substring(6, 2)), int.Parse(timeString_.Substring(8, 2)),
                                                  int.Parse(timeString_.Substring(10, 2)), int.Parse(timeString_.Substring(12, 2)));

            // UTC time + 8 hours = GMT+8 (Time zone of Taiwan)
            timeString_dt = timeString_dt.AddHours(8);

            string timeString = timeString_dt.ToString("yyyyMMddHHmm");

            string lat = palertEvent.Lat;
            string lng = palertEvent.Lng;

            // The unit of depth of palert event is KM too.
            string depth     = palertEvent.Depth;
            string magnitude = palertEvent.Magnitude;

            Earthquake.DataSource dataSource = Earthquake.DataSource.PALERT;

            // The format of the link of the p-alert data : Domain + Key
            //      Domain  :   http://palert.earth.sinica.edu.tw/db/index1.clt2.php?time=
            //      Key     :   YYYYMMDDhhmmss
            //      And the Key is equal to palertEvent.Timestring

            string Domain = "http://palert.earth.sinica.edu.tw/db/index1.clt2.php?time=";
            string Key    = palertEvent.Timestring;

            string dataLink = Domain + Key;

            Earthquake eq = new Earthquake(timeString, lat, lng, depth, magnitude, dataSource, dataLink);

            return(eq);
        }
Exemple #4
0
        public static string GetEarhquakeRequestString(Earthquake.DataSource datasource, string startdate, string enddate, string min_magnitude, string max_magnitude)
        {
            string requestString = "";
            string prefix;
            string latLng;
            string time;
            string magnitude;

            switch (datasource)
            {
            case Earthquake.DataSource.CKAN:

                //
                // ****************************
                // *                          *
                // *   CKAN                   *
                // *                          *
                // ****************************
                //
                //  The format of the link :
                //
                //      Domain                  :  ConstCkan.CkanAPIPrefix
                //
                //      Organization            :  organization_show?id=earthquake&
                //
                //      Need to show dataset    :  include_datasets =true
                //
                //      The response data type is JSON.
                //

                prefix        = ConstCkan.CkanAPIPrefix + "organization_show?id=earthquake&include_datasets=true";
                latLng        = "";
                time          = startdate + "&" + enddate;
                magnitude     = "";
                requestString = prefix;
                break;

            case Earthquake.DataSource.CWB:

                //
                // ****************************
                // *                          *
                // *   CWB                    *
                // *                          *
                // ****************************
                //
                //  The format of the link : Domain + Time
                //
                //      Prefix      :   http://scweb.cwb.gov.tw/GraphicContent.aspx?ItemId=20&
                //      Time        :   Date=201603
                //                          (All the earthquakes in 2016/03)
                //
                //  The response data is HTML text.
                //  The data of the earthqukes are in each row except the first row of the table datalist4
                //
                prefix = "http://scweb.cwb.gov.tw/GraphicContent.aspx?ItemId=20&Date=";
                DateTime date_i = DateTime.Parse(startdate);
                requestString = prefix + date_i.ToString("yyyyMM");
                break;

            case Earthquake.DataSource.NOAA:
                break;

            case Earthquake.DataSource.PALERT:

                //
                // ****************************
                // *                          *
                // *   P-ALERT                *
                // *                          *
                // ****************************
                //
                //  The format of the link : Domain + LatLng + Time + Intensity
                //  * The "Intensity" of P-ALERT actually means "Magnitude".
                //
                //      Prefix      :   http://palert.earth.sinica.edu.tw/db/querydb.php?
                //      LatLng      :   lat%5B%5D=21&lat%5B%5D=26&lng%5B%5D=119&lng%5B%5D=123&
                //                          (from latitude 21~26, longitude 119~123)
                //      Time        :   time%5B%5D=2016-03-01&time%5B%5D=2016-03-31&
                //                          (from 2016/03/01 to 2016/03/31)
                //      Intensity   :   intensity%5B%5D=1&intensity%5B%5D=7
                //                          (from intensity 1 to intensity 7)
                //
                //      The response data type is JSON.
                //
                //      If there is no earthquake data, P-ALERT will response "false".
                //

                prefix    = "http://palert.earth.sinica.edu.tw/db/querydb.php?";
                latLng    = "lat%5B%5D=21&lat%5B%5D=26&lng%5B%5D=119&lng%5B%5D=123&";
                time      = "time%5B%5D=" + startdate + "&time%5B%5D=" + enddate + "&";
                magnitude = "intensity%5B%5D=" + min_magnitude + "&intensity%5B%5D=" + max_magnitude;

                requestString = prefix + latLng + time + magnitude;
                break;
            }

            return(requestString);
        }