Sunday, December 29, 2024

SWMM5 Delphi GUI Dstats.pas Summary

 Below is an overview of Dstats.pas, a Delphi unit from SWMM 5.2 that provides a stay-on-top form (TStatsSelectForm) for selecting statistical analyses of time series results at a particular location (e.g., a specific node, link, subcatchment, or the entire system). The resulting selections are collected into a TStatsSelection record (from Ustats.pas) and used by SWMM to generate a statistical report (in Fstats.pas).


1. Purpose and Context

SWMM can generate long-term statistical analyses (for example, annual or seasonal frequency stats) of a parameter like node flooding, link flow, or pollutant concentration. This form allows the user to specify:

  1. Which object to analyze (subcatchment, node, link, or entire system).
  2. Which variable (e.g., runoff, flow, depth, pollutant, etc.).
  3. Which analysis type (e.g., peak, mean, total, duration, etc.).
  4. Which time period (continuous vs. event-based)
  5. Additional parameters for event definition (e.g., minimum flow, volume, or time between events).

All these choices are summarized into a TStatsSelection structure. The user then clicks OK, and SWMM launches the TStatsReportForm (defined in Fstats.pas) to produce the final report.


2. Main Form: TStatsSelectForm

2.1 Key Controls

  1. ObjectTypeCombo (TComboBox): Chooses the object category—Subcatchments, Nodes, Links, or System.
  2. ObjectIDEdit: The ID (name) of the specific subcatch, node, or link to analyze. If System is chosen, no ID is needed.
  3. VariableCombo: Lists available output variables for the chosen object category (flow, infiltration, water depth, pollutant concentration, etc.).
  4. TimePeriodCombo: Selects between continuous stats (entire simulation) or event-based stats (identified by a min. event gap).
  5. StatsTypeCombo: Picks the type of statistic—Mean, Peak, Total, Duration, Inter-event time, or for water quality—Mean Concen, Total Load, etc.
  6. MinValueEdit, MinVolEdit, MinDeltaEdit: Numeric fields used if event-based analysis is chosen, specifying minimal thresholds (minimum value, minimum volume, and minimum inter-event time) that define an “event.”
  7. ObjectIDBtn: Fills ObjectIDEdit with the currently selected item from the data browser (if consistent with the chosen category).
  8. OK, Cancel, Help: Standard actions.

2.2 Internal Variables

  • StatsTypeIndex: Distinguishes which set of stats is available (basic vs. flow vs. quality).
  • TStatsSelection fields (filled upon OK):
    • ObjectType (subcatch, node, link, system)
    • ObjectID (string)
    • Variable (index of the chosen variable)
    • TimePeriod (continuous or event-based)
    • StatsType (e.g. stMean, stPeak, stTotal, etc.)
    • MinEventDelta / MinEventValue / MinEventVolume (numeric thresholds)

3. Workflow

3.1 FormCreate / FormShow

  • ObjectTypeCombo is set to whichever object category the user is currently viewing in the data browser, if any (subcatchment, node, or link).
  • VariableCombo is then populated with the relevant list of variables, e.g., if subcatchments are chosen, the combo includes subcatchment variables from MainForm.SubcatchViewBox.Items.
  • The form also sets default combos for time period, event-based threshold fields, etc.

3.2 ObjectTypeComboClick

  • When the user picks “Subcatchments,” “Nodes,” or “Links,” the code populates VariableCombo with the correct variable list. If “System,” a separate list of system-level variables is used.
  • If an object is currently selected in the data browser, that object’s ID is loaded into ObjectIDEdit.

3.3 VariableComboClick

  • Chooses the valid StatsTypeCombo items (mean, peak, total, etc.) for the selected variable. For instance, if a pollutant variable is chosen, “Mean Concen,” “Total Load,” etc., become valid.

3.4 TimePeriodComboClick

  • If event-based analysis is chosen, certain numeric fields (MinDeltaEdit) become enabled or disabled.

3.5 OKBtnClick

  1. Calls GetStatsSelection(Stats) to fill a local TStatsSelection.
  2. If valid (e.g., if an object is selected, date/time checks are valid, etc.), it hides the form and creates a TStatsReportForm.
  3. The TStatsReportForm.CreateReport(Stats) is called to generate the statistical analysis result.

3.6 GetStatsSelection

  • Gathers ObjectType, ObjectID, Variable, and StatsType.
  • Reads numeric threshold fields for event-based analysis.
  • If ObjectType <> SYS, checks ObjectIDEdit.Text is not blank and references a valid object.
  • Sets booleans like IsQualParam or IsRainParam in the TStatsSelection record based on the chosen variable.

3.7 Validation

  • If the user fails to specify an object (except for “System”), an error message appears (“No object was selected”).
  • If PlotParameter is out of range, or if date/time are reversed (not relevant here, but might be handled similarly).
  • Then if all good, the form calls the final steps to build the stats report.

4. Additional Points

  • The form references Ustats for the TStatsSelection structure.
  • The user can specify a minimum infiltration or minimum event volume to define “events.” Only durations that exceed these thresholds are considered for event-based stats (like “Inter-Event Time” or “Duration”).

5. Summary

Dstats.pas provides a self-contained UI form to define a statistical analysis request for SWMM. By letting the user pick an object type, variable, analysis method, and time range mode (continuous vs. event-based), it compiles a TStatsSelection that’s used by the statistical report engine. This is how SWMM offers specialized statistics (peak flows, total loads, durations above thresholds, etc.) over simulation results for individual or system-level variables.

No comments:

A comprehensive explanation of how minimum travel distance relates to link length in InfoSewer

In hydraulic modeling of sewer networks, the minimum travel distance is a fundamental parameter that affects how accurately the model can si...