static void Main(string[] args) { Console.WriteLine("Utility: Hello world!"); PowerPrice_Server server = new PowerPrice_Server(); server.Open(); Thread.Sleep(Constants.WAITING_TIME); double price = 0; double hourOfTheDay; double USDToRSDRatio = 101.94; double highPrice = 7.117 / USDToRSDRatio; double lowPrice = 2.372 / USDToRSDRatio; while (true) { hourOfTheDay = ConnectHelper.ConnectUniversalClock().GetTimeInHours(); price = (hourOfTheDay >= 1.0 && hourOfTheDay < 7.0) ? lowPrice : highPrice; Console.WriteLine($"Price of kwh ($/kwh): {Math.Round(price, 5)} time[{hourOfTheDay}]"); Thread.Sleep(500); } }
private static void Driving(ElectricVehicleCharger evc, double drivingHours) { double drivingMinutes = drivingHours * Constants.MINUTES_IN_HOUR; int iterationStart = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes(); int dayStart = ConnectHelper.ConnectUniversalClock().GetDay(); do { int currentMoment = ConnectHelper.ConnectUniversalClock().GetTimeInMinutes(); int currentDay = ConnectHelper.ConnectUniversalClock().GetDay(); if (currentDay > dayStart || currentMoment - iterationStart >= 1) { iterationStart = currentMoment; dayStart = currentDay; } else { continue; } ElectricVehicleCharger evcFromDb = DBManager.S_Instance.GetSingleElectricVehicleCharger(evc.BatteryID); double capacityChange = evcFromDb.CurrentCapacity * Constants.MINUTES_IN_HOUR - 1; evcFromDb.CurrentCapacity = Math.Round(capacityChange / Constants.MINUTES_IN_HOUR, 2); DBManager.S_Instance.UpdateElecticVehicleCharger(evcFromDb); drivingMinutes--; }while (drivingMinutes > 0); }
public static void BatteryBehavior() { Double hourOfTheDay; 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; } Dictionary <string, Battery> batteries = DBManager.S_Instance.GetAllBatteries(); hourOfTheDay = ConnectHelper.ConnectUniversalClock().GetTimeInHours(); if (hourOfTheDay >= 3 && hourOfTheDay <= 6) { batteries = ChargeBatteries(batteries); } else if (hourOfTheDay >= 14 && hourOfTheDay <= 17) { batteries = DischargeBatteries(batteries); } else { foreach (Battery b in batteries.Values) { if (b is ElectricVehicleCharger evc) { if (evc.Mode == EMode.CONSUMING && evc.OnCharger) { evc.Consuming(); continue; } } b.Mode = EMode.NONE; } } foreach (Battery b in batteries.Values) { DBManager.S_Instance.UpdateBattery(b); } //Thread.Sleep(Constants.MILISECONDS_IN_MINUTE); } }
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); } }
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); } }
public void StartTask() { Task.Run(() => { CurrentPower = CalculatePower(ConnectHelper.ConnectWeatherForecast(), ConnectHelper.ConnectUniversalClock().GetTimeInHours()); DBManager.S_Instance.UpdateSolarPanel(this); }); }
static void Automatic(WeatherForecast_Server server) { //probaj sa currentSunlight server.Open(); Thread.Sleep(Constants.WAITING_TIME); int sunlightPercentage = 0; Random random = new Random(); while (true) { double hourOfTheDay = ConnectHelper.ConnectUniversalClock().GetTimeInHours(); if (hourOfTheDay >= 0 && hourOfTheDay < 5.5) { sunlightPercentage = 0; } else if (hourOfTheDay >= 5.5 && hourOfTheDay < 7.0) { sunlightPercentage = 25 * random.Next(8, 10) / 10; } else if (hourOfTheDay >= 7.0 && hourOfTheDay < 10.0) { sunlightPercentage = 50 * random.Next(8, 10) / 10; } else if (hourOfTheDay >= 10.0 && hourOfTheDay < 12.0) { sunlightPercentage = 75 * random.Next(8, 10) / 10; } else if (hourOfTheDay >= 12.0 && hourOfTheDay < 15.0) { sunlightPercentage = 100 * random.Next(8, 10) / 10; } else if (hourOfTheDay >= 15.0 && hourOfTheDay < 17.0) { sunlightPercentage = 75 * random.Next(8, 10) / 10; } else if (hourOfTheDay >= 17.0 && hourOfTheDay < 20.0) { sunlightPercentage = 50 * random.Next(8, 10) / 10; } else if (hourOfTheDay >= 20.0 && hourOfTheDay < 22.0) { sunlightPercentage = 25 * random.Next(8, 10) / 10; } else if (hourOfTheDay >= 22.0 && hourOfTheDay <= 23.0) { sunlightPercentage = 0; } // TODO // da li je ova dodela ok WeatherForecast_Server.CurrentSunlight = sunlightPercentage; // Console.WriteLine($"Sunlight(%): {sunlightPercentage} time[{hourOfTheDay}]"); Thread.Sleep(Constants.MILISECONDS_IN_SECOND); } }