@speleotica/frcsdata 4.3.1 → 5.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/ParseIssue.d.ts +98 -0
  2. package/ParseIssue.d.ts.map +1 -0
  3. package/ParseIssue.js +17 -0
  4. package/ParseIssue.js.map +1 -0
  5. package/SourceLoc.d.ts +67 -0
  6. package/SourceLoc.d.ts.map +1 -0
  7. package/SourceLoc.js +18 -0
  8. package/SourceLoc.js.map +1 -0
  9. package/chunksToLines.d.ts +5 -0
  10. package/chunksToLines.d.ts.map +1 -0
  11. package/chunksToLines.js +37 -0
  12. package/chunksToLines.js.map +1 -0
  13. package/cli/check-survey-correspondence.d.ts +2 -0
  14. package/cli/check-survey-correspondence.d.ts.map +1 -0
  15. package/cli/check-survey-correspondence.js +44 -0
  16. package/cli/check-survey-correspondence.js.map +1 -0
  17. package/cli/check-survey.d.ts +2 -0
  18. package/cli/check-survey.d.ts.map +1 -0
  19. package/cli/check-survey.js +27 -0
  20. package/cli/check-survey.js.map +1 -0
  21. package/cli/parse-survey.d.ts +2 -0
  22. package/cli/parse-survey.d.ts.map +1 -0
  23. package/cli/parse-survey.js +15 -0
  24. package/cli/parse-survey.js.map +1 -0
  25. package/cli/summarize-survey.d.ts +2 -0
  26. package/cli/summarize-survey.d.ts.map +1 -0
  27. package/cli/summarize-survey.js +33 -0
  28. package/cli/summarize-survey.js.map +1 -0
  29. package/cli.d.ts +2 -0
  30. package/cli.d.ts.map +1 -0
  31. package/cli.js +72 -0
  32. package/cli.js.map +1 -0
  33. package/formatFrcsTripSummaryFile.d.ts +3 -0
  34. package/formatFrcsTripSummaryFile.d.ts.map +1 -0
  35. package/formatFrcsTripSummaryFile.js +33 -0
  36. package/formatFrcsTripSummaryFile.js.map +1 -0
  37. package/formatIssues.d.ts +10 -0
  38. package/formatIssues.d.ts.map +1 -0
  39. package/formatIssues.js +52 -0
  40. package/formatIssues.js.map +1 -0
  41. package/index.d.ts +5 -7
  42. package/index.d.ts.map +1 -1
  43. package/index.js +16 -49
  44. package/index.js.map +1 -1
  45. package/node/index.d.ts +4 -2
  46. package/node/index.d.ts.map +1 -1
  47. package/node/index.js +6 -12
  48. package/node/index.js.map +1 -1
  49. package/package.json +8 -6
  50. package/parseFrcsPlotFile.js +112 -245
  51. package/parseFrcsPlotFile.js.map +1 -1
  52. package/parseFrcsTripSummaryFile.d.ts +3 -1
  53. package/parseFrcsTripSummaryFile.d.ts.map +1 -1
  54. package/parseFrcsTripSummaryFile.js +53 -119
  55. package/parseFrcsTripSummaryFile.js.map +1 -1
  56. package/src/ParseIssue.ts +19 -0
  57. package/src/SourceLoc.ts +13 -0
  58. package/src/chunksToLines.ts +26 -0
  59. package/src/cli/check-survey-correspondence.ts +49 -0
  60. package/src/cli/check-survey.ts +23 -0
  61. package/src/cli/parse-survey.ts +10 -0
  62. package/src/cli/summarize-survey.ts +28 -0
  63. package/src/cli.ts +63 -0
  64. package/src/formatFrcsTripSummaryFile.ts +45 -0
  65. package/src/formatIssues.ts +97 -0
  66. package/src/index.ts +9 -7
  67. package/src/node/index.ts +18 -5
  68. package/src/parseFrcsTripSummaryFile.ts +8 -2
  69. package/src/string/index.ts +18 -5
  70. package/src/survey/FrcsSurveyFile.ts +217 -0
  71. package/src/survey/FrcsSurveyFileJson.ts +46 -0
  72. package/src/survey/ZodFrcsSurveyFileJson.ts +260 -0
  73. package/src/survey/ZodFrcsSurveyFileToJson.ts +297 -0
  74. package/src/{formatFrcsShot.ts → survey/formatFrcsShot.ts} +39 -22
  75. package/src/{formatFrcsSurveyFile.ts → survey/formatFrcsSurveyFile.ts} +4 -5
  76. package/src/survey/getColumnRanges.ts +82 -0
  77. package/src/survey/normalizeTeamMemberName.ts +7 -0
  78. package/src/survey/parseFrcsSurveyFile.ts +848 -0
  79. package/src/survey/parsers.ts +128 -0
  80. package/src/survey/summarizeSurvey.ts +51 -0
  81. package/src/survey/validators.ts +24 -0
  82. package/src/underlineSource.ts +34 -0
  83. package/src/unwrapInvalid.ts +3 -0
  84. package/src/web/index.ts +27 -21
  85. package/string/index.d.ts +4 -2
  86. package/string/index.d.ts.map +1 -1
  87. package/string/index.js +8 -34
  88. package/string/index.js.map +1 -1
  89. package/survey/FrcsSurveyFile.d.ts +172 -0
  90. package/survey/FrcsSurveyFile.d.ts.map +1 -0
  91. package/{FrcsSurveyFile.js → survey/FrcsSurveyFile.js} +3 -1
  92. package/survey/FrcsSurveyFile.js.map +1 -0
  93. package/survey/FrcsSurveyFileJson.d.ts +15 -0
  94. package/survey/FrcsSurveyFileJson.d.ts.map +1 -0
  95. package/{FrcsTrip.js → survey/FrcsSurveyFileJson.js} +1 -1
  96. package/survey/FrcsSurveyFileJson.js.map +1 -0
  97. package/survey/ZodFrcsSurveyFileJson.d.ts +60549 -0
  98. package/survey/ZodFrcsSurveyFileJson.d.ts.map +1 -0
  99. package/survey/ZodFrcsSurveyFileJson.js +186 -0
  100. package/survey/ZodFrcsSurveyFileJson.js.map +1 -0
  101. package/survey/ZodFrcsSurveyFileToJson.d.ts +60390 -0
  102. package/survey/ZodFrcsSurveyFileToJson.d.ts.map +1 -0
  103. package/survey/ZodFrcsSurveyFileToJson.js +209 -0
  104. package/survey/ZodFrcsSurveyFileToJson.js.map +1 -0
  105. package/{formatFrcsShot.d.ts → survey/formatFrcsShot.d.ts} +2 -3
  106. package/survey/formatFrcsShot.d.ts.map +1 -0
  107. package/survey/formatFrcsShot.js +107 -0
  108. package/survey/formatFrcsShot.js.map +1 -0
  109. package/survey/formatFrcsSurveyFile.d.ts +3 -0
  110. package/survey/formatFrcsSurveyFile.d.ts.map +1 -0
  111. package/survey/formatFrcsSurveyFile.js +87 -0
  112. package/survey/formatFrcsSurveyFile.js.map +1 -0
  113. package/survey/getColumnRanges.d.ts +24 -0
  114. package/survey/getColumnRanges.d.ts.map +1 -0
  115. package/survey/getColumnRanges.js +62 -0
  116. package/survey/getColumnRanges.js.map +1 -0
  117. package/survey/normalizeTeamMemberName.d.ts +2 -0
  118. package/survey/normalizeTeamMemberName.d.ts.map +1 -0
  119. package/survey/normalizeTeamMemberName.js +12 -0
  120. package/survey/normalizeTeamMemberName.js.map +1 -0
  121. package/{parseFrcsSurveyFile.d.ts → survey/parseFrcsSurveyFile.d.ts} +2 -5
  122. package/survey/parseFrcsSurveyFile.d.ts.map +1 -0
  123. package/survey/parseFrcsSurveyFile.js +626 -0
  124. package/survey/parseFrcsSurveyFile.js.map +1 -0
  125. package/survey/parsers.d.ts +11 -0
  126. package/survey/parsers.d.ts.map +1 -0
  127. package/survey/parsers.js +119 -0
  128. package/survey/parsers.js.map +1 -0
  129. package/survey/summarizeSurvey.d.ts +6 -0
  130. package/survey/summarizeSurvey.d.ts.map +1 -0
  131. package/survey/summarizeSurvey.js +58 -0
  132. package/survey/summarizeSurvey.js.map +1 -0
  133. package/survey/validators.d.ts +7 -0
  134. package/survey/validators.d.ts.map +1 -0
  135. package/survey/validators.js +36 -0
  136. package/survey/validators.js.map +1 -0
  137. package/underlineSource.d.ts +6 -0
  138. package/underlineSource.d.ts.map +1 -0
  139. package/underlineSource.js +22 -0
  140. package/underlineSource.js.map +1 -0
  141. package/unwrapInvalid.d.ts +4 -0
  142. package/unwrapInvalid.d.ts.map +1 -0
  143. package/unwrapInvalid.js +10 -0
  144. package/unwrapInvalid.js.map +1 -0
  145. package/web/index.d.ts +6 -6
  146. package/web/index.d.ts.map +1 -1
  147. package/web/index.js +60 -118
  148. package/web/index.js.map +1 -1
  149. package/FrcsShot.d.ts +0 -57
  150. package/FrcsShot.d.ts.map +0 -1
  151. package/FrcsShot.js +0 -13
  152. package/FrcsShot.js.map +0 -1
  153. package/FrcsSurveyFile.d.ts +0 -29
  154. package/FrcsSurveyFile.d.ts.map +0 -1
  155. package/FrcsSurveyFile.js.map +0 -1
  156. package/FrcsTrip.d.ts +0 -23
  157. package/FrcsTrip.d.ts.map +0 -1
  158. package/FrcsTrip.js.map +0 -1
  159. package/formatFrcsShot.d.ts.map +0 -1
  160. package/formatFrcsShot.js +0 -96
  161. package/formatFrcsShot.js.map +0 -1
  162. package/formatFrcsSurveyFile.d.ts +0 -3
  163. package/formatFrcsSurveyFile.d.ts.map +0 -1
  164. package/formatFrcsSurveyFile.js +0 -165
  165. package/formatFrcsSurveyFile.js.map +0 -1
  166. package/parseFrcsSurveyFile.d.ts.map +0 -1
  167. package/parseFrcsSurveyFile.js +0 -812
  168. package/parseFrcsSurveyFile.js.map +0 -1
  169. package/src/FrcsShot.ts +0 -56
  170. package/src/FrcsSurveyFile.ts +0 -47
  171. package/src/FrcsTrip.ts +0 -25
  172. package/src/parseFrcsSurveyFile.ts +0 -788
@@ -0,0 +1,626 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = parseFrcsSurveyFile;
7
+ var _FrcsSurveyFile = require("./FrcsSurveyFile.js");
8
+ var _unitized = require("@speleotica/unitized");
9
+ var _chunksToLines = require("../chunksToLines.js");
10
+ var _validators = require("./validators.js");
11
+ var _getColumnRanges = require("./getColumnRanges.js");
12
+ var _parsers = require("./parsers.js");
13
+ var _normalizeTeamMemberName = require("./normalizeTeamMemberName.js");
14
+ var _unwrapInvalid = require("../unwrapInvalid.js");
15
+ /**
16
+ * Parses a raw cdata.fr survey file. These look like so:
17
+ *
18
+ <pre> Fisher Ridge Cave System, Hart Co., KY
19
+ ENTRANCE DROPS, JOE'S "I LOVE MY WIFE TRAVERSE", TRICKY TRAVERSE
20
+ PETER QUICK, KEITH ORTIZ - 2-15-81
21
+ This File has Crumps test connected. 11/20/12
22
+ *
23
+ FT C DD A
24
+ AE20 0 1 3 0 2
25
+ * %FS
26
+ * AE20 0 0 0 Bug-can't put before so put after-so can't make 2 fixed 10/28/12
27
+ AE19 AE20 9.3 60.0 60.0-36.0 2 12 0 20
28
+ AE18 AE19 24.5 0.0 0.0-90.0 6 10 25 0
29
+ AE17 AE18 8.0 350.5 350.5 17.0 3 5 0 0
30
+ AE16 AE17 6.7 0.0 0.0-90.0 3 5 6 1
31
+ AE15 AE16 12.6 70.5 71.0-18.0 4 0 2 1
32
+ AE14 AE15 10.0 21.5 20.0 6.0 5 5 0 3
33
+ AE13 AE14 26.8 288.0 286.0-50.0 0 7 20 5
34
+ *
35
+ *SHORT CANYON AT THE BASE OF THE SECOND DROP
36
+ AE12 AE13 20.7 236.0 236.0 34.0 3 5 4 4
37
+ AE11 AE12 12.4 210.0 210.0 35.0 7 4 5 1
38
+ AE10 AE13 25.7 40.0 40.0 -9.0 2 2 3 6
39
+ *
40
+ *AE10 AT JOE'S " I LOVE MY WIFE TRAVERSE "
41
+ AE9 AE10 17.8 32.5 31.0 23.0 4 5 20 15
42
+ AE1 AE9 13.7 82.0 82.0-13.0
43
+ A1 AE1 34.3 46.0 48.0-17.5
44
+ *
45
+ *SURVEY TO DOME NEAR THE ENTRANCE DOME (ABOVE THE SECOND DROP)
46
+ AD1 AE15 8.0 200.0 200.0 0.0 3 1 1 1
47
+ AD2 AD1 17.7 161.0 161.0 7.0 1 4 25 1
48
+ AD3 AD2 10.4 180.0 180.0 50.0 4 1 15 5
49
+ *
50
+ TRICKY TRAVERSE AND THEN FIRST SURVEY IN UPPER CROWLWAY
51
+ DAN CROWL, KEITH ORTIZ, CHIP HOPPER, PETER QUICK, LARRY BEAN 14 FEB 1981
52
+ *
53
+ FI B DD
54
+ A2 A1 48 10 292.0 110.0-42.0 5 10 35 5
55
+ A3 A2 12 5 333.5 153.5 35.0 3 1 15 5
56
+ A4 A3 4 2 0.0 0.0 90.0 3 1 10 10
57
+ ...</pre>
58
+ *
59
+ */
60
+ async function parseFrcsSurveyFile(file,
61
+ // eslint-disable-line @typescript-eslint/no-explicit-any
62
+ chunks, {
63
+ columns = _FrcsSurveyFile.defaultFrcsShotColumnConfig,
64
+ outputColumns = false,
65
+ normalizeNames = true,
66
+ suppressWarnings
67
+ } = {}) {
68
+ const columnRanges = (0, _getColumnRanges.getColumnRanges)(columns);
69
+ const maxRange = Math.max(...Object.values(columnRanges.decimal).map(r => r[1]));
70
+ let cave = undefined;
71
+ let location = undefined;
72
+ const trips = [];
73
+ const issues = [];
74
+ let tripName;
75
+ let tripTeam;
76
+ let tripDate;
77
+ let inTripComment = true;
78
+ let tripCommentStartLine = 1;
79
+ let tripCommentEndLine = -1;
80
+ const tripComment = [];
81
+ const commentLines = [];
82
+ let trip = undefined;
83
+ let inBlockComment = false;
84
+ let section;
85
+ const commentFromStationLruds = new Map();
86
+ let unitsChanged = false;
87
+ let alternateUnits;
88
+ let nextShotUnits;
89
+ let lineNumber = 0;
90
+ let line;
91
+ let lineStartIndex = 0;
92
+ let lineIssues = [];
93
+ let tripIssues = [];
94
+ let began = false;
95
+ for await ({
96
+ line,
97
+ startIndex: lineStartIndex
98
+ } of (0, _chunksToLines.chunksToLines)(chunks)) {
99
+ if (lineIssues.length) lineIssues = [];
100
+ lineNumber++;
101
+ if (!began) {
102
+ began = true;
103
+ if (/^\s+\*/.test(line)) {
104
+ continue;
105
+ }
106
+ const match = /^\s*([^,]+)(,(.*))?/.exec(line);
107
+ if (match) {
108
+ cave = match[1].trim();
109
+ if (match[3]) {
110
+ location = match[3].trim();
111
+ }
112
+ }
113
+ }
114
+ if (unitsChanged) {
115
+ unitsChanged = false;
116
+ alternateUnits = parseUnits();
117
+ nextShotUnits = alternateUnits;
118
+ } else if (/^\s{1,8}\*(?!\*)/.test(line)) {
119
+ inTripComment = !inTripComment;
120
+ alternateUnits = nextShotUnits = undefined;
121
+ unitsChanged = false;
122
+ if (inTripComment) {
123
+ section = undefined;
124
+ tripTeam = undefined;
125
+ tripDate = undefined;
126
+ tripComment.length = 0;
127
+ tripCommentStartLine = lineNumber;
128
+ } else {
129
+ tripCommentEndLine = lineNumber;
130
+ }
131
+ } else if (inTripComment) {
132
+ if (lineNumber === tripCommentStartLine + 1) {
133
+ tripName = line && line.trim();
134
+ } else if (lineNumber === tripCommentStartLine + 2) {
135
+ const dateMatch = /(?:[-.]\s*)?((\d+)[-/](\d+)[-/](\d{2,4})|((\d+)[-/ ](january|february|march|april|may|june|july|august|september|october|november|december|(?:jan|feb|mar|apr|jun|jul|aug|sept?|oct|nov|dec)\.?)[-/ ](\d{2,4}))|((january|february|march|april|may|june|july|august|september|october|november|december|(?:jan|feb|mar|apr|jun|jul|aug|sept?|oct|nov|dec)\.?)\s+(\d+)(?:,\s*|,?\s+)(\d{2,4})))/i.exec(line);
136
+ if (dateMatch) {
137
+ const team = line.substring(0, dateMatch.index);
138
+ tripTeam = team.split(team.indexOf(';') >= 0 ? ';' : ',').flatMap(member => member.trim() || []);
139
+ if (!tripTeam.length) {
140
+ addIssue('warning', 'missingTripTeam', 'Missing team', 0, dateMatch.index, tripIssues);
141
+ }
142
+ if (normalizeNames) tripTeam = tripTeam.map(_normalizeTeamMemberName.normalizeTeamMemberName);
143
+ let month, day, year;
144
+ if (dateMatch[2]) {
145
+ month = parseInt(dateMatch[2]);
146
+ day = parseInt(dateMatch[3]);
147
+ year = parseInt(dateMatch[4]);
148
+ } else if (dateMatch[6]) {
149
+ day = parseInt(dateMatch[6]);
150
+ month = (0, _parsers.parseMonth)(dateMatch[7]);
151
+ year = parseInt(dateMatch[8]);
152
+ } else {
153
+ month = (0, _parsers.parseMonth)(dateMatch[10]);
154
+ day = parseInt(dateMatch[11]);
155
+ year = parseInt(dateMatch[12]);
156
+ }
157
+ tripDate = new Date(year < 60 ? year + 2000 : year, month - 1, day);
158
+ } else {
159
+ addIssue('warning', 'missingTripDate', 'Missing date', line.length, line.length, tripIssues);
160
+ }
161
+ } else if (lineNumber > 1) {
162
+ tripComment.push(line);
163
+ }
164
+ const match = /^\*\*\*([^*]+)\*\*\*/.exec(line);
165
+ if (match) {
166
+ section = match[1].trim();
167
+ }
168
+ } else if (/^(\s{9,}|)\*(?!\*)/.test(line)) {
169
+ if (/^\*\s*%NC(\b|$)/.test(line)) {
170
+ unitsChanged = true;
171
+ }
172
+ if (/^\*\s*%/.test(line)) {
173
+ continue;
174
+ }
175
+ if (/[^\s*]/.test(line)) {
176
+ addCommentLine(line.replace(/^\s*\*/, ''));
177
+ inBlockComment = false;
178
+ } else {
179
+ inBlockComment = !inBlockComment;
180
+ if (inBlockComment) commentLines.length = 0;
181
+ }
182
+ } else if (inBlockComment) {
183
+ addCommentLine(line);
184
+ } else if (lineNumber === tripCommentEndLine + 1) {
185
+ if (trip) trips.push(trip);
186
+ const header = {
187
+ name: tripName || '',
188
+ comment: tripComment && tripComment.join('\n') || undefined,
189
+ section,
190
+ date: tripDate,
191
+ team: tripTeam
192
+ };
193
+ const units = parseUnits();
194
+ if ('INVALID' in units || tripIssues.some(i => issues[i]?.type === 'error')) {
195
+ trip = {
196
+ INVALID: {
197
+ header,
198
+ units,
199
+ shots: []
200
+ },
201
+ ...(tripIssues.length ? {
202
+ issues: tripIssues
203
+ } : {})
204
+ };
205
+ } else {
206
+ trip = {
207
+ tripNumber: 1,
208
+ header,
209
+ units,
210
+ shots: []
211
+ };
212
+ }
213
+ tripIssues = [];
214
+ } else if (trip) {
215
+ let distanceUnit = (0, _unwrapInvalid.unwrapInvalid)(alternateUnits)?.distanceUnit || (0, _unwrapInvalid.unwrapInvalid)((0, _unwrapInvalid.unwrapInvalid)(trip).units).distanceUnit || _unitized.Length.feet;
216
+ const azimuthUnit = (0, _unwrapInvalid.unwrapInvalid)(alternateUnits)?.azimuthUnit || (0, _unwrapInvalid.unwrapInvalid)((0, _unwrapInvalid.unwrapInvalid)(trip).units).azimuthUnit || _unitized.Angle.degrees;
217
+ const inclinationUnit = (0, _unwrapInvalid.unwrapInvalid)(alternateUnits)?.inclinationUnit || (0, _unwrapInvalid.unwrapInvalid)((0, _unwrapInvalid.unwrapInvalid)(trip).units).inclinationUnit || _unitized.Angle.degrees;
218
+ const inches = distanceUnit === _unitized.Length.inches;
219
+ if (inches) distanceUnit = _unitized.Length.feet;
220
+ const ranges = inches ? columnRanges.feetAndInches : columnRanges.decimal;
221
+
222
+ // from station name
223
+ if (!/\S/.test(line.substring(...ranges.fromStation))) continue;
224
+ const fromStr = validate(...ranges.fromStation, 'from station', _validators.isValidStation);
225
+ const from = fromStr.trim();
226
+
227
+ // Sadly I have found negative LRUD values in Chip's format and apparently
228
+ // his program doesn't fail on them, so I have to accept them here
229
+ // isValidOptFloat instead of isValidOptUFloat
230
+ const lStr = validate(...ranges.left, 'left', _validators.isValidOptFloat);
231
+ const rStr = validate(...ranges.right, 'right', _validators.isValidOptFloat);
232
+ const uStr = validate(...ranges.up, 'up', _validators.isValidOptFloat);
233
+ const dStr = validate(...ranges.down, 'down', _validators.isValidOptFloat);
234
+ const up = (0, _parsers.parseLrud)(uStr, distanceUnit);
235
+ const down = (0, _parsers.parseLrud)(dStr, distanceUnit);
236
+ const left = (0, _parsers.parseLrud)(lStr, distanceUnit);
237
+ const right = (0, _parsers.parseLrud)(rStr, distanceUnit);
238
+
239
+ // to station name
240
+ const toStr = line.substring(...ranges.toStation);
241
+ if (!toStr.trim()) {
242
+ const shot = {
243
+ from,
244
+ to: undefined,
245
+ distance: new _unitized.UnitizedNumber(0, distanceUnit),
246
+ frontsightAzimuth: undefined,
247
+ backsightAzimuth: undefined,
248
+ frontsightInclination: undefined,
249
+ backsightInclination: undefined,
250
+ fromLruds: {
251
+ left,
252
+ right,
253
+ up,
254
+ down
255
+ },
256
+ excludeDistance: true,
257
+ comment: getComment()
258
+ };
259
+ addShot(lineIssues.length ? {
260
+ INVALID: shot,
261
+ issues: lineIssues
262
+ } : shot);
263
+ continue;
264
+ }
265
+ if (!(0, _validators.isValidStation)(toStr)) {
266
+ addIssue('error', 'invalidStationName', 'Invalid station name', ...ranges.toStation);
267
+ }
268
+ let fromLruds = commentFromStationLruds.get(from);
269
+ if (fromLruds) {
270
+ commentFromStationLruds.delete(from);
271
+ } else {
272
+ const fromLrudMatch = new RegExp(`^\\s+${fromStr.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}((\\s+(\\d+(\\.\\d*)?|\\.\\d+)){4})`).exec(line.substring(maxRange));
273
+ if (fromLrudMatch) {
274
+ const [left, right, up, down] = fromLrudMatch[1].trim().split(/\s+/g).map(s => (0, _parsers.parseLrud)(s, distanceUnit));
275
+ fromLruds = {
276
+ left,
277
+ right,
278
+ up,
279
+ down
280
+ };
281
+ }
282
+ }
283
+ const comment = getComment();
284
+
285
+ // azimuth and inclination
286
+ const azmFsStr = validate(ranges.frontsightAzimuth[0], ranges.frontsightAzimuth[1], 'azimuth', _validators.isValidOptUFloat);
287
+ const azmBsStr = validate(...ranges.backsightAzimuth, 'azimuth', _validators.isValidOptUFloat);
288
+ const incFsStr = line.substring(...ranges.frontsightInclination);
289
+ const incBsStr = line.substring(...ranges.backsightInclination);
290
+ let distance;
291
+ let horizontalDistance;
292
+ let verticalDistance;
293
+ let frontsightInclination;
294
+ let backsightInclination;
295
+
296
+ // parse distance
297
+ if (inches) {
298
+ const feetStr = validate(...ranges.distanceFeet, 'feet', _validators.isValidOptUFloat);
299
+ const inchesStr = validate(...ranges.distanceInches, 'inches', _validators.isValidOptUFloat);
300
+ if (!/\S/.test(feetStr) && !/\S/.test(inchesStr)) {
301
+ addIssue('error', 'missingDistance', 'Missing distance', ranges.distanceFeet[0], ranges.distanceInches[1]);
302
+ }
303
+ // sometimes inches are omitted, hence the || 0...I'm assuming it's possible
304
+ // for feet to be omitted as well
305
+ else if ((0, _validators.isValidUInt)(feetStr) && (0, _validators.isValidOptUFloat)(inchesStr) || (0, _validators.isValidOptUFloat)(feetStr) && (0, _validators.isValidUInt)(inchesStr)) {
306
+ distance = _unitized.Unitize.inches(parseFloat(inchesStr) || 0).add(_unitized.Unitize.feet(parseFloat(feetStr) || 0));
307
+ }
308
+ // NOTE there are two columns around here that can contain a *.
309
+ // I think they might represent different values, but thisis confused by
310
+ // the fact that for ft/in shots, if there is a D or H flag it occupies the
311
+ // first column that can contain a * for decimal feet shots
312
+ } else {
313
+ const distStr = validate(...ranges.distance, 'distance', _validators.isValidUFloat);
314
+ const distNum = parseFloat(distStr);
315
+ distance = Number.isFinite(distNum) ? new _unitized.UnitizedNumber(distNum, distanceUnit) : undefined;
316
+ }
317
+ const specialKindStr = line.substring(...ranges.kind).trim();
318
+ const exclude = line.substring(...ranges.exclude).trim();
319
+ const specialKind = (0, _parsers.parseSpecialKind)(specialKindStr);
320
+ if (specialKindStr && !specialKind) {
321
+ addIssue('error', 'invalidShotType', 'Invalid shot type', ranges.kind[0], ranges.kind[1]);
322
+ }
323
+ const excludeDistance = exclude === '*' || exclude === 's';
324
+ const isSplay = exclude === 's';
325
+ if (exclude && !excludeDistance) {
326
+ addIssue('error', 'invalidShotFlag', 'Invalid shot flag', ranges.exclude[0], ranges.exclude[1]);
327
+ }
328
+ if (specialKind) {
329
+ validate(...ranges.frontsightInclination, 'vertical-distance', _validators.isValidFloat);
330
+ }
331
+
332
+ // convert horizontal and diagonal shots to standard
333
+ // in this case incFs is the vertical offset between stations
334
+ // fortunately it appears we can always count on incFs being specified
335
+ // and incBs not being specified for these types of shots
336
+ if (specialKind === 'horizontal') {
337
+ // distance is horizontal offset and incFsStr is vertical offset
338
+ horizontalDistance = distance;
339
+ const h = horizontalDistance?.get(distanceUnit) ?? NaN;
340
+ const v = parseFloat(incFsStr);
341
+ verticalDistance = Number.isFinite(v) ? new _unitized.UnitizedNumber(v, distanceUnit) : undefined;
342
+ distance = new _unitized.UnitizedNumber(Math.sqrt(h * h + v * v), distanceUnit);
343
+ frontsightInclination = verticalDistance && horizontalDistance ? _unitized.Angle.atan2(verticalDistance, horizontalDistance).in(inclinationUnit) : undefined;
344
+ backsightInclination = undefined;
345
+ } else if (specialKind === 'diagonal') {
346
+ // distance is as usual, but incFsStr is vertical offset
347
+ const d = distance?.get(distanceUnit) ?? NaN;
348
+ const v = parseFloat(incFsStr);
349
+ verticalDistance = Number.isFinite(v) ? new _unitized.UnitizedNumber(v, distanceUnit) : undefined;
350
+ frontsightInclination = _unitized.Angle.asin(v / d).in(inclinationUnit);
351
+ backsightInclination = undefined;
352
+ } else {
353
+ // frontsight inclination
354
+ validate(...ranges.frontsightInclination, 'inclination', _validators.isValidOptFloat);
355
+ // backsight inclination
356
+ validate(...ranges.backsightInclination, 'inclination', _validators.isValidOptFloat);
357
+ frontsightInclination = (0, _parsers.parseNumber)(incFsStr, inclinationUnit);
358
+ backsightInclination = (0, _parsers.parseNumber)(incBsStr, inclinationUnit);
359
+ }
360
+ const frontsightAzimuth = (0, _parsers.parseAzimuth)(azmFsStr, azimuthUnit);
361
+ const backsightAzimuth = (0, _parsers.parseAzimuth)(azmBsStr, azimuthUnit);
362
+ if (!/\S/.test(incFsStr) && !/\S/.test(incBsStr)) {
363
+ frontsightInclination = _unitized.Unitize.degrees(0);
364
+ }
365
+ if (from && distance && !lineIssues.length) {
366
+ const shot = {
367
+ from,
368
+ to: toStr.trim(),
369
+ specialKind,
370
+ distance,
371
+ frontsightAzimuth,
372
+ backsightAzimuth,
373
+ frontsightInclination,
374
+ backsightInclination,
375
+ toLruds: {
376
+ left,
377
+ right,
378
+ up,
379
+ down
380
+ },
381
+ excludeDistance,
382
+ comment
383
+ };
384
+ if (isSplay) shot.isSplay = true;
385
+ if (fromLruds) shot.fromLruds = fromLruds;
386
+ if (horizontalDistance) shot.horizontalDistance = horizontalDistance;
387
+ if (verticalDistance) shot.verticalDistance = verticalDistance;
388
+ addShot(shot);
389
+ } else {
390
+ const shot = {
391
+ from,
392
+ to: toStr.trim(),
393
+ specialKind,
394
+ distance,
395
+ frontsightAzimuth,
396
+ backsightAzimuth,
397
+ frontsightInclination,
398
+ backsightInclination,
399
+ toLruds: {
400
+ left,
401
+ right,
402
+ up,
403
+ down
404
+ },
405
+ excludeDistance,
406
+ comment
407
+ };
408
+ if (isSplay) shot.isSplay = true;
409
+ if (fromLruds) shot.fromLruds = fromLruds;
410
+ if (horizontalDistance) shot.horizontalDistance = horizontalDistance;
411
+ if (verticalDistance) shot.verticalDistance = verticalDistance;
412
+ addShot({
413
+ INVALID: shot,
414
+ issues: lineIssues
415
+ });
416
+ }
417
+ }
418
+ }
419
+ if (trip) trips.push(trip);
420
+ trips.forEach((trip, index) => (0, _unwrapInvalid.unwrapInvalid)(trip).tripNumber = index + 1);
421
+ if (!issues.some(i => i.type === 'error') && trips.every(t => !('INVALID' in t))) {
422
+ return {
423
+ cave,
424
+ columns: outputColumns ? columns : undefined,
425
+ location,
426
+ trips,
427
+ ...(issues.length ? {
428
+ issues
429
+ } : undefined)
430
+ };
431
+ }
432
+ return {
433
+ INVALID: {
434
+ cave,
435
+ columns: outputColumns ? columns : undefined,
436
+ location,
437
+ trips
438
+ },
439
+ issues
440
+ };
441
+
442
+ ////////////////////////////////////////////////////////////////////////////////////////////
443
+
444
+ function getComment() {
445
+ if (!commentLines?.length) return undefined;
446
+ const comment = commentLines.join('\n').trim();
447
+ commentLines.length = 0;
448
+ return comment || undefined;
449
+ }
450
+ function addCommentLine(comment) {
451
+ if (trip) {
452
+ const distanceUnit = (0, _unwrapInvalid.unwrapInvalid)(alternateUnits)?.distanceUnit || (0, _unwrapInvalid.unwrapInvalid)((0, _unwrapInvalid.unwrapInvalid)(trip).units).distanceUnit || _unitized.Length.feet;
453
+ const parsedFromStationLruds = (0, _parsers.parseFromStationLruds)(comment, distanceUnit);
454
+ if (parsedFromStationLruds) {
455
+ commentFromStationLruds.set(parsedFromStationLruds[0], parsedFromStationLruds[1]);
456
+ return;
457
+ }
458
+ }
459
+ if (commentLines) {
460
+ commentLines.push(comment);
461
+ }
462
+ }
463
+ function addIssue(type, code, message, startColumn, endColumn, indicesArray) {
464
+ if (suppressWarnings && type === 'warning' && (suppressWarnings === true || 'code' in suppressWarnings && suppressWarnings[code] === true)) {
465
+ return;
466
+ }
467
+ issues.push({
468
+ type,
469
+ code,
470
+ message,
471
+ loc: {
472
+ start: {
473
+ line: lineNumber,
474
+ column: startColumn,
475
+ index: lineStartIndex + startColumn
476
+ },
477
+ end: {
478
+ line: lineNumber,
479
+ column: endColumn,
480
+ index: lineStartIndex + endColumn
481
+ }
482
+ }
483
+ });
484
+ if (!lineIssues) lineIssues = [];
485
+ lineIssues.push(issues.length - 1);
486
+ indicesArray?.push(issues.length - 1);
487
+ }
488
+ function parseUnits() {
489
+ // FT CC DD
490
+ // 01234567
491
+ const distanceUnit = (0, _parsers.parseLengthUnit)(line.slice(0, 2));
492
+ if (!distanceUnit) {
493
+ addIssue('error', 'invalidDistanceUnit', 'Invalid distance unit', 0, 2);
494
+ }
495
+ const azimuthUnit = (0, _parsers.parseAngleUnit)(line[6]);
496
+ if (!azimuthUnit) {
497
+ addIssue('error', 'invalidAzimuthUnit', 'Invalid azimuth unit', 6, 7);
498
+ }
499
+ const inclinationUnit = (0, _parsers.parseAngleUnit)(line[7]);
500
+ if (!inclinationUnit) {
501
+ addIssue('error', 'invalidInclinationUnit', 'Invalid inclination unit', 7, 8);
502
+ }
503
+ const backsightAzimuthCorrected = line[3] === 'C';
504
+ const backsightInclinationCorrected = line[4] === 'C';
505
+ const hasBacksightAzimuth = line[3] !== ' ' && line[3] !== '-';
506
+ const hasBacksightInclination = line[4] !== ' ' && line[4] !== '-';
507
+ if (!/[-CB ]/.test(line[3])) {
508
+ addIssue('error', 'invalidBacksightAzimuthType', 'Invalid backsight azimuth type', 3, 4);
509
+ }
510
+ if (!/[-CB ]/.test(line[4])) {
511
+ addIssue('error', 'invalidBacksightInclinationType', 'Invalid backsight inclination type', 4, 5);
512
+ }
513
+ if (!distanceUnit || !azimuthUnit || !inclinationUnit) {
514
+ return {
515
+ INVALID: {
516
+ distanceUnit,
517
+ azimuthUnit,
518
+ inclinationUnit,
519
+ backsightAzimuthCorrected,
520
+ backsightInclinationCorrected,
521
+ hasBacksightAzimuth,
522
+ hasBacksightInclination
523
+ },
524
+ issues: lineIssues
525
+ };
526
+ }
527
+ return {
528
+ distanceUnit,
529
+ azimuthUnit,
530
+ inclinationUnit,
531
+ backsightAzimuthCorrected,
532
+ backsightInclinationCorrected,
533
+ hasBacksightAzimuth,
534
+ hasBacksightInclination
535
+ };
536
+ }
537
+ function validate(startColumn, endColumn, fieldName, validator) {
538
+ const field = line.substring(startColumn, endColumn);
539
+ if (!validator(field)) {
540
+ addIssue('error', `${field.trim() ? 'invalid' : 'missing'}${fieldName[0].toUpperCase()}${fieldName.substring(1)}`, (field.trim() ? 'Invalid ' : 'Missing ') + fieldName, startColumn, endColumn);
541
+ }
542
+ return field;
543
+ }
544
+ function addShot(shot) {
545
+ if (!trip) return;
546
+ if (alternateUnits) {
547
+ const recorded = shot;
548
+ if ('INVALID' in shot) {
549
+ shot.INVALID = {
550
+ ...shot.INVALID,
551
+ recorded
552
+ };
553
+ } else if ('INVALID' in recorded) {
554
+ shot = {
555
+ INVALID: {
556
+ ...shot,
557
+ recorded
558
+ }
559
+ };
560
+ } else {
561
+ shot = {
562
+ ...shot,
563
+ recorded
564
+ };
565
+ }
566
+ if (nextShotUnits) {
567
+ (0, _unwrapInvalid.unwrapInvalid)(recorded).units = nextShotUnits;
568
+ nextShotUnits = undefined;
569
+ }
570
+ const {
571
+ backsightAzimuthCorrected,
572
+ backsightInclinationCorrected,
573
+ distanceUnit,
574
+ azimuthUnit,
575
+ inclinationUnit
576
+ } = (0, _unwrapInvalid.unwrapInvalid)((0, _unwrapInvalid.unwrapInvalid)(trip).units);
577
+ const unwrappedAlternateUnits = (0, _unwrapInvalid.unwrapInvalid)(alternateUnits);
578
+ const unwrappedShot = (0, _unwrapInvalid.unwrapInvalid)(shot);
579
+ {
580
+ const alternateUnits = unwrappedAlternateUnits;
581
+ const shot = unwrappedShot;
582
+ if (alternateUnits.backsightAzimuthCorrected !== backsightAzimuthCorrected) {
583
+ shot.backsightAzimuth = shot.backsightAzimuth ? _unitized.Angle.opposite(shot.backsightAzimuth) : undefined;
584
+ }
585
+ if (alternateUnits.backsightInclinationCorrected !== backsightInclinationCorrected) {
586
+ shot.backsightInclination = shot.backsightInclination?.negate();
587
+ }
588
+ if (distanceUnit && distanceUnit !== alternateUnits.distanceUnit) {
589
+ shot.distance = shot.distance?.in(distanceUnit);
590
+ if (shot.fromLruds) {
591
+ shot.fromLruds.left = shot.fromLruds.left?.in(distanceUnit);
592
+ shot.fromLruds.right = shot.fromLruds.right?.in(distanceUnit);
593
+ shot.fromLruds.up = shot.fromLruds.up?.in(distanceUnit);
594
+ shot.fromLruds.down = shot.fromLruds.down?.in(distanceUnit);
595
+ }
596
+ if (shot.toLruds) {
597
+ shot.toLruds.left = shot.toLruds.left?.in(distanceUnit);
598
+ shot.toLruds.right = shot.toLruds.right?.in(distanceUnit);
599
+ shot.toLruds.up = shot.toLruds.up?.in(distanceUnit);
600
+ shot.toLruds.down = shot.toLruds.down?.in(distanceUnit);
601
+ }
602
+ }
603
+ if (azimuthUnit && azimuthUnit !== alternateUnits.azimuthUnit) {
604
+ shot.frontsightAzimuth = shot.frontsightAzimuth?.in(azimuthUnit);
605
+ shot.backsightAzimuth = shot.backsightAzimuth?.in(azimuthUnit);
606
+ }
607
+ if (inclinationUnit && inclinationUnit !== alternateUnits.inclinationUnit) {
608
+ shot.frontsightInclination = shot.frontsightInclination?.in(inclinationUnit);
609
+ shot.backsightInclination = shot.backsightInclination?.in(inclinationUnit);
610
+ }
611
+ }
612
+ }
613
+ if ('INVALID' in trip) {
614
+ trip.INVALID.shots.push(shot);
615
+ } else if ('INVALID' in shot) {
616
+ trip = {
617
+ INVALID: trip
618
+ };
619
+ trip.INVALID.shots.push(shot);
620
+ } else {
621
+ trip.shots.push(shot);
622
+ }
623
+ }
624
+ }
625
+ module.exports = exports.default;
626
+ //# sourceMappingURL=parseFrcsSurveyFile.js.map