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

RDM and Data Visualising #29

Merged
merged 19 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions HeatOptimiser.Tests/SourceDataManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public void TestLoadXLSXFile()
string projectDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
#pragma warning restore CS8602 // Dereference of a possibly null reference.
string file = Path.Combine(projectDirectory, "SourceDataTest.xlsx");
Console.WriteLine(file);

// Act
var result = SourceDataManager.LoadXLSXFile(file, 2, 4);
Expand All @@ -27,13 +26,11 @@ public void TestLoadXLSXFile()
public void TestGetDataInRange()
{
// Arrange
SourceData data = new SourceData();
data.LoadedData = new ObservableCollection<SourceDataPoint>(); // Initialize LoadedData
DateTime startDate = new DateTime(2023, 1, 1);
DateTime endDate = new DateTime(2023, 1, 31);

// Act
var result = SourceDataManager.GetDataInRange(data, startDate, endDate);
var result = SourceDataManager.GetDataInRange(startDate, endDate);

// Assert
Assert.NotNull(result);
Expand Down
2 changes: 2 additions & 0 deletions HeatOptimiser/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ namespace UserInterface;

public partial class App : Application
{
// Initialises new avalonia app
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

// Sets up the main window of the application with the appropriate view model when the framework initialization is completed.
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
Expand Down
46 changes: 30 additions & 16 deletions HeatOptimiser/Classes/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public double? CarbonDioxide
get { return _carbonDioxide; }
set { _carbonDioxide = value; }
}
public bool _isSelected;
private bool _isSelected;
public bool IsSelected
{
get => _isSelected;
set => this.RaiseAndSetIfChanged(ref _isSelected, value);
}
public bool _optimiseSelected;
private bool _optimiseSelected;
public bool OptimiseSelected
{
get => _optimiseSelected;
Expand All @@ -82,7 +82,7 @@ public static class AssetManager
{
public static ObservableCollection<ProductionAsset> _productionAssets = new ObservableCollection<ProductionAsset>();
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)
public static void AddUnit(string name, string image, double heat, double electricity, double energy, double cost, double carbonDioxide) // this function adds a production asset to the manager
{
if (name != null && image != null && !string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(image))
{
Expand All @@ -98,19 +98,19 @@ public static void AddUnit(string name, string image, double heat, double electr
IsSelected = false,
OptimiseSelected = false
});
_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.
_jsonAssetStorage.SaveUnits(_productionAssets);
}
else
{
throw new ArgumentNullException("Name and Image cannot be null");
}
}
public static void DeleteUnit(Guid ID)
public static void DeleteUnit(Guid ID) //this function deletes an asset and saves the units.
{
_productionAssets.Remove(_productionAssets.FirstOrDefault(x => x.ID == ID)!);
_jsonAssetStorage.SaveUnits(_productionAssets); // this is also up for debate, just like on AddUnit.
_jsonAssetStorage.SaveUnits(_productionAssets);
}
public static void EditUnit(Guid ID, int index, string stringValue)
public static void EditUnit(Guid ID, int index, string stringValue) //this function edits units picture or name and saves
{
switch (index)
{
Expand All @@ -123,9 +123,9 @@ 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); // this is also up for debate, just like on AddUnit.
_jsonAssetStorage.SaveUnits(_productionAssets);
}
public static void EditUnit(Guid ID, int index, double doubleValue)
public static void EditUnit(Guid ID, int index, double doubleValue) //this function edits units information that is with a double value, and saves
{
switch (index)
{
Expand All @@ -147,23 +147,31 @@ 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); // this is also up for debate, just like on AddUnit.
_jsonAssetStorage.SaveUnits(_productionAssets);
}
public static ObservableCollection<ProductionAsset> GetAllUnits()
{
return _productionAssets;
}
public static void SetSelectedUnits(ObservableCollection<ProductionAsset> productionAssets)
{
foreach (var asset in productionAssets)
{
_productionAssets.FirstOrDefault(x => x.ID == asset.ID)!.OptimiseSelected = asset.OptimiseSelected;
}
}
public static ObservableCollection<ProductionAsset> GetSelectedUnits()
{
var assets = _productionAssets.Where(x => x._optimiseSelected == true).ToList();
ObservableCollection<ProductionAsset> selectedAssets = new ObservableCollection<ProductionAsset>(assets);
var assets = _productionAssets.Where(x => x.OptimiseSelected == true).ToList();
ObservableCollection<ProductionAsset> selectedAssets = new(assets);
return selectedAssets;

}
public static ObservableCollection<ProductionAsset> LoadUnits()
{
_productionAssets = _jsonAssetStorage.LoadUnits();
if (_productionAssets.Count == 0 || _productionAssets == null)
_productionAssets = _jsonAssetStorage.LoadUnits();
return _productionAssets;

}
public static void SaveUnits(ObservableCollection<ProductionAsset> AllAssets)
{
Expand All @@ -175,6 +183,12 @@ public static ObservableCollection<ProductionAsset> SearchUnits(string name)
ObservableCollection<ProductionAsset> selected = [.. selection];
return selected;
}
public static ObservableCollection<ProductionAsset> SearchUnits(Guid searchID)
{
var selection = _productionAssets.Where(x => x.ID == searchID).ToList();
ObservableCollection<ProductionAsset> selected = [.. selection];
return selected;
}
}
public class JsonAssetStorage
{
Expand All @@ -183,7 +197,7 @@ public JsonAssetStorage(string passedFilePath)
{
filePath = passedFilePath;
}
public ObservableCollection<ProductionAsset> LoadUnits()
public ObservableCollection<ProductionAsset> LoadUnits() // this function loads assets from a json file.
{
if (File.Exists(filePath) && new FileInfo(filePath).Length > 2)
{
Expand All @@ -203,7 +217,7 @@ public ObservableCollection<ProductionAsset> LoadUnits()
return new ObservableCollection<ProductionAsset>();
}
}
public void SaveUnits(ObservableCollection<ProductionAsset> AllAssets)
public void SaveUnits(ObservableCollection<ProductionAsset> AllAssets) //this function saves units to json file.
{
string jsonString = JsonSerializer.Serialize(AllAssets);
File.WriteAllText(filePath, jsonString);
Expand Down
Loading
Loading