Skip to content

Commit

Permalink
issue #49: Correct data structures for performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
lbross committed Apr 24, 2024
1 parent 1acb651 commit 8c00365
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions bagis-pro/DockAdminToolsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,8 @@ private async void RunFireReportImplAsync(object param)
// Create initial log entry
string strLogEntry = DateTime.Now.ToString("MM/dd/yy H:mm:ss ") + "Starting fire report " + "\r\n";
File.WriteAllText(_strFireReportLogFile, strLogEntry); // overwrite file if it exists

// Dictionary: Key is the year, Value is an ArrayList of the values for that line
IDictionary<string, IList<IList<string>>> dictOutput = new Dictionary<string, IList<IList<string>>>();
int minYear = FireBaselineYear - FireDataClipYears;
for (int idxRow = 0; idxRow < Names.Count; idxRow++)
{
Expand All @@ -2172,7 +2173,6 @@ private async void RunFireReportImplAsync(object param)
Names[idxRow].Name + "\r\n";
File.AppendAllText(_strFireReportLogFile, strLogEntry); // append
}
string strAoiFolder = GeodatabaseTools.GetGeodatabasePath(aoiFolder, GeodatabaseNames.Aoi);
// Set current AOI
Aoi oAoi = await GeneralTools.SetAoiAsync(aoiFolder, Names[idxRow]);
if (Module1.Current.CboCurrentAoi != null)
Expand All @@ -2186,36 +2186,61 @@ private async void RunFireReportImplAsync(object param)

for (int i = minYear; i <= FireBaselineYear; i++)
{
// Structures to manage data
string strCsvFile = $@"{Path.GetDirectoryName(_strFireReportLogFile)}\{i}_annual_statistics.csv";
string separator = ",";
StringBuilder output = new StringBuilder();
String[] headings = { "stationTriplet", "stationName", $@"{i}_newfireno" };
output.AppendLine(string.Join(separator, headings));

IList<string> lstElements = await AnalysisTools.GenerateFireStatisticsList(oAoi, _strFireReportLogFile, i);
output.AppendLine(string.Join(separator, lstElements));



try
if (dictOutput.ContainsKey(i.ToString()))
{
// Overwrites file with new content
File.WriteAllText(strCsvFile, output.ToString());
dictOutput[i.ToString()].Add(lstElements);
}
catch (Exception ex)
else
{
strLogEntry = $@"{DateTime.Now.ToString("MM/dd/yy H:mm:ss")} Data could not be written to the CSV file!{System.Environment.NewLine}";
File.AppendAllText(_strFireReportLogFile, strLogEntry);
MessageBox.Show("Data could not be written to the CSV file!", "BAGIS-PRO");
return;
}
IList<IList<string>> lstNew = new List<IList<string>>();
lstNew.Add(lstElements);
dictOutput.Add(i.ToString(), lstNew);
}
}

Names[idxRow].AoiBatchStateText = AoiBatchState.Completed.ToString(); // update gui
strLogEntry = DateTime.Now.ToString("MM/dd/yy H:mm:ss ") + "Finished generate fire statistics export for " +
Names[idxRow].Name + "\r\n";
File.AppendAllText(_strFireReportLogFile, strLogEntry); // append
}
}

// Write out results from dictionary
for (int i = minYear; i <= FireBaselineYear; i++)
{
// Structures to manage data
string strCsvFile = $@"{Path.GetDirectoryName(_strFireReportLogFile)}\{i}_annual_statistics.csv";
string separator = ",";
StringBuilder output = new StringBuilder();
String[] headings = { "stationTriplet", "stationName", $@"{i}_newfireno" };
output.AppendLine(string.Join(separator, headings));

if (dictOutput.ContainsKey(i.ToString()))
{
IList<IList<string>> lstYearElements = dictOutput[i.ToString()];
foreach (var item in lstYearElements)
{
output.AppendLine(string.Join(separator, item));
}
}

try
{
// Overwrites file with new content
File.WriteAllText(strCsvFile, output.ToString());
}
catch (Exception ex)
{
strLogEntry = $@"{DateTime.Now.ToString("MM/dd/yy H:mm:ss")} Data could not be written to the CSV file!{System.Environment.NewLine}";
File.AppendAllText(_strFireReportLogFile, strLogEntry);
MessageBox.Show("Data could not be written to the CSV file!", "BAGIS-PRO");
return;
}
}



}

private string CreateLogEntry(string strAoiPath, string strOldTriplet, string strNewTriplet, string strRemarks)
Expand Down

0 comments on commit 8c00365

Please sign in to comment.