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 #28 from 2nd-Semester-Project/SDM-DV-Restructure
Browse files Browse the repository at this point in the history
Sdm dv restructure
  • Loading branch information
svenons authored May 28, 2024
2 parents f4f42ac + 73be4c2 commit e344454
Show file tree
Hide file tree
Showing 25 changed files with 600 additions and 663 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"args": [],
"cwd": "${workspaceFolder}/HeatOptimiser",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"console": "externalTerminal",
"stopAtEntry": false
},
{
Expand Down
16 changes: 2 additions & 14 deletions HeatOptimiser.Tests/AssetManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ public void TestAssetManagerLoadAndSaveUnits()
{
// Arrange
AssetManager.AddUnit("Unit 1", "image1.jpg", 10.5, 20.5, 30.5, 40.5, 50.5);
AssetManager.SaveUnits(AssetManager.GetAllUnits(), "TestUnits.json");
AssetManager.SaveUnits(AssetManager.GetAllUnits());

// Act
AssetManager.LoadUnits("TestUnits.json");
var units = AssetManager.GetAllUnits();
ObservableCollection<ProductionAsset> units = AssetManager.LoadUnits();

// Assert
Assert.NotNull(units);
Expand All @@ -85,16 +84,5 @@ public void TestAssetManagerLoadAndSaveUnits()

AssetManager.DeleteUnit(AssetManager.GetAllUnits()[0].ID);
}
[Fact]
public void TestAssetManagerSetSaveFile()
{
// Act
AssetManager.SetSaveFile("TestUnits.json");
var saveFileName = AssetManager.saveFileName;

// Assert
Assert.NotNull(saveFileName);
Assert.Equal("TestUnits.json", saveFileName);
}
}
}
5 changes: 3 additions & 2 deletions HeatOptimiser.Tests/SourceDataManagerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit;
using System.Collections.ObjectModel;

namespace HeatOptimiser.Tests
{
Expand All @@ -15,7 +16,7 @@ public void TestLoadXLSXFile()
Console.WriteLine(file);

// Act
var result = SourceDataManager.LoadXLSXFile(file, 4, 2);
var result = SourceDataManager.LoadXLSXFile(file, 2, 4);

// Assert
Assert.NotNull(result);
Expand All @@ -27,7 +28,7 @@ public void TestGetDataInRange()
{
// Arrange
SourceData data = new SourceData();
data.LoadedData = new List<SourceDataPoint>(); // Initialize LoadedData
data.LoadedData = new ObservableCollection<SourceDataPoint>(); // Initialize LoadedData
DateTime startDate = new DateTime(2023, 1, 1);
DateTime endDate = new DateTime(2023, 1, 31);

Expand Down
Binary file added HeatOptimiser/Assets/800px-Danfoss-Logo.svg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 34 additions & 20 deletions HeatOptimiser/Classes/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ public bool IsSelected
get => _isSelected;
set => this.RaiseAndSetIfChanged(ref _isSelected, value);
}
public bool _optimiseSelected;
public bool OptimiseSelected
{
get => _optimiseSelected;
set => this.RaiseAndSetIfChanged(ref _optimiseSelected, value);
}
}
public static class AssetManager
{
public static string saveFileName = "ProductionAssets.json";
public static ObservableCollection<ProductionAsset> _productionAssets = new ObservableCollection<ProductionAsset>();
private static JsonAssetStorage _jsonAssetStorage = new JsonAssetStorage();
private static JsonAssetStorage _jsonAssetStorage = new JsonAssetStorage("ProductionAssets.json");
public static void AddUnit(string name, string image, double heat, double electricity, double energy, double cost, double carbonDioxide)
{
if (name != null && image != null && !string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(image))
Expand All @@ -90,9 +95,10 @@ public static void AddUnit(string name, string image, double heat, double electr
Energy = energy,
Cost = cost,
CarbonDioxide = carbonDioxide,
IsSelected = false
IsSelected = false,
OptimiseSelected = false
});
_jsonAssetStorage.SaveUnits(_productionAssets, saveFileName); // this is up for debate, I just want to auto save, and they likely wont have thousands of production units, that could cause a performance issue.
_jsonAssetStorage.SaveUnits(_productionAssets); // this is up for debate, I just want to auto save, and they likely wont have thousands of production units, that could cause a performance issue.
}
else
{
Expand All @@ -102,7 +108,7 @@ public static void AddUnit(string name, string image, double heat, double electr
public static void DeleteUnit(Guid ID)
{
_productionAssets.Remove(_productionAssets.FirstOrDefault(x => x.ID == ID)!);
_jsonAssetStorage.SaveUnits(_productionAssets, saveFileName); // this is also up for debate, just like on AddUnit.
_jsonAssetStorage.SaveUnits(_productionAssets); // this is also up for debate, just like on AddUnit.
}
public static void EditUnit(Guid ID, int index, string stringValue)
{
Expand All @@ -117,7 +123,7 @@ public static void EditUnit(Guid ID, int index, string stringValue)
default:
throw new ArgumentOutOfRangeException("Index out of range or wrong type used");
}
_jsonAssetStorage.SaveUnits(_productionAssets, saveFileName); // this is also up for debate, just like on AddUnit.
_jsonAssetStorage.SaveUnits(_productionAssets); // this is also up for debate, just like on AddUnit.
}
public static void EditUnit(Guid ID, int index, double doubleValue)
{
Expand All @@ -141,39 +147,47 @@ public static void EditUnit(Guid ID, int index, double doubleValue)
default:
throw new ArgumentOutOfRangeException("Index out of range or wrong type used");
}
_jsonAssetStorage.SaveUnits(_productionAssets, saveFileName); // this is also up for debate, just like on AddUnit.
_jsonAssetStorage.SaveUnits(_productionAssets); // this is also up for debate, just like on AddUnit.
}
public static ObservableCollection<ProductionAsset> GetAllUnits()
{
return _productionAssets;
}
public static ObservableCollection<ProductionAsset> LoadUnits(string fileName)
public static ObservableCollection<ProductionAsset> GetSelectedUnits()
{
var assets = _productionAssets.Where(x => x._optimiseSelected == true).ToList();
ObservableCollection<ProductionAsset> selectedAssets = new ObservableCollection<ProductionAsset>(assets);
return selectedAssets;

}
public static ObservableCollection<ProductionAsset> LoadUnits()
{
_productionAssets = _jsonAssetStorage.LoadUnits(fileName);
_productionAssets = _jsonAssetStorage.LoadUnits();
return _productionAssets;
}
public static void SaveUnits(ObservableCollection<ProductionAsset> AllAssets, string fileName)
public static void SaveUnits(ObservableCollection<ProductionAsset> AllAssets)
{
_jsonAssetStorage.SaveUnits(AllAssets, fileName);
_jsonAssetStorage.SaveUnits(AllAssets);
}
public static ObservableCollection<ProductionAsset> SearchUnits(string name)
{
var selection = _productionAssets.Where(x => x.Name!.ToLower().Contains(name.ToLower())).ToList();
ObservableCollection<ProductionAsset> selected = [.. selection];
return selected;
}
public static void SetSaveFile(string fileName)
{
saveFileName = fileName;
}
}
public class JsonAssetStorage
{
public ObservableCollection<ProductionAsset> LoadUnits(string fileName)
private string filePath;
public JsonAssetStorage(string passedFilePath)
{
filePath = passedFilePath;
}
public ObservableCollection<ProductionAsset> LoadUnits()
{
if (File.Exists(fileName) && new FileInfo(fileName).Length > 2)
if (File.Exists(filePath) && new FileInfo(filePath).Length > 2)
{
string jsonString = File.ReadAllText(fileName);
string jsonString = File.ReadAllText(filePath);
try
{
var info = JsonSerializer.Deserialize<ObservableCollection<ProductionAsset>>(jsonString)!;
Expand All @@ -189,10 +203,10 @@ public ObservableCollection<ProductionAsset> LoadUnits(string fileName)
return new ObservableCollection<ProductionAsset>();
}
}
public void SaveUnits(ObservableCollection<ProductionAsset> AllAssets, string fileName)
public void SaveUnits(ObservableCollection<ProductionAsset> AllAssets)
{
string jsonString = JsonSerializer.Serialize(AllAssets);
File.WriteAllText(fileName, jsonString);
File.WriteAllText(filePath, jsonString);
}
}

Expand Down
59 changes: 51 additions & 8 deletions HeatOptimiser/Classes/DataVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,70 @@
using System.Collections.ObjectModel;
using DynamicData;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
using static System.Runtime.InteropServices.JavaScript.JSType;
using UserInterface.ViewModels;

namespace HeatOptimiser
{

public static class DataVisualizer
{
public static SourceData sourceData = new SourceData();
public static SourceData sourceData = new();

public static readonly ObservableCollection<DateTimePoint>? HeatDemandData = new ObservableCollection<DateTimePoint>();
public static void AccessSummerData()
public static readonly ObservableCollection<DateTimePoint>? HeatDemandData = new();
public static void VisualiseSourceData(List<List<DateTimePoint>> data, List<string> names)
{
// Accessing the summer data
foreach (var point in sourceData.LoadedData)
List<SKColor> colors = [
new SKColor(194, 36, 62),
new SKColor(0, 92, 230)
];
SourceDataManager.Series = [];
SourceDataManager.XAxes = [];
SourceDataManager.YAxes = new Axis[names.Count];
if (data.Count != names.Count)
{
if (point.TimeFrom.HasValue) // Ensuring the time is not null
Console.WriteLine("Invalid arguments!");
return;
}
for(int index = 0; index < data.Count; index++)
{
LineSeries<DateTimePoint> lineSeries = new()
{
Values = data[index],
Name = names[index],
Fill = null,
GeometryStroke = null,
GeometryFill = null,
LineSmoothness = 1,
Stroke = new SolidColorPaint(colors[index%colors.Count])
{
StrokeThickness = 3
}
};
Axis axis = new()
{
Name = names[index],
TextSize = 16,
NameTextSize = 18
};
if (index != 0)
{
HeatDemandData?.Add(new DateTimePoint(point.TimeFrom.Value, point.HeatDemand));
// SummerElectricityPrices.Add(point.ElectricityPrice);
lineSeries.LineSmoothness = 2;
lineSeries.ScalesYAt = 1;
axis.Position = LiveChartsCore.Measure.AxisPosition.End;
}
SourceDataManager.Series.Add(
lineSeries
);
SourceDataManager.YAxes[index] = axis;
}
SourceDataManager.XAxes = [
new DateTimeAxis(TimeSpan.FromDays(1), date => date.ToString("MMMM dd HH:mm"))
];
}
}
}
Loading

0 comments on commit e344454

Please sign in to comment.