public static void CollectingMeasurements()
        {
            int iterationStart = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes();
            int dayStart       = ConnectHelper.ConnectUniversalClock().GetDay();

            while (true)
            {
                int currentMoment = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes();
                int currentDay    = ConnectHelper.ConnectUniversalClock().GetDay();
                if (currentDay > dayStart || currentMoment - iterationStart >= 1)
                {
                    iterationStart = currentMoment;
                    dayStart       = currentDay;
                }
                else
                {
                    continue;
                }

                IPowerPrice            powerPriceProxy     = ConnectHelper.ConnectUtility();
                IUniversalClockService universalClockProxy = ConnectHelper.ConnectUniversalClock();

                Measurement currentMeasurement = new Measurement
                {
                    BatteryConsumption   = 0,
                    BatteryProduction    = 0,
                    ConsumersConsumption = 0,
                    SolarPanelProduction = 0,
                };

                Dictionary <string, Battery> batteries           = DBManager.S_Instance.GetAllBatteries();
                Dictionary <string, ElectricVehicleCharger> evcs = DBManager.S_Instance.GetAllElectricVehicleChargers();
                Dictionary <string, SolarPanel>             sps  = DBManager.S_Instance.GetAllSolarPanels();
                Dictionary <string, Consumer> consumers          = DBManager.S_Instance.GetAllConsumers();

                Measurement currentConsumptionMeasurement = CalculateCurrentConsumption(batteries, evcs, consumers);
                currentMeasurement.BatteryConsumption   = currentConsumptionMeasurement.BatteryConsumption;
                currentMeasurement.ConsumersConsumption = currentConsumptionMeasurement.ConsumersConsumption;

                Measurement currentProductionMeasurement = CalculateCurrentProduction(batteries, evcs, sps);
                currentMeasurement.SolarPanelProduction = currentProductionMeasurement.SolarPanelProduction;
                currentMeasurement.BatteryProduction    = currentMeasurement.BatteryProduction;

                currentMeasurement.PowerPrice   = powerPriceProxy.GetPowerPrice(universalClockProxy.GetTimeInHours());
                currentMeasurement.Day          = universalClockProxy.GetDay();
                currentMeasurement.HourOfTheDay = universalClockProxy.GetTimeInHours();

                DBManager.S_Instance.AddMeasurement(currentMeasurement);
                //Thread.Sleep(Constants.MILISECONDS_IN_MINUTE);
            }
        }
Example #2
0
        public void GetPowerPriceGoodExpample2()
        {
            PowerPrice_Provider ppp = new PowerPrice_Provider();
            double hourOfTheDay     = _clockProxy2.GetTimeInHours();

            if (hourOfTheDay >= 1.0 && hourOfTheDay < 7.0)
            {
                Assert.AreEqual(ppp.GetPowerPrice(hourOfTheDay), Math.Round(2.372 / 101.94, 3));
            }
            else
            {
                Assert.AreEqual(ppp.GetPowerPrice(hourOfTheDay), Math.Round(7.117 / 101.94, 3));
            }
        }
Example #3
0
        public void GetSunlightPercentageGoodExample2()
        {
            WeatherForecast_Provider provider = new WeatherForecast_Provider();
            double hourOfTheDay = _clockProxy2.GetTimeInHours();

            if (hourOfTheDay >= 0 && hourOfTheDay < 5.5)
            {
                Assert.AreEqual(provider.GetSunlightPercentage(hourOfTheDay), 0);
            }
            else if (hourOfTheDay >= 5.5 && hourOfTheDay < 7.0)
            {
                Assert.GreaterOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 25 * (8 / 10));
                Assert.LessOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 25 * (10 / 10));
            }
            else if (hourOfTheDay >= 7.0 && hourOfTheDay < 10.0)
            {
                Assert.GreaterOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 50 * (8 / 10));
                Assert.LessOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 50 * (10 / 10));
            }
            else if (hourOfTheDay >= 10.0 && hourOfTheDay < 12.0)
            {
                Assert.GreaterOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 75 * (8 / 10));
                Assert.LessOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 75 * (10 / 10));
            }
            else if (hourOfTheDay >= 12.0 && hourOfTheDay < 15.0)
            {
                Assert.GreaterOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 100 * (8 / 10));
                Assert.LessOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 100 * (10 / 10));
            }
            else if (hourOfTheDay >= 15.0 && hourOfTheDay < 17.0)
            {
                Assert.GreaterOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 75 * (8 / 10));
                Assert.LessOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 75 * (10 / 10));
            }
            else if (hourOfTheDay >= 17.0 && hourOfTheDay < 20.0)
            {
                Assert.GreaterOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 50 * (8 / 10));
                Assert.LessOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 50 * (10 / 10));
            }
            else if (hourOfTheDay >= 20.0 && hourOfTheDay < 22.0)
            {
                Assert.GreaterOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 25 * (8 / 10));
                Assert.LessOrEqual(provider.GetSunlightPercentage(hourOfTheDay), 25 * (10 / 10));
            }
            else if (hourOfTheDay >= 22.0 && hourOfTheDay <= 23.0)
            {
                Assert.AreEqual(provider.GetSunlightPercentage(hourOfTheDay), 0);
            }
            else
            {
                Assert.AreEqual(provider.GetSunlightPercentage(hourOfTheDay), -1);
            }
        }
Example #4
0
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                IUniversalClockService universalClockProxy = ConnectHelper.ConnectUniversalClock();
                TotalMinutes = universalClockProxy.GetTimeInMinutes();
                TimeSpan ts = TimeSpan.FromMinutes(TotalMinutes);

                IPowerPrice utilityProxy = ConnectHelper.ConnectUtility();

                Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
                {
                    CurrentTimeProperty  = String.Format($"{ts.Hours} : {ts.Minutes}");
                    CurrentPriceProperty = String.Format($"Power price: {utilityProxy.GetPowerPrice(universalClockProxy.GetTimeInHours())} [$/kWh]");

                    Int32 day = universalClockProxy.GetDay();
                    if (day - 1 != 0)
                    {
                        String newDayString = $"{day - 1}. dan od startovanja aplikacije";

                        if (!ListOfDays.Contains(newDayString))
                        {
                            ListOfDays.Add(newDayString);
                        }
                    }
                    else
                    {
                        String newDayString = $"Dan u kojem je startovana aplikacija";

                        if (!ListOfDays.Contains(newDayString))
                        {
                            ListOfDays.Add(newDayString);
                        }
                    }
                }));

                Thread.Sleep(Constants.MILISECONDS_IN_SECOND);
            }
        }