Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
Merge pull request #9 from 2nd-Semester-Project/main
Browse files Browse the repository at this point in the history
main to userinterface
  • Loading branch information
svenons authored Mar 19, 2024
2 parents 3dd8132 + de007ec commit a8b6c9e
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 3 deletions.
59 changes: 58 additions & 1 deletion HeatOptimiser/Classes/Optimiser.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,67 @@
using System.Security.Cryptography;

namespace HeatOptimiser
{
public class Schedule
{
public DateTime startDate;
public DateTime endDate;
public List<ScheduleHour> schedule;
public Schedule(DateTime start, DateTime end)
{
startDate = start;
endDate = end;
schedule = [];
}
public void AddHour(DateTime? dateTime, List<ProductionAsset> assets, List<double> demands)
{
schedule.Add(new ScheduleHour
{
Hour = dateTime,
Assets = assets,
Demands = demands
});
}
}
public class ScheduleHour
{
public DateTime? Hour { get; set; }
public List<ProductionAsset>? Assets { get; set; }
public List<double>? Demands { get; set; }
}
public class Optimiser: IOptimiserModule
{
private ISourceDataManager sd;
private IAssetManager am;
public Optimiser(ISourceDataManager sourceDataManager, IAssetManager assetManager)
{
throw new System.NotImplementedException();
sd = sourceDataManager;
am = assetManager;
}

public Schedule Optimise(DateTime startDate, DateTime endDate)
{
SourceData data = new();
Schedule schedule = new(startDate, endDate);
ProductionAsset gasBoiler = am.SearchUnits("GB")[0];
ProductionAsset oilBoiler = am.SearchUnits("OB")[0];

foreach (SourceDataPoint hour in sd.GetDataInRange(data, startDate, endDate))
{
if (hour.HeatDemand <= gasBoiler.Heat)
{
double gasDemand = (double)hour.HeatDemand;
schedule.AddHour(hour.TimeFrom, [gasBoiler], [gasDemand]);
}
else
{
double gasCapacity = (double)gasBoiler.Heat;

Check warning on line 58 in HeatOptimiser/Classes/Optimiser.cs

View workflow job for this annotation

GitHub Actions / build

Nullable value type may be null.

Check warning on line 58 in HeatOptimiser/Classes/Optimiser.cs

View workflow job for this annotation

GitHub Actions / build

Nullable value type may be null.
double hourDemand = (double)hour.HeatDemand;

Check warning on line 59 in HeatOptimiser/Classes/Optimiser.cs

View workflow job for this annotation

GitHub Actions / build

Nullable value type may be null.

Check warning on line 59 in HeatOptimiser/Classes/Optimiser.cs

View workflow job for this annotation

GitHub Actions / build

Nullable value type may be null.
double oilDemand = hourDemand - gasCapacity;
schedule.AddHour(hour.TimeFrom, [gasBoiler, oilBoiler], [gasCapacity, oilDemand]);
}
}
return schedule;
}
}
}
35 changes: 35 additions & 0 deletions HeatOptimiser/Classes/SourceDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,40 @@ public List<SourceDataPoint> LoadXLSXFile(string file, int rowStart, int columnS

return sourceList;
}
public List<SourceDataPoint> GetDataInRange(SourceData data, DateTime startDate, DateTime endDate)
{
DateTime winterEnd = DateTime.ParseExact("31/03/2023", "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
bool rangeExists = false;
int startIndex = 0;
List<SourceDataPoint> dataCollection = startDate.Date < winterEnd.Date ? data.SummerData : data.WinterData;
foreach (SourceDataPoint point in dataCollection)
{
if (point.TimeFrom.HasValue)
{
DateTime dt = (DateTime)point.TimeFrom;
if (dt.Date == startDate.Date)
{
rangeExists = true;
break;
}
startIndex++;
}
}
int endIndex = startIndex;
if (rangeExists)
{
foreach (SourceDataPoint point in dataCollection.GetRange(startIndex, dataCollection.Count - startIndex))
{
endIndex++;
DateTime dt = (DateTime)point.TimeTo;

Check warning on line 95 in HeatOptimiser/Classes/SourceDataManager.cs

View workflow job for this annotation

GitHub Actions / build

Nullable value type may be null.

Check warning on line 95 in HeatOptimiser/Classes/SourceDataManager.cs

View workflow job for this annotation

GitHub Actions / build

Nullable value type may be null.
if (dt.Date > endDate.Date)
{
break;
}
}
return dataCollection.GetRange(startIndex, endIndex-startIndex);
}
return [];
}
}
}
2 changes: 1 addition & 1 deletion HeatOptimiser/Interfaces/IOptimiserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace HeatOptimiser
{
public interface IOptimiserModule
{

Schedule Optimise(DateTime startDate, DateTime endDate);
}
}
1 change: 1 addition & 0 deletions HeatOptimiser/Interfaces/ISourceDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace HeatOptimiser
public interface ISourceDataManager
{
public List<SourceDataPoint> LoadXLSXFile(string filePath, int rowStartd, int columnStart, int workSheetNumber);
public List<SourceDataPoint> GetDataInRange(SourceData data, DateTime startDate, DateTime endDate);
}
}
1 change: 1 addition & 0 deletions HeatOptimiser/ProductionAssets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"ID":"214839e8-f97d-4012-b50c-eb6f5f96856e","Name":"GB","Image":"none","Heat":5,"Electricity":0,"Energy":1.1,"Cost":500,"CarbonDioxide":215},{"ID":"23962281-442d-4c78-975e-a2c8777c304c","Name":"OB","Image":"none","Heat":4,"Electricity":0,"Energy":1.2,"Cost":700,"CarbonDioxide":265}]
32 changes: 31 additions & 1 deletion HeatOptimiser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,37 @@
class Program {
public static void Main()
{
AssetManager assets = new();
assets.AddUnit("GB", "none", 5.0, 0, 1.1, 500, 215);
assets.AddUnit("OB", "none", 4.0, 0, 1.2, 700, 265);

SourceDataManager dataManager = new();
Optimiser optimiser = new(dataManager, assets);
string startDateStr = "12/02/2023";
string endDateStr = "25/02/2023";
DateTime startDate = DateTime.ParseExact(startDateStr, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
DateTime endDate = DateTime.ParseExact(endDateStr, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
Schedule optimisedData = optimiser.Optimise(startDate, endDate);


// Example on visualizing the data

// foreach (ScheduleHour hour in optimisedData.schedule)
// {
// Console.WriteLine(hour.Hour);
// foreach (ProductionAsset asset in hour.Assets)
// {
// Console.Write($"{asset.Name} ");
// }
// Console.WriteLine();
// foreach (double demand in hour.Demands)
// {
// Console.Write($"{demand} ");
// }
// Console.WriteLine("\n");
// }

new TextBasedUI().example();
}
}
}
}

0 comments on commit a8b6c9e

Please sign in to comment.