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
        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);
            }
        }
Example #3
0
        public void GetPowerPriceWithDateGoodExample2()
        {
            PowerPrice_Provider ppp = new PowerPrice_Provider();
            double hourOfTheDay     = _clockProxy2.GetTimeInHours();
            int    day = _clockProxy2.GetDay();

            if (hourOfTheDay >= 1.0 && hourOfTheDay < 7.0)
            {
                Assert.AreEqual(ppp.GetPowerPriceWithDate(hourOfTheDay, day), new Tuple <Tuple <int, double>, double>(
                                    new Tuple <int, double>(
                                        day,
                                        hourOfTheDay),
                                    Math.Round(2.372 / 101.94, 3)));
            }
            else
            {
                Assert.AreEqual(ppp.GetPowerPriceWithDate(hourOfTheDay, day), new Tuple <Tuple <int, double>, double>(
                                    new Tuple <int, double>(
                                        day,
                                        hourOfTheDay),
                                    Math.Round(7.117 / 101.94, 3)));
            }
        }