コード例 #1
0
        private DateTime GetSunriseDate(DateTime date)
        {
            Celestial celestial = Celestial.CalculateCelestialTimes(42.304428, -87.948996, date);
            var       sunrise   = celestial.SunRise.Value;

            return(sunrise);
        }
コード例 #2
0
        private DateTime GetSunsetDate(DateTime date)
        {
            Celestial celestial = Celestial.CalculateCelestialTimes(42.304428, -87.948996, date);
            var       sunset    = celestial.SunSet.Value;

            return(sunset);
        }
コード例 #3
0
ファイル: LightAdjuster.cs プロジェクト: hakerg/Eyes-Guardian
        public void Adjust(bool force)
        {
            mutex.WaitOne();

            if (force)
            {
                lightMode  = -1;
                brightness = -1;
            }

            Celestial celestial = Celestial.CalculateCelestialTimes
                                      (location.Latitude, location.Longitude, DateTime.UtcNow);

            if (celestial.IsSunUp)
            {
                SetLightMode(1);
            }
            else
            {
                SetLightMode(0);
            }

            double factor = (Sin(celestial.SunAltitude * PI / 180.0) + 0.3) * 1.0 / 1.3;

            if (factor > 0.0)
            {
                SetBrightness((int)(Sqrt(factor) * 100.0));
            }
            else
            {
                SetBrightness(0);
            }

            mutex.ReleaseMutex();
        }
コード例 #4
0
        private void InitTimeZone(DateTime?dtOverride = null)
        {
            if (TimeZone == null ||
                celestial == null)
            {
                TimeZone = TZConvert.GetTimeZoneInfo(TimeZoneId);

                var dt = GetDateTimeInLocation(dtOverride);
                celestial = Celestial.CalculateCelestialTimes(Latitude, Longitude, dt, TimeZone.GetUtcOffset(dt).TotalHours);
            }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static double Koeff(DateTime start, DateTime end)
        {
            int      deltaHour = (DateTime.Now - DateTime.UtcNow).Hours;
            TimeSpan timeWorkForPeriodMinusHour = TimeSpan.Zero, timeWorkForPeriod = TimeSpan.Zero;

            for (int i = 0; start.AddDays(i) < end; i++)
            {
                Celestial cel        = Celestial.CalculateCelestialTimes(55.9077000, 53.9355000, start.AddDays(i));
                DateTime  sunRiseUTC = cel.SunRise.Value;
                DateTime  sunSetUTC  = cel.SunSet.Value;
                DateTime  sunRise    = sunRiseUTC.AddHours(deltaHour);
                DateTime  sunSet     = sunSetUTC.AddHours(deltaHour);
                TimeSpan  tmpsum     = (sunRise - start.AddDays(i)) + (start.AddDays(i + 1) - sunSet);
                timeWorkForPeriod          += tmpsum;
                timeWorkForPeriodMinusHour += tmpsum - TimeSpan.FromHours(1);
            }
            double tmp = timeWorkForPeriod.TotalMinutes / timeWorkForPeriodMinusHour.TotalMinutes;

            return(tmp);
        }
コード例 #6
0
        public static void Run_Test()
        {
            Coordinate tc = null;

            Console.WriteLine("Starting Benchmarks, this test may take a while to finish...");
            Console.WriteLine();
            //Benchmark Standard Object Initialization
            Benchmark(() => { tc = new Coordinate(39.891219, -74.872435, new DateTime(2018, 7, 26, 15, 49, 0)); }, 100, "Standard Initialization");

            Benchmark(() => {
                tc           = new Coordinate();
                tc.Latitude  = new CoordinatePart(39, 45, 34, CoordinatesPosition.N);
                tc.Longitude = new CoordinatePart(74, 34, 45, CoordinatesPosition.W);
                tc.GeoDate   = new DateTime(2018, 7, 26, 15, 49, 0);
            }, 100, "Secondary Initialization");

            //Benchmark TryParse Object Initialization
            Benchmark(() => { Coordinate.TryParse("39.891219, -74.872435", new DateTime(2010, 7, 26, 15, 49, 0), out tc); }, 100, "TryParse() Initialization");

            //Benchmark with EagerLoad fully off
            Benchmark(() => {
                EagerLoad eg = new EagerLoad(false);

                tc = new Coordinate(39.891219, -74.872435, new DateTime(2018, 7, 26, 15, 49, 0), eg);
            }, 100, "EagerLoad Off Initialization");
            tc = new Coordinate(39.891219, -74.872435, new DateTime(2018, 7, 26, 15, 49, 0));

            //Benchmark property change
            Random r = new Random();

            Benchmark(() => { tc.Latitude.DecimalDegree = r.Next(-90, 90); }, 100, "Property Change");

            //Benchmark Celestial Times
            Benchmark(() => { Celestial cel = new Celestial(45, 45, DateTime.Now); }, 100, "Celestial Time Calculations");

            EagerLoad  el = new EagerLoad();
            Coordinate c  = new Coordinate(45, 45, DateTime.Now, el);

            //Benchmark Local Times
            Benchmark(() => {
                Celestial cel = c.Celestial_LocalTime(-7);
            }, 100, "Local Celestial Times From Coordinate");
            el.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Solar_Cycle);
            Benchmark(() => {
                Celestial cel = c.Celestial_LocalTime(-7);
            }, 100, "Local Solar Cycle Only Times From Coordinate");
            el.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Lunar_Cycle);
            Benchmark(() => {
                Celestial cel = c.Celestial_LocalTime(-7);
            }, 100, "Local Lunar Cycle Only Times From Coordinate");
            el = new EagerLoad();
            Benchmark(() => {
                Celestial cel = Celestial.CalculateCelestialTimes(45, 45, DateTime.Now, el, -7);
            }, 100, "Local Celestial Times From Direct Celestial");
            el            = new EagerLoad(EagerLoadType.Celestial);
            el.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Solar_Cycle);
            Benchmark(() => {
                Celestial cel = Celestial.CalculateCelestialTimes(45, 45, DateTime.Now, el, -7);
            }, 100, "Local Solar Cycle Only Times From Direct Celestial");
            el.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Lunar_Cycle);
            Benchmark(() => {
                Celestial cel = Celestial.CalculateCelestialTimes(45, 45, DateTime.Now, el, -7);
            }, 100, "Local Lunar Cycle Only Times From Direct Celestial");


            //Benchmark EagerLoading Extension Times
            el = new EagerLoad();
            Benchmark(() =>
            {
                el.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Solar_Cycle);
                c             = new Coordinate(45, 45, DateTime.Now, el);
            }, 100, "Coordinate Initialization with Solar Cycle Calculations Only.");

            Benchmark(() =>
            {
                el.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Lunar_Cycle);
                c             = new Coordinate(45, 45, DateTime.Now, el);
            }, 100, "Coordinate Initialization with Lunar Cycle Calculations Only.");
        }
コード例 #7
0
        private bool Check_Local_Times()
        {
            DateTime d      = new DateTime(2019, 10, 31, 14, 10, 22);
            double   offset = -7;

            //INSTANCE CHECK

            //Coordinate in UTC
            Coordinate cUTC = new Coordinate(47.60357, -122.32945, d);
            //Coordinate in UTC - offset added to account for UTC date differing
            Coordinate sUTC = new Coordinate(47.60357, -122.32945, d.AddDays(offset / Math.Abs(offset) * -1));
            //Coordinate in Local
            Coordinate lLoc = new Coordinate(47.60357, -122.32945, d);
            //Coordinate in local + offset (for cel coord comparision)
            Coordinate simUTC = new Coordinate(47.60357, -122.32945, d.AddHours(-offset));

            lLoc.Offset = offset;


            Celestial cCel = cUTC.CelestialInfo;
            Celestial sCel = sUTC.CelestialInfo;
            Celestial lCel = lLoc.CelestialInfo;
            Celestial bCel = simUTC.CelestialInfo;

            if (!Local_Time_Checker(cCel, lCel, sCel, bCel, offset))
            {
                return(false);
            }

            //STATIC CHECK

            cCel = Celestial.CalculateCelestialTimes(47.60357, -122.32945, d);
            sCel = Celestial.CalculateCelestialTimes(47.60357, -122.32945, d.AddDays(offset / Math.Abs(offset) * -1));
            lCel = Celestial.CalculateCelestialTimes(47.60357, -122.32945, d, offset);
            bCel = Celestial.CalculateCelestialTimes(47.60357, -122.32945, d.AddHours(-offset));

            if (!Local_Time_Checker(cCel, lCel, sCel, bCel, offset))
            {
                return(false);
            }


            //With EagerLoad
            EagerLoad el = new EagerLoad(EagerLoadType.Celestial);

            cCel = Celestial.CalculateCelestialTimes(47.60357, -122.32945, d, el);
            sCel = Celestial.CalculateCelestialTimes(47.60357, -122.32945, d.AddDays(offset / Math.Abs(offset) * -1), el);
            lCel = Celestial.CalculateCelestialTimes(47.60357, -122.32945, d, el, offset);
            bCel = Celestial.CalculateCelestialTimes(47.60357, -122.32945, d.AddHours(-offset), el);

            if (!Local_Time_Checker(cCel, lCel, sCel, bCel, offset))
            {
                return(false);
            }

            //VALIDATIONS
            //IN RANGE
            try { cUTC.Offset = -12; } catch (ArgumentOutOfRangeException) { return(false); }
            try { cUTC.Offset = 12; } catch (ArgumentOutOfRangeException) { return(false); }
            try { cCel = new Celestial(0, 0, DateTime.Now, -12); } catch (ArgumentOutOfRangeException) { return(false); }
            try { cCel = new Celestial(0, 0, DateTime.Now, 12); } catch (ArgumentOutOfRangeException) { return(false); }
            try { cCel = new Celestial(0, 0, DateTime.Now, -12, new EagerLoad()); } catch (ArgumentOutOfRangeException) { return(false); }
            try { cCel = new Celestial(0, 0, DateTime.Now, 12, new EagerLoad()); } catch (ArgumentOutOfRangeException) { return(false); }
            try { cCel = Celestial.CalculateCelestialTimes(0, 0, DateTime.Now, -12); } catch (ArgumentOutOfRangeException) { return(false); }
            try { cCel = Celestial.CalculateCelestialTimes(0, 0, DateTime.Now, 12); } catch (ArgumentOutOfRangeException) { return(false); }
            try { cCel = Celestial.CalculateCelestialTimes(0, 0, DateTime.Now, new EagerLoad(), 12); } catch (ArgumentOutOfRangeException) { return(false); }
            try { cCel = Celestial.CalculateCelestialTimes(0, 0, DateTime.Now, new EagerLoad(), -12); } catch (ArgumentOutOfRangeException) { return(false); }
            //OUT OF RANGE
            try { cUTC.Offset = -13; return(false); } catch (ArgumentOutOfRangeException) { }
            try { cUTC.Offset = 13; return(false); } catch (ArgumentOutOfRangeException) { }
            try { cCel = new Celestial(0, 0, DateTime.Now, -13); return(false); } catch (ArgumentOutOfRangeException) {  }
            try { cCel = new Celestial(0, 0, DateTime.Now, 13); return(false); } catch (ArgumentOutOfRangeException) { }
            try { cCel = new Celestial(0, 0, DateTime.Now, -13, new EagerLoad()); return(false); } catch (ArgumentOutOfRangeException) { }
            try { cCel = new Celestial(0, 0, DateTime.Now, 13, new EagerLoad()); return(false); } catch (ArgumentOutOfRangeException) { }
            try { cCel = Celestial.CalculateCelestialTimes(0, 0, DateTime.Now, -13); return(false); } catch (ArgumentOutOfRangeException) { }
            try { cCel = Celestial.CalculateCelestialTimes(0, 0, DateTime.Now, 13); return(false); } catch (ArgumentOutOfRangeException) { }
            try { cCel = Celestial.CalculateCelestialTimes(0, 0, DateTime.Now, new EagerLoad(), -13); return(false); } catch (ArgumentOutOfRangeException) { }
            try { cCel = Celestial.CalculateCelestialTimes(0, 0, DateTime.Now, new EagerLoad(), 13); return(false); } catch (ArgumentOutOfRangeException) { }



            return(true);
        }
コード例 #8
0
        //Unit Test Console
        //This is a partial unit test meant to test initialization of objects.
        //Error, limit & MVVM testing should be done in the WPF test app.

        static void Main(string[] args)
        {
            //Test Lat Long KWRI 40.0352° N, 74.5844° W

            //Test Coordinate Initialization w & w/o eager load
            d("INITIALIZATION TESTS:");
            Coordinate c = new Coordinate();

            d(c.ToString());
            c = new Coordinate(40.0352, -74.5844);
            d(c.ToString());
            c = new Coordinate(40.0352, -74.5844, new DateTime(2017, 8, 21, 0, 0, 0));
            d(c.ToString());


            EagerLoad eagerLoad = new EagerLoad();

            c = new Coordinate(eagerLoad);
            d(c.ToString());
            c = new Coordinate(40.0352, -74.5844, eagerLoad);
            d(c.ToString());
            c = new Coordinate(40.0352, -74.5844, new DateTime(2017, 8, 21, 0, 0, 0), eagerLoad);
            d(c.ToString());

            //Test Coord String Formats
            CoordinateFormatOptions cfo = new CoordinateFormatOptions();

            cfo.Format                 = CoordinateFormatType.Degree_Decimal_Minutes;
            cfo.Display_Symbols        = false;
            cfo.Display_Trailing_Zeros = true;
            c.FormatOptions            = cfo;
            d(c.Latitude.ToString() + " - " + c.Longitude.ToString());

            //Test ToDouble
            d(c.Latitude.ToDouble() + "  -  " + c.Longitude.ToDouble());

            //Test UTM & MGRS
            d(c.MGRS.ToString());
            d(c.MGRS.Digraph + " - " + c.MGRS.Easting + " - " + c.MGRS.LatZone + " - " + c.MGRS.LongZone + " - " + c.MGRS.Northing);
            d(c.UTM.ToString());
            d(c.UTM.Easting + " - " + c.UTM.LatZone + " - " + c.UTM.LongZone + " - " + c.UTM.Northing);

            //TEST CELESTIAL
            //Main Properties
            d("SUN CONDITION: " + c.CelestialInfo.SunCondition.ToString());
            d("SUN RISE: " + c.CelestialInfo.SunRise);
            d("SUN SET: " + c.CelestialInfo.SunSet);
            d("SUN ALTITUDE: " + c.CelestialInfo.SunAltitude);
            d("SUN AZIMUTH: " + c.CelestialInfo.SunAzimuth);

            d("MOON CONDITION: " + c.CelestialInfo.MoonCondition.ToString());
            d("MOON DISTANCE: " + c.CelestialInfo.MoonDistance);
            d("MOON RISE: " + c.CelestialInfo.MoonRise);
            d("MOON SET: " + c.CelestialInfo.MoonSet);

            //Sub Properties
            d("CIVIL DAWN: " + c.CelestialInfo.AdditionalSolarTimes.CivilDawn.ToString());
            d("CIVIL DUSK: " + c.CelestialInfo.AdditionalSolarTimes.CivilDusk.ToString());
            d("NAUTICAL DAWN: " + c.CelestialInfo.AdditionalSolarTimes.NauticalDawn.ToString());
            d("NAUTICAL DUSK: " + c.CelestialInfo.AdditionalSolarTimes.NauticalDusk.ToString());

            d("MOON NAME: " + c.CelestialInfo.AstrologicalSigns.MoonName);
            d("MOON SIGN: " + c.CelestialInfo.AstrologicalSigns.MoonSign);
            d("ZODIAC SIGN: " + c.CelestialInfo.AstrologicalSigns.ZodiacSign);

            d("MOON ANGLE: " + c.CelestialInfo.MoonIllum.Angle.ToString());
            d("MOON FRACTION: " + c.CelestialInfo.MoonIllum.Fraction.ToString());
            d("MOON PHASE: " + c.CelestialInfo.MoonIllum.Phase.ToString());
            d("MOON PHASENAME: " + c.CelestialInfo.MoonIllum.PhaseName.ToString());

            //VALUE CHANGE NOTIFICATION TEST (PARTIAL. MORE COMPLETE TESTING OF NOTIFICATION CHANGES SHOULD BE DONE IN THE MVVM WPF TESTER)
            //New Lat Long Cape Town Intl 33.9715° S, 18.6021° E
            d("COORDINATE CHANGE NOTIFICATION TESTS");
            c.Latitude.DecimalDegree  = 33.9715;
            c.Latitude.Position       = CoordinatesPosition.S;
            c.Longitude.DecimalDegree = 18.6021;
            c.Longitude.Position      = CoordinatesPosition.E;

            d(c.ToString());
            d(c.MGRS.ToString());
            d(c.UTM.ToString());

            d("SUN CONDITION: " + c.CelestialInfo.SunCondition.ToString());
            d("SUN RISE: " + c.CelestialInfo.SunRise);
            d("SUN SET: " + c.CelestialInfo.SunSet);
            d("SUN ALTITUDE: " + c.CelestialInfo.SunAltitude);
            d("SUN AZIMUTH: " + c.CelestialInfo.SunAzimuth);

            d("MOON CONDITION: " + c.CelestialInfo.MoonCondition.ToString());
            d("MOON DISTANCE: " + c.CelestialInfo.MoonDistance);
            d("MOON RISE: " + c.CelestialInfo.MoonRise);
            d("MOON SET: " + c.CelestialInfo.MoonSet);

            //EAGERLOAD TESTS
            eagerLoad.Celestial = false;
            c = new Coordinate(40.0352, -74.5844, DateTime.Now, eagerLoad);
            try { d(c.CelestialInfo.SunSet.Value.ToString()); }
            catch (NullReferenceException ex) { d("TEST EAGERLOAD OFF: " + ex.Message); }
            c.LoadCelestialInfo();
            d(c.CelestialInfo.SunSet.Value.ToString());

            //TEST STATIC CELESTIALS
            Console.WriteLine(Celestial.CalculateCelestialTimes(40.0352, -74.5844, DateTime.Now).SunSet);

            Console.ReadKey();
        }