Skip to content

Commit 839f3fa

Browse files
committed
unit string updates
1 parent ffa0f6d commit 839f3fa

File tree

3 files changed

+183
-47
lines changed

3 files changed

+183
-47
lines changed

src/SwmmOut.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
// SwmmOut.ts
22

3+
import { outputDataUnitsWords } from "./WordsnKeys"
4+
5+
6+
interface ResultsSets {
7+
[objectType: string]: ResultsType;
8+
}
9+
10+
interface ResultsType {
11+
[resultsType: number]: string;
12+
}
13+
314
/**
415
* Class for storing and working with .out file contents.
516
* This class expects a standard ArrayBuffer type, which
@@ -655,7 +666,7 @@ static SUBCATCHMENT_RESULTS = [
655666
* @type {Array}
656667
* Description strings structure for node results.
657668
*/
658-
static NODE_RESULTS = [
669+
static NODE_RESULTS: Array<string> = [
659670
"Depth", "Head", "Volume", "Lat. Flow", "Inflow", "Overflow"//, "Quality"
660671
]
661672

@@ -675,6 +686,28 @@ static SYS_RESULTS = [
675686
"Temperature", "Rainfall", "Snow Depth", "Infil", "Runoff", "DW Flow", "GW Flow", "RDII", "External Inflow", "Lateral Inflow", "Flooding", "Outflow", "Storage", "Evap", "Potential ET"
676687
]
677688

689+
/**
690+
* @type {Array}
691+
* Description strings structure for subcatchment results.
692+
* Should replace SUBCATCHMENT_RESULTS, NODE_RESULTS, LINK_RESULTS, SYS_RESULTS
693+
* because those systems are easier to access with string identifiers if given a base
694+
* object for SwmmOut to reference, like 'RESULTS'.
695+
*/
696+
static RESULTS: ResultsSets = {
697+
SUBCATCHMENT_RESULTS : [
698+
"Rainfall", "Snow Depth", "Evap", "Infiltration", "Runoff", "GW Flow", "GW Elev", "Soil Moisture"//, "Washoff"
699+
],
700+
NODE_RESULTS: [
701+
"Depth", "Head", "Volume", "Lat. Flow", "Inflow", "Overflow"//, "Quality"
702+
],
703+
LINK_RESULTS: [
704+
"Flow", "Depth", "Velocity", "Volume", "Capacity"//, "Quality"
705+
],
706+
SYS_RESULTS: [
707+
"Temperature", "Rainfall", "Snow Depth", "Infil", "Runoff", "DW Flow", "GW Flow", "RDII", "External Inflow", "Lateral Inflow", "Flooding", "Outflow", "Storage", "Evap", "Potential ET"
708+
]
709+
}
710+
678711
/**
679712
* @type {Array}
680713
* Strings structure for pollutant concentrations.
@@ -723,7 +756,7 @@ version(): number{
723756
/**
724757
* Returns the object's first magic number.
725758
*
726-
* @returns {number} Integer. Flow unit code.
759+
* @returns {number} Integer. Magic number.
727760
*/
728761
magic1(): number{
729762
return this.readInt(0)
@@ -836,6 +869,36 @@ magic2(): number{
836869
return this.readInt(this.value.byteLength - SwmmOut.RECORD_SIZE * 1)
837870
}
838871

872+
////////////////////////////////////////////////////////////////////////////////////////
873+
// Unit strings for charts and displays.
874+
////////////////////////////////////////////////////////////////////////////////////////
875+
876+
/**
877+
* Returns a unit string for a given data value ('Volume, cf', or 'Area, m^2').
878+
*
879+
* @param {string} objectType Type of an object, e.g.: 'NODE_RESULTS'
880+
* @param {number} resultIndex Index of a result from e.g.: NODE_RESULTS[]
881+
* @returns {string} subcatchment's name.
882+
*/
883+
unitString(objectType:string, resultIndex:number): string {
884+
// First, get the flowUnitCode, which is an integer that represents CMS, GPM, GPD, etc.
885+
let flowUnits = this.flowUnitCode()
886+
let unitSystem = 'US'
887+
// The flowUnits lets us determine the unit system, 'US' or 'SI'.
888+
if ( flowUnits <= SwmmOut.FLOW_UNIT_VALUES.indexOf("MGD")){
889+
unitSystem = 'US'
890+
}
891+
else {
892+
unitSystem = 'SI'
893+
}
894+
895+
let descriptionStrings = SwmmOut.RESULTS[objectType][resultIndex]
896+
let outString = descriptionStrings +
897+
' ' +
898+
outputDataUnitsWords[objectType][resultIndex][unitSystem](flowUnits)
899+
return outString
900+
}
901+
839902
////////////////////////////////////////////////////////////////////////////////////////
840903
// Object IDs (names) & pollutant concentration units
841904
////////////////////////////////////////////////////////////////////////////////////////

src/WordsnKeys.ts

Lines changed: 114 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -107,55 +107,124 @@ export const outputDataWords = {
107107
// Despite this being the only property of a pollut, it should still
108108
// be an array to match the object structure of links, nodes, and areas.
109109
//
110-
export const outputDataUnitsWords = {
111-
SUBCATCH: [
112-
{ US: ()=>'in/hr', SI: ()=>'mm/hr' },
113-
{ US: ()=>'inches', SI: ()=>'mm' },
114-
{ US: ()=>'in/day', SI: ()=>'mm/day' },
115-
{ US: ()=>'in/hr', SI: ()=>'mm/hr' },
116-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
117-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
118-
{ US: ()=>'feet', SI: ()=>'meters' },
119-
{ US: ()=>'unitless', SI: ()=>'unitless' },
120-
{ US: (d:number)=>{return QualUnitsWords[d]}, SI: (d:number)=>{return QualUnitsWords[d]} }
110+
interface OutputDataUnit {
111+
[resultType: string]: OutputDataUnitFunction;
112+
}
113+
114+
interface OutputDataUnitFunction {
115+
(d: number): string;
116+
}
117+
118+
interface OutputDataUnitType {
119+
[unitSystem: number]: OutputDataUnit;
120+
}
121+
122+
interface OutputDataUnitsWords {
123+
[objectType: string]: OutputDataUnitType;
124+
}
125+
126+
127+
export const outputDataUnitsWords: OutputDataUnitsWords = {
128+
'SUBCATCH': [
129+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
130+
{ 'US': ()=>'inches', 'SI': ()=>'mm' },
131+
{ 'US': ()=>'in/day', 'SI': ()=>'mm/day' },
132+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
133+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
134+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
135+
{ 'US': ()=>'feet', 'SI': ()=>'meters' },
136+
{ 'US': ()=>'unitless', 'SI': ()=>'unitless' },
137+
{ 'US': (d)=>{return QualUnitsWords[d]}, 'SI': (d)=>{return QualUnitsWords[d]} }
138+
],
139+
'NODE': [
140+
{ 'US': ()=>'feet', 'SI': ()=>'meters' },
141+
{ 'US': ()=>'feet', 'SI':()=> 'meters' },
142+
{ 'US': ()=>'ft^3', 'SI': ()=>'m^3' },
143+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
144+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
145+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} }
146+
],
147+
'LINK': [
148+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
149+
{ 'US': ()=>'feet', 'SI': ()=>'meters' },
150+
{ 'US': ()=>'ft/s', 'SI': ()=>'m/s' },
151+
{ 'US': ()=>'ft^3', 'SI': ()=>'m^3' },
152+
{ 'US': ()=>'unitless', 'SI': ()=>'unitless' },
153+
{ 'US': (d)=>{return QualUnitsWords[d]}, 'SI': (d)=>{return QualUnitsWords[d]} }
154+
],
155+
'SYS': [
156+
{ 'US': ()=>'F', 'SI': ()=>'C' },
157+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
158+
{ 'US': ()=>'inches', 'SI': ()=>'mm' },
159+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
160+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
161+
162+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
163+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
164+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
165+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
166+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
167+
168+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
169+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
170+
{ 'US': ()=>'ft^3', 'SI': ()=>'m^3' },
171+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
172+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' }
121173
],
122-
NODE: [
123-
{ US: ()=>'feet', SI: ()=>'meters' },
124-
{ US: ()=>'feet', SI:()=> 'meters' },
125-
{ US: ()=>'ft^3', SI: ()=>'m^3' },
126-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
127-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
128-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} }
174+
///////////////////////////////////////////////////////////////////////////////////
175+
// The previous unit return functions are being deprecated to reduce the number
176+
// of calling strings. The following are intended to replace the previous functions:
177+
////////////////////////////////////////////////////////////////////////////////////
178+
'SUBCATCHMENT_RESULTS': [
179+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
180+
{ 'US': ()=>'inches', 'SI': ()=>'mm' },
181+
{ 'US': ()=>'in/day', 'SI': ()=>'mm/day' },
182+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
183+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
184+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
185+
{ 'US': ()=>'feet', 'SI': ()=>'meters' },
186+
{ 'US': ()=>'unitless', 'SI': ()=>'unitless' },
187+
{ 'US': (d)=>{return QualUnitsWords[d]}, 'SI': (d)=>{return QualUnitsWords[d]} }
129188
],
130-
LINK: [
131-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
132-
{ US: ()=>'feet', SI: ()=>'meters' },
133-
{ US: ()=>'ft/s', SI: ()=>'m/s' },
134-
{ US: ()=>'ft^3', SI: ()=>'m^3' },
135-
{ US: ()=>'unitless', SI: ()=>'unitless' },
136-
{ US: (d:number)=>{return QualUnitsWords[d]}, SI: (d:number)=>{return QualUnitsWords[d]} }
189+
'NODE_RESULTS': [
190+
{ 'US': ()=>'feet', 'SI': ()=>'meters' },
191+
{ 'US': ()=>'feet', 'SI':()=> 'meters' },
192+
{ 'US': ()=>'ft^3', 'SI': ()=>'m^3' },
193+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
194+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
195+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} }
196+
],
197+
'LINK_RESULTS': [
198+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
199+
{ 'US': ()=>'feet', 'SI': ()=>'meters' },
200+
{ 'US': ()=>'ft/s', 'SI': ()=>'m/s' },
201+
{ 'US': ()=>'ft^3', 'SI': ()=>'m^3' },
202+
{ 'US': ()=>'unitless', 'SI': ()=>'unitless' },
203+
{ 'US': (d)=>{return QualUnitsWords[d]}, 'SI': (d)=>{return QualUnitsWords[d]} }
204+
],
205+
'SYS_RESULTS': [
206+
{ 'US': ()=>'F', 'SI': ()=>'C' },
207+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
208+
{ 'US': ()=>'inches', 'SI': ()=>'mm' },
209+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
210+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
211+
212+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
213+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
214+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
215+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
216+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
217+
218+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
219+
{ 'US': (d)=>{return FlowUnitWords[d]}, 'SI': (d)=>{return FlowUnitWords[d]} },
220+
{ 'US': ()=>'ft^3', 'SI': ()=>'m^3' },
221+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' },
222+
{ 'US': ()=>'in/hr', 'SI': ()=>'mm/hr' }
137223
],
138-
SYS: [
139-
{ US: ()=>'F', SI: ()=>'C' },
140-
{ US: ()=>'in/hr', SI: ()=>'mm/hr' },
141-
{ US: ()=>'inches', SI: ()=>'mm' },
142-
{ US: ()=>'in/hr', SI: ()=>'mm/hr' },
143-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
144-
145-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
146-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
147-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
148-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
149-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
150-
151-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
152-
{ US: (d:number)=>{return FlowUnitWords[d]}, SI: (d:number)=>{return FlowUnitWords[d]} },
153-
{ US: ()=>'ft^3', SI: ()=>'m^3' },
154-
{ US: ()=>'in/hr', SI: ()=>'mm/hr' },
155-
{ US: ()=>'in/hr', SI: ()=>'mm/hr' }
156-
]
157224
}
158225

226+
227+
159228
// Analysis Option Keywords
160229
var w_FLOW_UNITS = "FLOW_UNITS"
161230
var w_INFIL_MODEL = "INFILTRATION"
@@ -608,7 +677,7 @@ export const EvapTypeWords = [ w_CONSTANT, w_MONTHLY, w_TIMESERIES,
608677
export const FileTypeWords = [ w_RAINFALL, w_RUNOFF, w_HOTSTART, w_RDII,
609678
w_INFLOWS, w_OUTFLOWS, '']
610679
export const FileModeWords = [ w_NO, w_SCRATCH, w_USE, w_SAVE, '']
611-
export const FlowUnitWords = [ w_CFS, w_GPM, w_MGD, w_CMS, w_LPS, w_MLD, '']
680+
export const FlowUnitWords: string[] = [ w_CFS, w_GPM, w_MGD, w_CMS, w_LPS, w_MLD, '']
612681
export const ForceMainEqnWords = [ w_H_W, w_D_W, '']
613682
export const GageDataWords = [ w_TIMESERIES, w_FILE, '']
614683
export const InfilModelWords = [ w_HORTON, w_MOD_HORTON, w_GREEN_AMPT,

test/SwmmOut.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ test('flowUnitCode', () =>{
3232
expect((global as any).example1.flowUnitCode()).toBe(0)
3333
})
3434

35+
test('unitString', () =>{
36+
expect((global as any).example1.unitString('LINK_RESULTS', 2)).toBe(0)
37+
})
38+
3539
/*test('subcatchmentCount', () =>{
3640
expect((global as any).example1.subcatchmentCount()).toBe(8)
3741
})*/

0 commit comments

Comments
 (0)