コード例 #1
0
        /// <summary>
        /// Fetches DarkSky api, Tidal api to gather weather data, and select relevant data
        /// assigning it to this object
        /// </summary>
        /// <param name="lat">Latitude</param>
        /// <param name="lon">Longitude</param>
        /// <param name="location">Location name for provided coordinates</param>
        /// <param name="stationId">Tidal station id</param>
        /// <param name="addDays">Fetch data for future days. How many days add to today date</param>
        /// <param name="addHours">Fetch data for current hours + addHours</param>
        public void Update(double lat, double lon, string location, string stationId, int addDays = 0, int addHours = 0)
        {
            var client = new DarkSkyService(Constants.DarkSkyKey);
            // creating time object which depicts forecast time
            var time = DateTimeOffset.Now.AddDays(addDays).AddHours(addHours);

            // calling api for weather info
            DarkSkyApi.Models.Forecast f = Task.Run(() => client.GetTimeMachineWeatherAsync(lat, lon, time)).Result;
            // setting model properties with api result
            icon          = f.Currently.Icon;
            this.location = location;
            double _temp = Math.Round(UnitConverters.FahrenheitToCelsius(f.Currently.Temperature), 1);

            temperature   = _temp.ToString() + "°C";
            summary       = f.Currently.Summary;
            humidity      = $"{(int)(f.Currently.Humidity * 100)}%";
            windSpeed     = string.Format("{0:0.00}m/s", f.Currently.WindSpeed / 2.237); // convert to m/s
            windDirection = ((int)(f.Currently.WindBearing)).ToString() + "°";
            if (stationId != string.Empty)
            {
                waterLevel = TidalApi.GetInstance().GetWaterInfo(stationId, addDays, time.Hour);
            }
            else
            {
                waterLevel = "0m";
            }
            // setting forecast time in model, setting minutes and seconds to 0
            date = new DateTime(time.Year, time.Month, time.Day, time.Hour, 0, 0);
        }
コード例 #2
0
ファイル: TidalApi.cs プロジェクト: armandasalmd/tidalio
 /// <summary>
 /// Get single instance of this class
 /// </summary>
 /// <returns>Singleton instance</returns>
 public static TidalApi GetInstance()
 {
     if (instance == null)
     {
         instance = new TidalApi();
     }
     return(instance);
 }