ROBERT311
ROBERT311
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
while i agree with you i still dont understand why it sometimes wont properly output to the csv files and sometimes it will
16 replies
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
i know but when i reference normally it doesent work since we ve added another unit test project in the same folder
16 replies
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
i am running the project through vs code so it shouldnt have any permission issue to the csv files
16 replies
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
project runs through avalonia framework if thats relevant i can share the starting poin
16 replies
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
sometimes it works sometimes it doesen't i cannot find a pattern i have tried closing opening, dotnet clean dotnet build , restarting pc , recloning the project i have no idea
16 replies
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
ok so there are csv files in my project and the output needs to be stored inside them through this method
public void SaveResultsToCsv(string unitName)
{

string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

string relativeDirectory = Path.Combine(baseDirectory, @"..\..\..\Assets\ProductionUnitResults");

// Resolve the absolute path
string resolvedDirectory = Path.GetFullPath(relativeDirectory);

string filePath = unitName switch
{
"GB1" => Path.Combine(resolvedDirectory, "GB1_Results.csv"),
"GB2" => Path.Combine(resolvedDirectory, "GB2_Results.csv"),
"OB1" => Path.Combine(resolvedDirectory, "OB1_Results.csv"),
_ => throw new Exception($"Unknown unit name: {unitName}")
};

var resultsForUnit = optimizationResults.Where(r => r.UnitName == unitName).ToList();

// Writing to CSV
if (File.Exists(filePath))
{
using (var writer = new StreamWriter(filePath, append: true))
{

foreach (var result in resultsForUnit)
{
writer.WriteLine($"{result.UnitName},{result.HeatProduced},{result.Cost},{result.FuelConsumed}");
}
}


}
else
{
Console.WriteLine($"File does not exist: {filePath}. File cannot be saved.");
}
}
}
}
public void SaveResultsToCsv(string unitName)
{

string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

string relativeDirectory = Path.Combine(baseDirectory, @"..\..\..\Assets\ProductionUnitResults");

// Resolve the absolute path
string resolvedDirectory = Path.GetFullPath(relativeDirectory);

string filePath = unitName switch
{
"GB1" => Path.Combine(resolvedDirectory, "GB1_Results.csv"),
"GB2" => Path.Combine(resolvedDirectory, "GB2_Results.csv"),
"OB1" => Path.Combine(resolvedDirectory, "OB1_Results.csv"),
_ => throw new Exception($"Unknown unit name: {unitName}")
};

var resultsForUnit = optimizationResults.Where(r => r.UnitName == unitName).ToList();

// Writing to CSV
if (File.Exists(filePath))
{
using (var writer = new StreamWriter(filePath, append: true))
{

foreach (var result in resultsForUnit)
{
writer.WriteLine($"{result.UnitName},{result.HeatProduced},{result.Cost},{result.FuelConsumed}");
}
}


}
else
{
Console.WriteLine($"File does not exist: {filePath}. File cannot be saved.");
}
}
}
}
16 replies
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
the issue was that it was literally random i couldnt find any type or kind of pattern
16 replies
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
i will post updates if i can figure something out
16 replies
CC#
Created by ROBERT311 on 4/6/2025 in #help
magic code???
ive deleted and i am trying to figure it out again
16 replies
CC#
Created by ROBERT311 on 3/17/2025 in #help
need help!!! unit testing
oh you mean it might be multiple elements compared instead of one actual element because of the comma?
6 replies
CC#
Created by ROBERT311 on 3/17/2025 in #help
need help!!! unit testing
using xUnit
6 replies