public static void TrackPageViewEnd <T> (T page, WuLocation location) where T : TView { TrackPageViewEnd(page, location == null ? null : new Dictionary <string, string> { //{ "location", location.Name }, { "current", location.Current.ToString() } }); }
public static void TrackPageViewStart <T> (T page, Pages pageType, WuLocation location) where T : TView { TrackPageViewStart(page, pageType.Name(), location == null ? null : new Dictionary <string, string> { //{ "location", location.Name }, { "current", location.Current.ToString() } }); }
public static string ForecastString(this WuLocation location, TemperatureUnits unit) { var today = location?.TxtForecasts? [0]; var tonight = location?.TxtForecasts? [1]; var todayString = unit.IsImperial() ? today?.fcttext : today.fcttext_metric; var tonightString = unit.IsImperial() ? tonight?.fcttext : tonight.fcttext_metric; return($"{todayString}\n\nTonight: {tonightString}"); }
public static string ForecastString(this WuLocation location, TemperatureUnits unit, DateTime?date = null) { var period = date.HasValue ? (date.Value.Day - DateTime.Now.Day) * 2 : 0; var day = location?.TxtForecasts?.FirstOrDefault(f => f.period == period); var night = location?.TxtForecasts?.FirstOrDefault(f => f.period == (period + 1)); var dayString = unit.IsImperial() ? day?.fcttext : day.fcttext_metric; var nightString = unit.IsImperial() ? night?.fcttext : night.fcttext_metric; var dayTitle = (period == 0) ? "Today" : day?.title; var nightTitle = (period == 0) ? "Tonight" : night?.title; var forecastString = string.IsNullOrEmpty(dayString) ? string.Empty : $"{dayTitle} expect {dayString}"; if (!string.IsNullOrEmpty(nightString)) { forecastString += $"\n\n{nightTitle} expect {nightString}"; } return(forecastString); }
public static string ProbabilityPercipString(this WuLocation location) => location?.TodayForecast.ProbabilityPercipString() ?? 0.ToPercentString ();
public static string SunsetString(this WuLocation location) => location?.Sunset?.LocalDateTime.ToString("t").ToLower();
public static string LowTempString(this WuLocation location, TemperatureUnits units, bool round = false, bool degreeSymbol = false) => getTemperatureString(location.TodayForecast.LowTemp(units, round), degreeSymbol);
public static string TempString(this WuLocation location, TemperatureUnits units, bool round = false, bool degreeSymbol = false) => getTemperatureString(location.Conditions.Temp(units, round), degreeSymbol);
public static int GetTimeOfDayIndex(this WuLocation location, bool random = false) { var maxIndex = 9; // the middle gradients are sexier if (random) { return(new Random().Next(5) + 2); } // if there's no data, assume day if (!location.HasSunTimes) { return(maxIndex); } /* Assumes that the "full" sunrise: * - Begins b minutes before the top of the sun breaks the horizon * - Continues to rise for t minutes * * Assumes that the "full" sunset: * - Begins t minutes before the top of the sun disappears behind the horizon * - Continues to rise for b minutes */ const double t = 90; const double b = 30; const double f = t + b; var current = location.CurrentTime.LocalDateTime; var sunrise = location.Sunrise.LocalDateTime; var sunset = location.Sunset.LocalDateTime; // start the sunrise t mins before var sunriseStart = sunrise.Subtract(TimeSpan.FromMinutes(b)); var sunriseEnd = sunrise.AddMinutes(t); // start the sunset t mins before var sunsetStart = sunset.Subtract(TimeSpan.FromMinutes(t)); var sunsetEnd = sunset.AddMinutes(b); int index = 0; if (current.IsOutside(sunriseStart, sunsetEnd)) { // night (before sunrise or after sunset) index = 0; } else if (current.IsBetween(sunriseEnd, sunsetStart)) { // day (after sunrise and before sunset) index = maxIndex; } else if (current.IsBetween(sunriseStart, sunriseEnd)) { // during sunrise index = (int)Math.Floor((current.Subtract(sunriseStart).TotalMinutes / f) * 10); } else if (current.IsBetween(sunsetStart, sunsetEnd)) { // during sunset index = (int)Math.Floor((current.Subtract(sunsetStart).TotalMinutes / f) * 10); // the gradient array is ordered from dark to light, so reverse it for sunset index = maxIndex - index; } return(index); }
public static string GetForecastStrings(this WuLocation location) { return(null); }