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 #24 from 2nd-Semester-Project/AssetManager-Editing…
Browse files Browse the repository at this point in the history
…FunctionTest

new AssetManager
  • Loading branch information
svenons authored May 19, 2024
2 parents b652426 + a893ca8 commit 8cf769c
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 57 deletions.
2 changes: 1 addition & 1 deletion HeatOptimiser.Tests/OptimiserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void TestOptimise()
DateTime endDate = DateTime.ParseExact(endDateStr, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

// Act
Schedule schedule = Optimiser.Optimise(startDate, endDate);
Schedule schedule = Optimiser.Optimise2(startDate, endDate);

// Assert
Assert.NotNull(schedule);
Expand Down
1 change: 1 addition & 0 deletions HeatOptimiser.Tests/SourceDataManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void TestGetDataInRange()
{
// Arrange
SourceData data = new SourceData();
data.LoadedData = new List<SourceDataPoint>(); // Initialize LoadedData
DateTime startDate = new DateTime(2023, 1, 1);
DateTime endDate = new DateTime(2023, 1, 31);

Expand Down
8 changes: 7 additions & 1 deletion HeatOptimiser/Classes/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using System.Reactive;
using UserInterface.ViewModels;
using System.Net;
using Avalonia.Data;
using System.Globalization;
using Avalonia.Data.Converters;

namespace HeatOptimiser
{
Expand Down Expand Up @@ -46,7 +49,7 @@ public double? Electricity
public double? Energy
{
get { return _energy; }
set { _energy = value; }
set { _energy=value;}
}

private double? _cost;
Expand Down Expand Up @@ -192,4 +195,7 @@ public void SaveUnits(ObservableCollection<ProductionAsset> AllAssets, string fi
File.WriteAllText(fileName, jsonString);
}
}



}
1 change: 1 addition & 0 deletions HeatOptimiser/Classes/Optimiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static Schedule Optimise(DateTime startDate, DateTime endDate)
public static Schedule Optimise2(DateTime startDate, DateTime endDate)
{
SourceData data = new();
data.LoadedData = new List<SourceDataPoint>(); // Initialize LoadedData
Schedule schedule = new(startDate, endDate);

ObservableCollection<ProductionAsset> assets = AssetManager.GetAllUnits();
Expand Down
24 changes: 12 additions & 12 deletions HeatOptimiser/Classes/SourceDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ public static List<SourceDataPoint> LoadXLSXFile(string file, int rowStart, int
{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial; // EPPlus license

using (var package = new ExcelPackage(new FileInfo(file)))
using (var package = new ExcelPackage(new FileInfo(file)))
{
ExcelWorksheet worksheet;
try
{
ExcelWorksheet worksheet;
try
{
worksheet = null ?? package.Workbook.Worksheets[0];
worksheet = package.Workbook.Worksheets[workSheetNumber];
}
catch (Exception e)
{
Console.WriteLine($"Worksheet not found: {e}");
return sourceList;
}
worksheet = null ?? package.Workbook.Worksheets[0];
worksheet = package.Workbook.Worksheets[workSheetNumber];
}
catch (Exception e)
{
Console.WriteLine($"Worksheet not found: {e}");
return sourceList;
}

if (worksheet.Dimension == null)
{
Expand Down
2 changes: 1 addition & 1 deletion HeatOptimiser/ProductionAssets.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"ID":"d8303d3f-39a2-4dc1-abc7-d75d5fecdad9","Name":"GB","Image":"none","Heat":5,"Electricity":0,"Energy":1.1,"Cost":500,"CarbonDioxide":215,"IsSelected":false},{"ID":"aa0fe1d9-a586-4e42-bfe6-025ecc165c1e","Name":"OB","Image":"none","Heat":4,"Electricity":0,"Energy":1.2,"Cost":700,"CarbonDioxide":265,"IsSelected":false}]
[{"ID":"f728fabf-b907-41bb-a0d5-91f699d20a85","Name":"GB","Image":"none","Heat":5,"Electricity":0,"Energy":1.1,"Cost":500,"CarbonDioxide":215,"IsSelected":false},{"ID":"33a34683-f561-4265-a70b-c8868407cce2","Name":"OB","Image":"none","Heat":4,"Electricity":0,"Energy":1.2,"Cost":700,"CarbonDioxide":265,"IsSelected":false}]
19 changes: 3 additions & 16 deletions HeatOptimiser/ViewModels/AssetManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public string ErrorText

public ReactiveCommand<Unit, Unit> AddAssetCommand { get; }
public ReactiveCommand<Unit, Unit> DeleteAssetCommand { get; }
public ReactiveCommand<Unit, Unit> EditAssetCommand { get; }
public ReactiveCommand<Unit, Unit> UpdateAssetCommand { get; }

public string _assetEdit;

Expand Down Expand Up @@ -210,20 +210,7 @@ public void DeleteAsset()
}
public void EditAsset()
{
var selectedAsset = ProductionAssets.Where(x => x.IsSelected == true).ToList();
if(selectedAsset.Count==1)
{

AssetNameNew=selectedAsset[0].Name;
AssetHeatNew=selectedAsset[0].Heat.ToString();
AssetElectricityNew=selectedAsset[0].Electricity.ToString();
AssetEnergyNew=selectedAsset[0].Energy.ToString();
AssetCostNew=selectedAsset[0].Cost.ToString();
AssetCarbonNew=selectedAsset[0].CarbonDioxide.ToString();
AssetButton="Update Unit";
AssetManager.DeleteUnit(selectedAsset[0].ID);

}
AssetManager.SaveUnits(ProductionAssets, "ProductionAssets.json");

}
public void ValidateInput(string input)
Expand All @@ -236,7 +223,7 @@ public AssetManagerViewModel()
//Assets = new ObservableCollection<ProductionAsset>(assetManager.LoadUnits("ProductionAssets.json"));
AddAssetCommand=ReactiveCommand.Create(AddAsset);
DeleteAssetCommand=ReactiveCommand.Create(DeleteAsset);
EditAssetCommand=ReactiveCommand.Create(EditAsset);
UpdateAssetCommand=ReactiveCommand.Create(EditAsset);
//assetManager.SaveUnits(ProductionAssets, assetManager.saveFileName);
ProductionAssets=AssetManager.LoadUnits(AssetManager.saveFileName);
}
Expand Down
80 changes: 54 additions & 26 deletions HeatOptimiser/Views/AssetManagerView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@
</Style>
</UserControl.Styles>

<StackPanel Grid.Column="0" Margin="30" Spacing="10">
<StackPanel Margin="30" Spacing="10">

<TextBlock Text="Asset Manager"
HorizontalAlignment="Left"
Margin="0,0,0,20" FontSize="30"
Foreground="#a11d33"/>
<Grid>
<StackPanel Grid.Column="0" Spacing="10" Width="200" HorizontalAlignment="Left" Margin="0,0,20,0">
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="170"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="0" Spacing="5" Width="160" HorizontalAlignment="Left" Margin="10">
<StackPanel>
<TextBox Text="{Binding AssetNameNew}" Watermark="Enter Assets Name"/>
<TextBlock Text="{Binding ErrorText1}" Foreground="Red"/>
Expand All @@ -46,49 +54,69 @@
<TextBox Text="{Binding AssetCarbonNew}" Watermark="Enter CarbonDioxide"/>
<TextBlock Text="{Binding ErrorText6}" Foreground="Red"/>
</StackPanel>
<Button Content="{Binding AssetButton}" CornerRadius="50" Background="#a11d33" HorizontalAlignment="Center" Command="{Binding AddAssetCommand}" Margin="5"/>
<Button Content="Add Unit" CornerRadius="50" Background="#a11d33" HorizontalAlignment="Center" Command="{Binding AddAssetCommand}" Margin="5"/>
</StackPanel>

<ListBox Grid.Column="1" ItemsSource="{Binding ProductionAssets}" CornerRadius="20" Width="500" HorizontalAlignment="Right" Height="300" Margin="0,0,10,5">
<ListBox Grid.Column="1" ItemsSource="{Binding ProductionAssets}" CornerRadius="5" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Background="#a11d33" Spacing="10">
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock FontSize="20"
Text="{Binding Name}"
Margin="10"/>
<CheckBox HorizontalAlignment="Right"
<StackPanel Margin="5" Orientation="Horizontal" Background="#a11d33" Spacing="5">
<CheckBox HorizontalAlignment="Left"
VerticalAlignment="Center"
IsChecked="{Binding IsSelected}"/>
<TextBox FontSize="20"
Text="{Binding Name}"
Margin="10"
HorizontalAlignment="Left"
VerticalAlignment="Center"/>
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal">
<TextBlock Text=" Heat: " VerticalAlignment="Center" HorizontalAlignment="Left"/><TextBox Text="{Binding Heat}" HorizontalAlignment="Right"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal">
<TextBlock Text=" Electricity: " VerticalAlignment="Center" HorizontalAlignment="Left"/><TextBox Text="{Binding Electricity}" MaxWidth="200" HorizontalAlignment="Right"/>
</StackPanel>
<StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal">
<TextBlock Text=" Carbon: " VerticalAlignment="Center" HorizontalAlignment="Left"/><TextBox Text="{Binding CarbonDioxide}" Width="40" HorizontalAlignment="Right"/>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal">
<Rectangle Grid.Column="0" Grid.Row="1" Fill="Blue"/>
<TextBlock Text=" Energy: " VerticalAlignment="Center" HorizontalAlignment="Left"/><TextBox Text="{Binding Energy}" Width="40" HorizontalAlignment="Right"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal">
<TextBlock Text=" Cost: " VerticalAlignment="Center" HorizontalAlignment="Left"/><TextBox Text="{Binding Cost}" Width="40" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
</StackPanel>

<StackPanel Margin="5,5,5,5" Orientation="Horizontal">
<TextBlock Text="Heat: "/><TextBlock Text="{Binding Heat}"/>
<TextBlock Margin="15,0,0,0" Text="Electricity: "/><TextBox Text="{Binding Electricity}"/>
<TextBlock Margin="15,0,0,0" Text="Energy: "/><TextBlock Text="{Binding Energy}"/>
<TextBlock Margin="15,0,0,0" Text="Cost: "/><TextBlock Text="{Binding Cost}"/>
<TextBlock Margin="15,0,0,0" Text="Carbon: "/><TextBlock Text="{Binding CarbonDioxide}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="10,10,20,150">
<Button Content="Edit Asset"

<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Margin="10">
<Button Content="Update Units"
CornerRadius="25"
Background="#a11d33"
Width="130"
HorizontalAlignment="Left"
Margin="0,0,20,0"
Command="{Binding EditAssetCommand}"/>
<Button Content="Delete Assets"
Command="{Binding UpdateAssetCommand}"/>
<Button Content="Delete Units"
CornerRadius="25"
Background="#a11d33"
Width="130"
Command="{Binding DeleteAssetCommand}"/>
</StackPanel>

</Grid>
</StackPanel>

</UserControl>
Loading

0 comments on commit 8cf769c

Please sign in to comment.