Skip to content

Commit 90cbfe4

Browse files
authored
bug fix in test util. produce individual and summary csv (#1318)
1 parent f3e151a commit 90cbfe4

4 files changed

Lines changed: 288 additions & 204 deletions

File tree

HEC.FDA.TestingUtility/ComputeRunner.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public async Task<int> RunAsync()
7171
Stopwatch studyStopwatch = Stopwatch.StartNew();
7272
int studyErrors = 0;
7373
int studyCompleted = 0;
74+
CsvReportFactory studyReportFactory = new();
7475

7576
try
7677
{
@@ -94,23 +95,27 @@ public async Task<int> RunAsync()
9495
SaveStageDamageResults(compute.ElementName, sdResult.StageDamageFunctions);
9596
WriteStructureDetails(study.StudyId, compute.ElementName, sdResult);
9697
_csvReportFactory.AddStageDamageSummary(study.StudyId, compute.ElementName, sdResult.StageDamageFunctions);
98+
studyReportFactory.AddStageDamageSummary(study.StudyId, compute.ElementName, sdResult.StageDamageFunctions);
9799
break;
98100

99101
case "scenario":
100102
ScenarioResults scenarioResults = ScenarioRunner.RunScenario(compute.ElementName, _cts.Token);
101103
IASElement scenarioElement = SaveScenarioResults(compute.ElementName, scenarioResults);
102104
_csvReportFactory.AddScenarioResults(study.StudyId, scenarioElement);
105+
studyReportFactory.AddScenarioResults(study.StudyId, scenarioElement);
103106
break;
104107

105108
case "alternative":
106109
AlternativeResults altResults = AlternativeRunner.RunAlternative(compute.ElementName, _cts.Token);
107110
AlternativeElement altElement = SaveAlternativeResults(compute.ElementName, altResults);
108111
_csvReportFactory.AddAlternativeResults(study.StudyId, altElement);
112+
studyReportFactory.AddAlternativeResults(study.StudyId, altElement);
109113
break;
110114

111115
case "alternativecomparison":
112116
(AlternativeComparisonReportResults compResults, List<(int altId, string altName)> withProjAlts) = RunAlternativeComparisonWithMetadata(compute.ElementName, _cts.Token);
113117
_csvReportFactory.AddAlternativeComparisonResults(study.StudyId, compute.ElementName, compResults, withProjAlts);
118+
studyReportFactory.AddAlternativeComparisonResults(study.StudyId, compute.ElementName, compResults, withProjAlts);
114119
break;
115120

116121
default:
@@ -149,6 +154,13 @@ public async Task<int> RunAsync()
149154
studyTimings.Add((study.StudyId, studyStopwatch.Elapsed, studyCompleted, studyErrors));
150155
completed += studyCompleted;
151156
errors += studyErrors;
157+
158+
// Save per-study CSV report
159+
string studyOutputDir = Path.Combine(_outputDir, study.StudyId);
160+
Directory.CreateDirectory(studyOutputDir);
161+
string studyCsvPath = Path.Combine(studyOutputDir, "results_report.csv");
162+
studyReportFactory.SaveReport(studyCsvPath);
163+
152164
Console.WriteLine($" Completed in {FormatDuration(studyStopwatch.Elapsed)} ({studyCompleted} succeeded, {studyErrors} failed)");
153165
Console.WriteLine();
154166
}

HEC.FDA.TestingUtility/README.md

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HEC.FDA.TestingUtility
22

3-
A command-line regression testing tool for HEC-FDA studies. It loads FDA study databases, runs computations (stage damage, scenarios, alternatives, and alternative comparisons), and produces a comprehensive CSV report of the results.
3+
A command-line regression testing tool for HEC-FDA studies. It loads FDA study databases, runs computations (stage damage, scenarios, alternatives, and alternative comparisons), and produces comprehensive CSV reports of the results.
44

55
## Purpose
66

@@ -18,7 +18,17 @@ This utility runs FDA computations outside the GUI so that results can be valida
1818
dotnet build HEC.FDA.TestingUtility/HEC.FDA.TestingUtility.csproj
1919
```
2020

21-
### 2. Create a configuration file
21+
### 2a. Run directly against a study file (simplest)
22+
23+
If you just want to run all computations on a single study, point directly at its `.sqlite` file:
24+
25+
```bash
26+
dotnet run --project HEC.FDA.TestingUtility -- compute -sp "C:/path/to/my/study/MyStudy.sqlite" -o results
27+
```
28+
29+
This auto-discovers and runs all stage damage, scenario, alternative, and alternative comparison elements in the study. Output defaults to the study's directory if `-o` is not specified.
30+
31+
### 2b. Run with a configuration file (multiple studies or selective runs)
2232

2333
Copy `example-config.json` from this project directory and update `networkSourcePath` to point to your FDA study folder (the folder containing the `.sqlite` or `.db` file):
2434

@@ -82,11 +92,32 @@ dotnet run --project HEC.FDA.TestingUtility -- compute -c my-test.json -o result
8292

8393
# Filter to multiple studies
8494
dotnet run --project HEC.FDA.TestingUtility -- compute -c my-test.json -s "study-a" -s "study-b"
95+
96+
# Run directly against a single .sqlite file
97+
dotnet run --project HEC.FDA.TestingUtility -- compute -sp "C:/Studies/Muncie/Muncie.sqlite" -o results
8598
```
8699

87100
### 4. Check the output
88101

89-
After the run completes, look for `results_report.csv` in the output directory. It contains separate sections for scenario EAD, damage by category, performance metrics, alternative EqAD, stage damage summaries, and alternative comparison results.
102+
After the run completes, the output directory will contain:
103+
104+
```
105+
results/
106+
results_report.csv # Global summary across all studies
107+
muncie/
108+
results_report.csv # Per-study report for Muncie
109+
StructureDetails/
110+
My Stage Damage_StructureStageDamageDetails.csv
111+
My Stage Damage_DamagedElementCountsByStage.csv
112+
greenbrook/
113+
results_report.csv # Per-study report for Greenbrook
114+
StructureDetails/
115+
...
116+
```
117+
118+
- **`results_report.csv`** (root) - Combined report across all studies with sections for scenario EAD, damage by category, performance metrics, alternative EqAD, stage damage summaries, and alternative comparison results.
119+
- **`{studyId}/results_report.csv`** - Same report format, but scoped to a single study.
120+
- **`{studyId}/StructureDetails/`** - Generated for computed (non-manual) stage damage elements. Contains per-structure stage-damage details and damaged element counts by stage.
90121

91122
The console output will also show a summary:
92123

@@ -118,16 +149,19 @@ dotnet build HEC.FDA.TestingUtility/HEC.FDA.TestingUtility.csproj
118149
The utility uses the `System.CommandLine` library and exposes a `compute` subcommand:
119150

120151
```bash
121-
dotnet run --project HEC.FDA.TestingUtility -- compute --config <path-to-config.json> [options]
152+
dotnet run --project HEC.FDA.TestingUtility -- compute [options]
122153
```
123154

155+
You must provide either `--config` or `--study-path` (but not both).
156+
124157
### Options
125158

126-
| Option | Alias | Required | Description |
127-
|---|---|---|---|
128-
| `--config` | `-c` | Yes | Path to a JSON configuration file defining the studies and computations to run. |
129-
| `--output` | `-o` | No | Output directory for generated files. Defaults to the current working directory. |
130-
| `--study` | `-s` | No | Filter to one or more specific study IDs. Can be specified multiple times. |
159+
| Option | Alias | Description |
160+
|---|---|---|
161+
| `--config` | `-c` | Path to a JSON configuration file defining the studies and computations to run. Required unless `--study-path` is used. |
162+
| `--study-path` | `-sp` | Path to a `.sqlite` study file. Runs all computations (stage damage, scenarios, alternatives, alternative comparisons) automatically. Required unless `--config` is used. |
163+
| `--output` | `-o` | Output directory for generated files. Defaults to the current working directory (or the study directory when using `--study-path`). |
164+
| `--study` | `-s` | Filter to one or more specific study IDs. Can be specified multiple times. Only applies when using `--config`. |
131165

132166
### Examples
133167

@@ -143,6 +177,18 @@ Run only a specific study:
143177
dotnet run --project HEC.FDA.TestingUtility -- compute -c tests/regression.json -s "muncie"
144178
```
145179

180+
Run a single study directly without a config file:
181+
182+
```bash
183+
dotnet run --project HEC.FDA.TestingUtility -- compute -sp "E:/Studies/Muncie/Muncie.sqlite" -o results/
184+
```
185+
186+
Run all case studies from a directory (see `example-directory.json`):
187+
188+
```bash
189+
dotnet run --project HEC.FDA.TestingUtility -- compute -c example-directory.json -o results/
190+
```
191+
146192
## Configuration File
147193

148194
The configuration is a JSON file with the following structure:
@@ -152,7 +198,7 @@ The configuration is a JSON file with the following structure:
152198
"testSuiteId": "regression-v1",
153199
"globalSettings": {
154200
"localTempDirectory": "C:/temp/FDATests",
155-
"timeoutMinutes": 30
201+
"timeoutMinutes": 120
156202
},
157203
"studies": [
158204
{
@@ -174,7 +220,7 @@ The configuration is a JSON file with the following structure:
174220
| Field | Default | Description |
175221
|---|---|---|
176222
| `localTempDirectory` | System temp + `FDATests` | Directory where studies are copied locally before computation. |
177-
| `timeoutMinutes` | `30` | Maximum wall-clock time for all computations before cancellation. |
223+
| `timeoutMinutes` | `120` | Maximum wall-clock time for all computations before cancellation. Set to `0` to disable the timeout. |
178224

179225
### Study Configuration
180226

@@ -211,6 +257,15 @@ Valid `type` values (case-insensitive):
211257

212258
Computations are automatically sorted in dependency order: stage damage -> scenario -> alternative -> alternative comparison. This means you can list them in any order and the utility will execute them correctly.
213259

260+
## Example Configuration Files
261+
262+
| File | Description |
263+
|---|---|
264+
| `example-config.json` | Minimal template for a single study with all `runAll*` flags enabled. |
265+
| `example-directory.json` | Template for running all studies found as subfolders under a common parent directory. |
266+
| `all_case_studies.json` | Real-world config targeting 9 case studies with all computations. |
267+
| `sunnyvale_alt_only.json` | Example of a selective run (alternatives only). |
268+
214269
## How It Works
215270

216271
1. **Study Loading** - The study folder is copied from `networkSourcePath` to a local temp directory to avoid locking network files. The SQLite database is opened and all element types are loaded into the `StudyCache` in dependency order (terrains, impact areas, hydraulics, frequencies, inventories, stage damage, scenarios, alternatives, etc.).
@@ -223,7 +278,7 @@ Computations are automatically sorted in dependency order: stage damage -> scena
223278

224279
3. **Result Saving** - Computed results are saved back to the temp study database so that downstream computations (e.g., alternatives depending on scenario results) can access them.
225280

226-
4. **CSV Report** - A single `results_report.csv` file is written to the output directory containing sections for:
281+
4. **CSV Report** - A `results_report.csv` file is written both globally (to the output directory) and per-study (to `{outputDir}/{studyId}/`). Each report contains sections for:
227282
- Scenario results (mean and percentile EAD by impact area)
228283
- Scenario damage by category
229284
- Scenario performance (long-term risk, AEP, assurance)
@@ -234,7 +289,11 @@ Computations are automatically sorted in dependency order: stage damage -> scena
234289
- Alternative comparison summary (EqAD reduced, base/future EAD reduced)
235290
- Alternative comparison by damage category
236291

237-
5. **Cleanup** - When a study finishes, the temp copy is deleted automatically.
292+
5. **Structure Details** - For computed (non-manual) stage damage elements, two additional CSVs are written to `{outputDir}/{studyId}/StructureDetails/`:
293+
- `{elementName}_StructureStageDamageDetails.csv` - Per-structure stage-damage detail curves.
294+
- `{elementName}_DamagedElementCountsByStage.csv` - Number of damaged elements at each stage.
295+
296+
6. **Cleanup** - When a study finishes, the temp copy is deleted automatically.
238297

239298
## Project Structure
240299

0 commit comments

Comments
 (0)