Beispiel #1
0
        public static string GetTimeTypeIconName(TimeType tType, LocationTimeHolder lth = null)
        {
            if (lth == null)
            {
                lth = LocationTimeHolder.LocalInstance;
            }
            switch (tType)
            {
            case TimeType.RealSunTime:
                return("real_sun_time");

            case TimeType.MiddleSunTime:
                return("middle_sun_time");

            case TimeType.TimeZoneTime:
                return("icons8_timezone_" + ((int)lth.TimeZoneOffset).ToString().Replace("-", "m"));

            case TimeType.UtcTime:
                return("icons8_timezone_globe");
            }
            return("");
        }
        private static (DateTime peak, DateTime min, DateTime max) FindPeakCenter(DateTime tPeakTime, double nPeakVal, string cMember, int?zone, LocationTimeHolder lth = null)
        {
            var fld = typeof(SunMoon).GetProperty(cMember);

            DateTime tStartPeakTime = DateTime.MaxValue;
            int      xTry           = 0;
            int      iJumpSize      = 3600;
            TimeSpan tsJump         = TimeSpan.FromSeconds(iJumpSize);

            while (xTry < 1000)
            {
                xTry++;
                var    sm   = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, tPeakTime - tsJump, zone, lth);
                double nVal = getValue(fld.GetValue(sm), cMember);
                if (nVal == nPeakVal)
                {
                    tsJump += TimeSpan.FromSeconds(iJumpSize);
                    if (sm.Datum < tStartPeakTime)
                    {
                        tStartPeakTime = sm.Datum;
                    }
                }
                else
                {
                    tsJump   -= TimeSpan.FromSeconds(iJumpSize);
                    iJumpSize = iJumpSize / 10;
                    tsJump   += TimeSpan.FromSeconds(iJumpSize);
                }
                if (iJumpSize < 0.01)
                {
                    break;
                }
            }

            DateTime tEndPeakTime = DateTime.MinValue;

            xTry      = 0;
            iJumpSize = 3600;
            tsJump    = TimeSpan.FromSeconds(iJumpSize);
            while (xTry < 1000)
            {
                xTry++;
                var    sm   = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, tPeakTime + tsJump, zone, lth);
                double nVal = getValue(fld.GetValue(sm), cMember);
                if (nVal == nPeakVal)
                {
                    tsJump += TimeSpan.FromSeconds(iJumpSize);
                    if (sm.Datum > tStartPeakTime)
                    {
                        tEndPeakTime = sm.Datum;
                    }
                }
                else
                {
                    tsJump   -= TimeSpan.FromSeconds(iJumpSize);
                    iJumpSize = iJumpSize / 10;
                    tsJump   += TimeSpan.FromSeconds(iJumpSize);
                }
                if (iJumpSize < 0.01)
                {
                    break;
                }
            }

            if (tStartPeakTime == DateTime.MaxValue)
            {
                tStartPeakTime = tPeakTime;
            }
            if (tEndPeakTime == DateTime.MinValue)
            {
                tEndPeakTime = tPeakTime;
            }

            if (tStartPeakTime != tPeakTime || tEndPeakTime != tPeakTime)
            {
                tPeakTime = tStartPeakTime.AddMilliseconds((tEndPeakTime - tStartPeakTime).TotalMilliseconds / 2);
            }

            return(tPeakTime, tStartPeakTime, tEndPeakTime);
        }
        public static PeakPoint FindPeakAt(double nPeakDest, DateTime tStartPoint, string cMember, int?zone = null, double iJumpSize = 360000, LocationTimeHolder lth = null)
        {
            if (zone == null)
            {
                zone = (DateTime.Now - DateTime.UtcNow).Hours;
            }

            DateTime mNow = tStartPoint;
            var      fld  = typeof(SunMoon).GetProperty(cMember);

            if (fld != null)
            {
                SunMoon  sm        = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow, zone, lth);
                double   nLastDist = double.MaxValue;
                TimeSpan tsJump    = TimeSpan.FromSeconds(0);

                var xPoints = new Dictionary <DateTime, double>();
                xPoints.Add(sm.Datum, getValue(fld.GetValue(sm), cMember));

                int iTry = 0;
                while (iTry < 1000)
                {
                    iTry++;

                    if (iTry > 100)
                    {
                        iTry.ToString();
                    }

                    sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow + tsJump, zone, lth);
                    double nVal  = getValue(fld.GetValue(sm), cMember);
                    double nDist = nPeakDest - nVal;
                    if (nDist < 0)
                    {
                        nDist = nDist * -1;
                    }
                    if (nDist > nLastDist) //wenn am PeakVorbei
                    {
                        xPoints.Add(sm.Datum.AddMilliseconds(iTry), nVal);
                        nLastDist = double.MaxValue;

                        //two step back and continue smaler
                        tsJump   -= TimeSpan.FromSeconds(iJumpSize * 2);
                        iJumpSize = iJumpSize / 10;
                    }
                    else
                    {
                        nLastDist = nDist;
                    }
                    tsJump += TimeSpan.FromSeconds(iJumpSize);
                    if (iJumpSize < 0.01)
                    {
                        sm        = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow + tsJump, zone, lth);
                        iJumpSize = iJumpSize * 10; //für die Anzeige
                        break;
                    }
                }

                string c = "";
                foreach (var x in xPoints)
                {
                    c += x.Key + "    " + x.Value + "\n";
                }

                c.ToString();

                double nPeakVal = getValue(fld.GetValue(sm), cMember);

                var peak      = FindPeakCenter(sm.Datum, nPeakVal, cMember, zone, lth);
                var tPeakTime = peak.Item1;

                string cEinheit = GetEinheit(cMember);
                string cPeakVal = nPeakVal.ToString();
                if ("h".Equals(cEinheit))
                {
                    cPeakVal = GetTime(nPeakVal);
                }
                else if ("°".Equals(cEinheit))
                {
                    cPeakVal = GetGrad(nPeakVal);
                }
                else if ("km".Equals(cEinheit))
                {
                    cPeakVal = GetKm(nPeakVal);
                }

                return(new PeakPoint()
                {
                    DateTime = tPeakTime, Value = nPeakVal, JumpCount = iTry, JumpSize = TimeSpan.FromSeconds(iJumpSize), PeakStart = peak.Item2, PeakEnd = peak.Item3
                });
            }
            return(null);
        }
        public static PeakPoint FindPeakBefore(DateTime tStartPoint, int iDirection, string cMember, int?zone = null, double iJumpSize = 360000, LocationTimeHolder lth = null)
        {
            if (zone == null)
            {
                zone = (DateTime.Now - DateTime.UtcNow).Hours;
            }
            DateTime mNow = tStartPoint;
            var      fld  = typeof(SunMoon).GetProperty(cMember);

            if (fld != null)
            {
                SunMoon sm      = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow, zone, lth);
                double  nMaxVal = getValue(fld.GetValue(sm), cMember) * iDirection;

                var xPoints = new Dictionary <DateTime, double>();
                xPoints.Add(sm.Datum, nMaxVal);

                TimeSpan tsJump = TimeSpan.FromSeconds(iJumpSize);

                //prüfen, ob nicht ein halber Zyklus übersprungen werden sollt..

                var nPrev = getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - TimeSpan.FromHours(6), zone, lth)), cMember) * iDirection;
                var nNext = getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow + TimeSpan.FromHours(6), zone, lth)), cMember) * iDirection;
                if (nPrev > nMaxVal && nNext < nMaxVal)
                {
                    var next = FindPeakBefore(tStartPoint.AddHours(-12), iDirection * -1, cMember, zone, iJumpSize, lth);
                    tsJump  = next.DateTime - tStartPoint;
                    nMaxVal = getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow + tsJump, zone, lth)), cMember) * iDirection;
                    xPoints.Clear();
                    xPoints.Add(mNow + tsJump, nMaxVal);
                }

                int iTry = 0;
                while (iTry < 1000)
                {
                    iTry++;
                    sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - tsJump, zone, lth);
                    double nVal = getValue(fld.GetValue(sm), cMember) * iDirection;

                    if (nVal > nMaxVal)
                    {
                        nMaxVal = nVal;
                    }

                    if (nVal < nMaxVal)
                    {
                        tsJump -= TimeSpan.FromSeconds(iJumpSize);
                        if (iJumpSize > 0.1)
                        {
                            //two step back and continue smaler
                            tsJump -= TimeSpan.FromSeconds(iJumpSize);

                            xPoints.Add(sm.Datum.AddMilliseconds(iTry), nVal);

                            nMaxVal = getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - tsJump, zone, lth)), cMember) * iDirection;
                            xPoints.Add((mNow + tsJump).AddMilliseconds(iTry + 1), getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - tsJump, zone, lth)), cMember) * iDirection);

                            iJumpSize = iJumpSize / 10;
                        }
                        else
                        {
                            sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - tsJump, zone, lth);
                            break;
                        }
                    }
                    tsJump += TimeSpan.FromSeconds(iJumpSize);
                }

                string c = "";
                foreach (var x in xPoints)
                {
                    c += x.Key + "    " + x.Value + "\n";
                }

                c.ToString();

                double   nPeakVal  = getValue(fld.GetValue(sm), cMember);
                DateTime tPeakTime = sm.Datum;

                var peak = FindPeakCenter(tPeakTime, nPeakVal, cMember, zone, lth);
                tPeakTime = peak.Item1;

                string cEinheit = GetEinheit(cMember);
                string cPeakVal = nPeakVal.ToString();
                if ("h".Equals(cEinheit))
                {
                    cPeakVal = GetTime(nPeakVal);
                }
                else if ("°".Equals(cEinheit))
                {
                    cPeakVal = GetGrad(nPeakVal);
                }
                else if ("km".Equals(cEinheit))
                {
                    cPeakVal = GetKm(nPeakVal);
                }

                return(new PeakPoint()
                {
                    DateTime = tPeakTime, Value = nPeakVal, JumpCount = iTry, JumpSize = TimeSpan.FromSeconds(iJumpSize), PeakStart = peak.Item2, PeakEnd = peak.Item3
                });
            }
            return(null);
        }
Beispiel #5
0
 public static int GetTimeTypeIconID(TimeType tType, LocationTimeHolder lth = null)
 {
     return((int)typeof(Resource.Drawable).GetField(GetTimeTypeIconName(tType, lth)).GetValue(null));
 }
Beispiel #6
0
 public static Bitmap GetTimeTypeIcon(Context ctx, TimeType tType, LocationTimeHolder lth = null, float nSizeDp = 24, string color = "#FFFFFFFF")
 {
     return(DrawableHelper.GetIconBitmap(ctx, GetTimeTypeIconName(tType, lth), nSizeDp, xColor.FromHex(color)));
 }
Beispiel #7
0
        public async Task DoLoadCalendarEventsListed(DateTime dStart, DateTime dEnd, int iMax = 0, int iError = 0)
        {
            xLog.Debug("DoLoadCalendarEventsListed: Start: " + bIsLoadingCalendarEventsListed.ToString());
            if (bIsLoadingCalendarEventsListed)
            {
                xLog.Debug("xxxxxxxxxxxxxxxDoLoadCalendarEventsListed: Start: " + bIsLoadingCalendarEventsListed.ToString());
            }
            if (false)
            {
                while (bIsLoadingCalendarEventsListed)
                {
                    Task.Delay(25).Wait();
                }
                bIsLoadingCalendarEventsListed = true;
                xLog.Debug("DoLoadCalendarEventsListed: Start Now");
            }
            bIsLoadingCalendarEventsListed = true;
            try
            {
                int iMs       = 0;
                var newEvents = new SortedDictionary <DateTime, CalendarEvent>();
                LocationTimeHolder lthCheck = LocationTimeHolder.LocalInstanceClone;

                DateTime swStart = DateTime.Now;
                if (sys.isWindows)
                {
                    var rnd = new Random(DateTime.Now.Second);
                    for (int i = 0; i < rnd.Next(5) * 2; i++)
                    {
                        string name     = "win";
                        var    calEvent = new CalendarEvent();
                        calEvent.Title              = $"{name} event {i}";
                        calEvent.Description        = $"This is {name} event{i}'s description!";
                        calEvent.Start              = dStart.AddHours(new Random().Next(8) + 10).AddMinutes(new Random().Next(50));
                        calEvent.End                = calEvent.Start.AddHours(new Random().Next(5) + 1);
                        calEvent.EventColor         = xColor.FromRgb(rnd.Next(200), rnd.Next(200), rnd.Next(200));
                        calEvent.DisplayColorString = calEvent.EventColorString;

                        //CheckEventLocationTime(lthCheck, calendar, calEvent);
                        newEvents.Add(calEvent.SortTime.AddMilliseconds(iMs++), calEvent);
                    }
                }
                else
                {
                    var calendars = new List <DeviceCalendar.Calendar>(await DeviceCalendar.DeviceCalendar.GetCalendarsAsync());
                    foreach (DeviceCalendar.Calendar calendar in calendars)
                    {
                        if (string.IsNullOrEmpty(CalendarFilter) || !CalendarFilter.Contains("|" + calendar.ExternalID + "|"))
                        {
                            var calEvents = await DeviceCalendar.DeviceCalendar.GetEventsAsync(calendar, dStart, dEnd);

                            foreach (CalendarEvent calEvent in calEvents)
                            {
                                CheckEventLocationTime(lthCheck, calendar, calEvent);
                                newEvents.Add(calEvent.SortTime.AddMilliseconds(iMs++), calEvent);

                                if (iMax > 0 && iMs >= iMax)
                                {
                                    break;
                                }
                                iMs++;
                            }
                        }
                    }
                }
                xLog.Debug("LoadAndCheckEvents took " + (DateTime.Now - swStart).TotalMilliseconds.ToString() + "ms for " + iMs.ToString() + " Events");
                lock (ListedDates)
                {
                    ListedDates.Clear();
                    ListedDates.AddRange(newEvents.Values);
                }
            }
            catch (Exception ex)
            {
                base.Clear();
                xLog.Debug("Error reading Calendar Events: " + ex.GetType().Name + ": " + ex.Message);
            }
            finally { bIsLoadingCalendarEventsListed = false; }
            xLog.Debug("DoLoadCalendarEventsListed: Stop");
        }