@speleotica/frcsdata 4.3.0 → 4.3.1

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 (81) hide show
  1. package/FrcsPlotFile.d.ts +1 -0
  2. package/FrcsPlotFile.d.ts.map +1 -0
  3. package/FrcsPlotFile.js +2 -1
  4. package/FrcsPlotFile.js.map +1 -0
  5. package/FrcsPlotShot.d.ts +1 -0
  6. package/FrcsPlotShot.d.ts.map +1 -0
  7. package/FrcsPlotShot.js +2 -1
  8. package/FrcsPlotShot.js.map +1 -0
  9. package/FrcsShot.d.ts +1 -0
  10. package/FrcsShot.d.ts.map +1 -0
  11. package/FrcsShot.js +2 -1
  12. package/FrcsShot.js.map +1 -0
  13. package/FrcsSurveyFile.d.ts +1 -0
  14. package/FrcsSurveyFile.d.ts.map +1 -0
  15. package/FrcsSurveyFile.js +2 -1
  16. package/FrcsSurveyFile.js.map +1 -0
  17. package/FrcsTrip.d.ts +1 -0
  18. package/FrcsTrip.d.ts.map +1 -0
  19. package/FrcsTrip.js +2 -1
  20. package/FrcsTrip.js.map +1 -0
  21. package/FrcsTripSummary.d.ts +1 -0
  22. package/FrcsTripSummary.d.ts.map +1 -0
  23. package/FrcsTripSummary.js +2 -1
  24. package/FrcsTripSummary.js.map +1 -0
  25. package/FrcsTripSummaryFile.d.ts +1 -0
  26. package/FrcsTripSummaryFile.d.ts.map +1 -0
  27. package/FrcsTripSummaryFile.js +2 -1
  28. package/FrcsTripSummaryFile.js.map +1 -0
  29. package/formatFrcsShot.d.ts +1 -0
  30. package/formatFrcsShot.d.ts.map +1 -0
  31. package/formatFrcsShot.js +5 -5
  32. package/formatFrcsShot.js.map +1 -0
  33. package/formatFrcsSurveyFile.d.ts +1 -0
  34. package/formatFrcsSurveyFile.d.ts.map +1 -0
  35. package/formatFrcsSurveyFile.js +2 -1
  36. package/formatFrcsSurveyFile.js.map +1 -0
  37. package/index.d.ts +1 -0
  38. package/index.d.ts.map +1 -0
  39. package/index.js +2 -1
  40. package/index.js.map +1 -0
  41. package/node/index.d.ts +1 -0
  42. package/node/index.d.ts.map +1 -0
  43. package/node/index.js +2 -1
  44. package/node/index.js.map +1 -0
  45. package/package.json +5 -2
  46. package/parseFrcsPlotFile.d.ts +1 -0
  47. package/parseFrcsPlotFile.d.ts.map +1 -0
  48. package/parseFrcsPlotFile.js +2 -1
  49. package/parseFrcsPlotFile.js.map +1 -0
  50. package/parseFrcsSurveyFile.d.ts +1 -0
  51. package/parseFrcsSurveyFile.d.ts.map +1 -0
  52. package/parseFrcsSurveyFile.js +5 -4
  53. package/parseFrcsSurveyFile.js.map +1 -0
  54. package/parseFrcsTripSummaryFile.d.ts +1 -0
  55. package/parseFrcsTripSummaryFile.d.ts.map +1 -0
  56. package/parseFrcsTripSummaryFile.js +2 -1
  57. package/parseFrcsTripSummaryFile.js.map +1 -0
  58. package/src/FrcsPlotFile.ts +9 -0
  59. package/src/FrcsPlotShot.ts +18 -0
  60. package/src/FrcsShot.ts +56 -0
  61. package/src/FrcsSurveyFile.ts +47 -0
  62. package/src/FrcsTrip.ts +25 -0
  63. package/src/FrcsTripSummary.ts +14 -0
  64. package/src/FrcsTripSummaryFile.ts +7 -0
  65. package/src/formatFrcsShot.ts +168 -0
  66. package/src/formatFrcsSurveyFile.ts +97 -0
  67. package/src/index.ts +29 -0
  68. package/src/node/index.ts +20 -0
  69. package/src/parseFrcsPlotFile.ts +168 -0
  70. package/src/parseFrcsSurveyFile.ts +788 -0
  71. package/src/parseFrcsTripSummaryFile.ts +76 -0
  72. package/src/string/index.ts +21 -0
  73. package/src/web/index.ts +119 -0
  74. package/string/index.d.ts +1 -0
  75. package/string/index.d.ts.map +1 -0
  76. package/string/index.js +2 -1
  77. package/string/index.js.map +1 -0
  78. package/web/index.d.ts +1 -0
  79. package/web/index.d.ts.map +1 -0
  80. package/web/index.js +5 -4
  81. package/web/index.js.map +1 -0
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { FrcsTrip, FrcsTripHeader } from './FrcsTrip'
2
+ import { FrcsShot, FrcsShotKind } from './FrcsShot'
3
+ import { FrcsSurveyFile } from './FrcsSurveyFile'
4
+ import parseFrcsSurveyFile from './parseFrcsSurveyFile'
5
+ import { FrcsPlotShot } from './FrcsPlotShot'
6
+ import { FrcsPlotFile } from './FrcsPlotFile'
7
+ import parseFrcsPlotFile from './parseFrcsPlotFile'
8
+ import { FrcsTripSummary } from './FrcsTripSummary'
9
+ import { FrcsTripSummaryFile } from './FrcsTripSummaryFile'
10
+ import parseFrcsTripSummaryFile from './parseFrcsTripSummaryFile'
11
+ import formatFrcsShot from './formatFrcsShot'
12
+ import { formatFrcsSurveyFile } from './formatFrcsSurveyFile'
13
+
14
+ export {
15
+ FrcsShot,
16
+ FrcsShotKind,
17
+ FrcsSurveyFile,
18
+ FrcsTrip,
19
+ FrcsTripHeader,
20
+ parseFrcsSurveyFile,
21
+ FrcsPlotShot,
22
+ FrcsPlotFile,
23
+ parseFrcsPlotFile,
24
+ FrcsTripSummary,
25
+ FrcsTripSummaryFile,
26
+ parseFrcsTripSummaryFile,
27
+ formatFrcsShot,
28
+ formatFrcsSurveyFile,
29
+ }
@@ -0,0 +1,20 @@
1
+ import fs from 'fs'
2
+ import readline from 'readline'
3
+ import _parseFrcsSurveyFile from '../parseFrcsSurveyFile'
4
+ import _parseFrcsPlotFile from '../parseFrcsPlotFile'
5
+ import _parseFrcsTripSummaryFile from '../parseFrcsTripSummaryFile'
6
+
7
+ const convert =
8
+ <T, Rest extends any[]>(
9
+ fn: (
10
+ file: string,
11
+ lines: AsyncIterable<string>,
12
+ ...rest: Rest
13
+ ) => Promise<T>
14
+ ) =>
15
+ (file: string, ...rest: Rest): Promise<T> =>
16
+ fn(file, readline.createInterface(fs.createReadStream(file)), ...rest)
17
+
18
+ export const parseFrcsSurveyFile = convert(_parseFrcsSurveyFile)
19
+ export const parseFrcsPlotFile = convert(_parseFrcsPlotFile)
20
+ export const parseFrcsTripSummaryFile = convert(_parseFrcsTripSummaryFile)
@@ -0,0 +1,168 @@
1
+ import { FrcsPlotShot } from './FrcsPlotShot'
2
+ import { FrcsPlotFile } from './FrcsPlotFile'
3
+ import { Length, UnitizedNumber, Unitize } from '@speleotica/unitized'
4
+ import { Segment, SegmentParseError } from 'parse-segment'
5
+
6
+ /**
7
+ * Parses data from a calculated survey file. These look like so:
8
+ <pre> 123.182259
9
+ AE20 1 1 0 0 0 153 -257 -51 85 0 20 1
10
+ AE19 1 2 653 402 -548 1046 -587 -174 97 0 200 1
11
+ AE18 2 3 669 449 -3002 995 94 -597 -56 250 0 1
12
+ AE17 3 4 539 1217 -2770 497 47 -298 -28 0 0 1
13
+ AE16 4 5 544 1230 -3441 411 -284 -246 170 60 10 1
14
+ AE15 5 6 1679 1663 -3833 0 0 -282 283 20 10 1
15
+ AE14 6 7 2026 2617 -3730 446 225 -446 -225 0 30 1
16
+ AE13 7 8 391 3152 -5788 -111 691 0 0 200 50 1
17
+ AE12 8 9 -1019 2175 -4630 -369 336 221 -201 40 40 1
18
+ AE11 9 10 -1516 1289 -3919 -348 195 610 -342 50 10 1</pre>
19
+ */
20
+ export default async function parseFrcsPlotFile(
21
+ file: string,
22
+ lines: AsyncIterable<string>
23
+ ): Promise<FrcsPlotFile> {
24
+ let totalLength: UnitizedNumber<Length> = Unitize.feet(NaN)
25
+ const shots: Array<FrcsPlotShot> = []
26
+ const errors: Array<SegmentParseError> = []
27
+
28
+ let lineNumber = 0
29
+
30
+ const error = (
31
+ message: string,
32
+ line: string,
33
+ startColumn: number,
34
+ endColumn: number
35
+ ): void => {
36
+ errors.push(
37
+ new SegmentParseError(
38
+ message,
39
+ new Segment({
40
+ value: line,
41
+ source: file,
42
+ startLine: lineNumber - 1,
43
+ startCol: 0,
44
+ }).substring(startColumn, endColumn)
45
+ )
46
+ )
47
+ }
48
+
49
+ function parseUint(
50
+ line: string,
51
+ startColumn: number,
52
+ endColumn: number,
53
+ fieldName: string
54
+ ): number | null {
55
+ const str = line.substring(startColumn, endColumn)
56
+ if (!/\S/.test(str)) {
57
+ error(`Missing ${fieldName}`, line, startColumn, endColumn)
58
+ return null
59
+ }
60
+ if (!/^\s*\d+\s*$/.test(str)) {
61
+ error(`Invalid ${fieldName}`, line, startColumn, endColumn)
62
+ return null
63
+ }
64
+ return parseInt(str)
65
+ }
66
+
67
+ function parseOptionalUint(
68
+ line: string,
69
+ startColumn: number,
70
+ endColumn: number,
71
+ fieldName: string
72
+ ): number | null {
73
+ const str = line.substring(startColumn, endColumn)
74
+ if (!/\S/.test(str)) {
75
+ return null
76
+ }
77
+ if (!/^\s*\d+\s*$/.test(str)) {
78
+ error(`Invalid ${fieldName}`, line, startColumn, endColumn)
79
+ return null
80
+ }
81
+ return parseInt(str)
82
+ }
83
+
84
+ function parseLength(
85
+ line: string,
86
+ startColumn: number,
87
+ endColumn: number,
88
+ fieldName: string,
89
+ divisor: number
90
+ ): UnitizedNumber<Length> | null {
91
+ const str = line.substring(startColumn, endColumn)
92
+ if (!/^\s*-?\d+\s*$/.test(str)) {
93
+ error(`Invalid ${fieldName}`, line, startColumn, endColumn)
94
+ return null
95
+ }
96
+ const value = parseFloat(str)
97
+ if (isNaN(value)) {
98
+ error(`Missing ${fieldName}`, line, startColumn, endColumn)
99
+ return null
100
+ }
101
+ return Unitize.feet(value / divisor)
102
+ }
103
+
104
+ for await (const line of lines) {
105
+ lineNumber++
106
+ if (lineNumber === 1) {
107
+ totalLength = Unitize.feet(parseFloat(line))
108
+ continue
109
+ }
110
+ if (!/\S/.test(line)) continue
111
+ const toName = line.substring(0, 6).trim()
112
+ if (!toName) {
113
+ error('Invalid to station name', line, 0, 6)
114
+ continue
115
+ }
116
+ if (/[^ S]/.test(line[6])) {
117
+ error('Invalid flag', line, 6, 7)
118
+ continue
119
+ }
120
+ const isSurface = line[6] === 'S'
121
+ const fromNumber = parseUint(line, 7, 12, 'from station number')
122
+ if (fromNumber == null) continue
123
+ const toNumber = parseUint(line, 12, 17, 'to station number')
124
+ if (toNumber == null) continue
125
+ const easting = parseLength(line, 17, 25, 'easting', 100)
126
+ if (!easting) continue
127
+ const northing = parseLength(line, 25, 33, 'northing', 100)
128
+ if (!northing) continue
129
+ const elevation = parseLength(line, 33, 40, 'elevation', 100)
130
+ if (!elevation) continue
131
+ const leftEasting = parseLength(line, 40, 46, 'left wall easting', 100)
132
+ if (!leftEasting) continue
133
+ const leftNorthing = parseLength(line, 46, 52, 'left wall northing', 100)
134
+ if (!leftNorthing) continue
135
+ const rightEasting = parseLength(line, 52, 58, 'right wall easting', 100)
136
+ if (!rightEasting) continue
137
+ const rightNorthing = parseLength(line, 58, 64, 'right wall northing', 100)
138
+ if (!rightNorthing) continue
139
+ const up = parseLength(line, 64, 68, 'up', 10)
140
+ if (!up) continue
141
+ const down = parseLength(line, 68, 72, 'down', 10)
142
+ if (!down) continue
143
+ const tripNumber = parseOptionalUint(line, 72, 78, 'trip number')
144
+
145
+ shots.push({
146
+ toName,
147
+ isSurface,
148
+ fromNumber,
149
+ toNumber,
150
+ easting,
151
+ northing,
152
+ elevation,
153
+ leftEasting,
154
+ leftNorthing,
155
+ rightEasting,
156
+ rightNorthing,
157
+ up,
158
+ down,
159
+ tripNumber,
160
+ })
161
+ }
162
+
163
+ return {
164
+ totalLength,
165
+ shots,
166
+ errors,
167
+ }
168
+ }