@rangefoundry/importers 0.0.0 → 0.1.0
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.
- package/LICENSE +661 -0
- package/README.md +20 -1
- package/dist/cells.d.ts +31 -0
- package/dist/cells.js +22 -0
- package/dist/cfb.d.ts +2 -0
- package/dist/cfb.js +196 -0
- package/dist/csrload.d.ts +12 -0
- package/dist/csrload.js +153 -0
- package/dist/diagnostics.d.ts +42 -0
- package/dist/diagnostics.js +29 -0
- package/dist/generic.d.ts +44 -0
- package/dist/generic.js +272 -0
- package/dist/grtload.d.ts +32 -0
- package/dist/grtload.js +264 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +126 -0
- package/dist/limits.d.ts +7 -0
- package/dist/limits.js +12 -0
- package/dist/pressure-history.d.ts +61 -0
- package/dist/pressure-history.js +158 -0
- package/dist/rangefoundry-json.d.ts +17 -0
- package/dist/rangefoundry-json.js +176 -0
- package/dist/record-fields.d.ts +35 -0
- package/dist/record-fields.js +190 -0
- package/dist/record-ids.d.ts +2 -0
- package/dist/record-ids.js +28 -0
- package/dist/records.d.ts +91 -0
- package/dist/records.js +433 -0
- package/dist/result.d.ts +65 -0
- package/dist/result.js +90 -0
- package/dist/shot-rows.d.ts +11 -0
- package/dist/shot-rows.js +39 -0
- package/dist/shotview.d.ts +16 -0
- package/dist/shotview.js +131 -0
- package/dist/statistics.d.ts +12 -0
- package/dist/statistics.js +48 -0
- package/dist/tables.d.ts +41 -0
- package/dist/tables.js +277 -0
- package/dist/template.d.ts +13 -0
- package/dist/template.js +37 -0
- package/dist/text.d.ts +28 -0
- package/dist/text.js +150 -0
- package/dist/units.d.ts +12 -0
- package/dist/units.js +62 -0
- package/dist/workbook.d.ts +12 -0
- package/dist/workbook.js +264 -0
- package/dist/worksheet-strings.d.ts +36 -0
- package/dist/worksheet-strings.js +50 -0
- package/dist/xls.d.ts +3 -0
- package/dist/xls.js +486 -0
- package/dist/xml.d.ts +26 -0
- package/dist/xml.js +261 -0
- package/dist/zip.d.ts +27 -0
- package/dist/zip.js +183 -0
- package/package.json +58 -4
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// The record kinds a table is read as and the fields each one maps.
|
|
2
|
+
import { conversions } from '@rangefoundry/units';
|
|
3
|
+
/** The kinds a table is scored for. */
|
|
4
|
+
export const tableKinds = ['bullet', 'powder', 'cartridge'];
|
|
5
|
+
/** The plural name of each kind, as the table import page titles its sections. */
|
|
6
|
+
export const kindNames = {
|
|
7
|
+
bullet: 'bullets',
|
|
8
|
+
powder: 'powders',
|
|
9
|
+
cartridge: 'cartridges',
|
|
10
|
+
};
|
|
11
|
+
const unit = (symbol, factor, named) => ({
|
|
12
|
+
symbol,
|
|
13
|
+
toStored: factor === 1 ? (x) => x : (x) => x * factor,
|
|
14
|
+
...(named && { named }),
|
|
15
|
+
});
|
|
16
|
+
// the customary factors come from the conversion table (SI per unit), turned into mm, g and bar here
|
|
17
|
+
const inch = conversions.in.factor;
|
|
18
|
+
const pound = conversions.lb.factor;
|
|
19
|
+
const lengthUnits = [unit('mm', 1), unit('in', inch / conversions.mm.factor), unit('cm', 10)];
|
|
20
|
+
const massUnits = [unit('g', 1), unit('gr', conversions.gr.factor * 1000)];
|
|
21
|
+
const coefficientUnits = [unit('lb/in2', 1), unit('kg/m2', inch ** 2 / pound)];
|
|
22
|
+
const densityUnits = [unit('g/cm3', 1)];
|
|
23
|
+
export const psi = conversions.psi.factor / conversions.bar.factor;
|
|
24
|
+
// the values of MPa and kpsi fall in the usual bar range too, so only a header names them
|
|
25
|
+
const pressureUnits = [
|
|
26
|
+
unit('bar', 1),
|
|
27
|
+
unit('psi', psi),
|
|
28
|
+
unit('MPa', 10, true),
|
|
29
|
+
unit('kpsi', psi * 1000, true),
|
|
30
|
+
];
|
|
31
|
+
const name = {
|
|
32
|
+
key: 'name',
|
|
33
|
+
label: 'Name',
|
|
34
|
+
aliases: [
|
|
35
|
+
'name',
|
|
36
|
+
'bullet',
|
|
37
|
+
'powder',
|
|
38
|
+
'cartridge',
|
|
39
|
+
'description',
|
|
40
|
+
'product',
|
|
41
|
+
'item',
|
|
42
|
+
'bezeichnung',
|
|
43
|
+
],
|
|
44
|
+
weight: 0.2,
|
|
45
|
+
required: true,
|
|
46
|
+
};
|
|
47
|
+
const maker = {
|
|
48
|
+
key: 'maker',
|
|
49
|
+
label: 'Maker',
|
|
50
|
+
aliases: ['maker', 'manufacturer', 'brand', 'make', 'hersteller'],
|
|
51
|
+
weight: 0.05,
|
|
52
|
+
};
|
|
53
|
+
/** The fields of each kind with their header aliases, units, usual ranges and score weights. */
|
|
54
|
+
export const fieldSpecs = {
|
|
55
|
+
bullet: [
|
|
56
|
+
name,
|
|
57
|
+
maker,
|
|
58
|
+
{
|
|
59
|
+
key: 'caliber',
|
|
60
|
+
label: 'Caliber',
|
|
61
|
+
aliases: ['caliber', 'calibre', 'cal', 'kaliber'],
|
|
62
|
+
weight: 0.05,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: 'diameter',
|
|
66
|
+
label: 'Diameter',
|
|
67
|
+
aliases: ['diameter', 'dia', 'durchmesser'],
|
|
68
|
+
weight: 0.4,
|
|
69
|
+
required: true,
|
|
70
|
+
units: lengthUnits,
|
|
71
|
+
range: [3, 25],
|
|
72
|
+
typical: [4, 12],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: 'mass',
|
|
76
|
+
label: 'Mass',
|
|
77
|
+
aliases: ['mass', 'weight', 'wt', 'grains', 'gr', 'gewicht', 'masse'],
|
|
78
|
+
weight: 0.4,
|
|
79
|
+
required: true,
|
|
80
|
+
units: massUnits,
|
|
81
|
+
range: [0.5, 60],
|
|
82
|
+
typical: [1, 30],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: 'length',
|
|
86
|
+
label: 'Length',
|
|
87
|
+
aliases: ['length', 'len', 'oal', 'laenge'],
|
|
88
|
+
weight: 0.05,
|
|
89
|
+
units: lengthUnits,
|
|
90
|
+
range: [5, 80],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: 'bcG1',
|
|
94
|
+
label: 'BC G1',
|
|
95
|
+
aliases: ['g1', 'bcg1', 'bc1'],
|
|
96
|
+
weight: 0.05,
|
|
97
|
+
units: coefficientUnits,
|
|
98
|
+
range: [0.05, 1.5],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
key: 'bcG7',
|
|
102
|
+
label: 'BC G7',
|
|
103
|
+
aliases: ['g7', 'bcg7', 'bc7'],
|
|
104
|
+
weight: 0.05,
|
|
105
|
+
units: coefficientUnits,
|
|
106
|
+
range: [0.05, 1.5],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
powder: [
|
|
110
|
+
name,
|
|
111
|
+
maker,
|
|
112
|
+
{
|
|
113
|
+
key: 'grainForm',
|
|
114
|
+
label: 'Grain form',
|
|
115
|
+
aliases: ['grainform', 'form', 'shape', 'grain', 'kornform'],
|
|
116
|
+
weight: 0.3,
|
|
117
|
+
choices: {
|
|
118
|
+
ball: 'ball',
|
|
119
|
+
spherical: 'ball',
|
|
120
|
+
extruded: 'extruded',
|
|
121
|
+
stick: 'extruded',
|
|
122
|
+
tubular: 'extruded',
|
|
123
|
+
flake: 'flake',
|
|
124
|
+
flattened: 'flake',
|
|
125
|
+
other: 'other',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
key: 'propellantBase',
|
|
130
|
+
label: 'Propellant base',
|
|
131
|
+
aliases: ['base', 'propellantbase', 'basis'],
|
|
132
|
+
weight: 0.25,
|
|
133
|
+
choices: {
|
|
134
|
+
single: 'single',
|
|
135
|
+
'single-base': 'single',
|
|
136
|
+
double: 'double',
|
|
137
|
+
'double-base': 'double',
|
|
138
|
+
triple: 'triple',
|
|
139
|
+
'triple-base': 'triple',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
key: 'bulkDensity',
|
|
144
|
+
label: 'Bulk density',
|
|
145
|
+
aliases: ['bulkdensity', 'density', 'bulk', 'schuettdichte'],
|
|
146
|
+
weight: 0.25,
|
|
147
|
+
units: densityUnits,
|
|
148
|
+
range: [0.3, 1.3],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
cartridge: [
|
|
152
|
+
name,
|
|
153
|
+
{
|
|
154
|
+
key: 'caseLength',
|
|
155
|
+
label: 'Case length',
|
|
156
|
+
aliases: ['caselength', 'l3', 'case', 'huelsenlaenge'],
|
|
157
|
+
weight: 0.3,
|
|
158
|
+
units: lengthUnits,
|
|
159
|
+
range: [10, 120],
|
|
160
|
+
typical: [15, 90],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
key: 'overallLength',
|
|
164
|
+
label: 'Overall length',
|
|
165
|
+
aliases: ['overalllength', 'coal', 'oal', 'l6', 'cartridgelength'],
|
|
166
|
+
weight: 0.1,
|
|
167
|
+
units: lengthUnits,
|
|
168
|
+
range: [15, 150],
|
|
169
|
+
typical: [25, 120],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
key: 'bulletDiameter',
|
|
173
|
+
label: 'Bullet diameter',
|
|
174
|
+
aliases: ['bulletdiameter', 'g1', 'diameter', 'dia'],
|
|
175
|
+
weight: 0.25,
|
|
176
|
+
units: lengthUnits,
|
|
177
|
+
range: [3, 25],
|
|
178
|
+
typical: [4, 12],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
key: 'maxPressure',
|
|
182
|
+
label: 'Max pressure',
|
|
183
|
+
aliases: ['maxpressure', 'pmax', 'pressure', 'maxpress'],
|
|
184
|
+
weight: 0.25,
|
|
185
|
+
units: pressureUnits,
|
|
186
|
+
range: [300, 6500],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=record-fields.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// A deterministic id for an imported row: the same key gives the same UUID, so a second import finds its records.
|
|
2
|
+
/** Four 32-bit words of a 128-bit non-cryptographic hash of `s` (the cyrb128 mix). */
|
|
3
|
+
function hash128(s) {
|
|
4
|
+
let h1 = 1779033703;
|
|
5
|
+
let h2 = 3144134277;
|
|
6
|
+
let h3 = 1013904242;
|
|
7
|
+
let h4 = 2773480762;
|
|
8
|
+
for (let i = 0; i < s.length; i++) {
|
|
9
|
+
const k = s.charCodeAt(i);
|
|
10
|
+
h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
|
|
11
|
+
h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
|
|
12
|
+
h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
|
|
13
|
+
h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
|
|
14
|
+
}
|
|
15
|
+
h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);
|
|
16
|
+
h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);
|
|
17
|
+
h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);
|
|
18
|
+
h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);
|
|
19
|
+
return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];
|
|
20
|
+
}
|
|
21
|
+
const hex = (n, width) => n.toString(16).padStart(width, '0');
|
|
22
|
+
/** The UUID (version nibble 8, variant 10) of `key`; it passes the id pattern of the user records. */
|
|
23
|
+
export function idOfKey(key) {
|
|
24
|
+
const [a, b, c, d] = hash128(key);
|
|
25
|
+
const variant = ((c >>> 16) & 0x3fff) | 0x8000;
|
|
26
|
+
return `${hex(a, 8)}-${hex(b >>> 16, 4)}-8${hex(b & 0xfff, 3)}-${hex(variant, 4)}-${hex(c & 0xffff, 4)}${hex(d, 8)}`;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=record-ids.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Diagnostic } from '@rangefoundry/statistics';
|
|
2
|
+
import type { Candidate, ReaderDiagnostic } from './diagnostics.ts';
|
|
3
|
+
import { type TableKind } from './record-fields.ts';
|
|
4
|
+
import { type Table } from './tables.ts';
|
|
5
|
+
/** How sure a kind suggestion is. */
|
|
6
|
+
export type Tier = 'high' | 'medium' | 'low';
|
|
7
|
+
/** Lowest kind score that suggests a kind, and the scores from which the tier is medium and high. */
|
|
8
|
+
export declare const tierFloors: {
|
|
9
|
+
readonly low: 0.4;
|
|
10
|
+
readonly medium: 0.6;
|
|
11
|
+
readonly high: 0.8;
|
|
12
|
+
};
|
|
13
|
+
/** How a column of a table is read: the field it fills, the unit and decimal mark of its numbers. */
|
|
14
|
+
export interface TableColumnMap {
|
|
15
|
+
field?: string | undefined;
|
|
16
|
+
/** Symbol of one of the field's units. */
|
|
17
|
+
unit?: string | undefined;
|
|
18
|
+
decimal: '.' | ',';
|
|
19
|
+
/** Where the unit came from: the header, the values or the stored unit as the default; `unknown` when the header names a unit the field does not take. */
|
|
20
|
+
unitFrom?: 'header' | 'values' | 'default' | 'unknown' | undefined;
|
|
21
|
+
/** The cells could also read as grouped integers: the decimal mark is a guess. */
|
|
22
|
+
ambiguousDecimal?: boolean | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** The score of one kind for a table, 0 to 1. */
|
|
25
|
+
export interface KindScore {
|
|
26
|
+
kind: TableKind;
|
|
27
|
+
score: number;
|
|
28
|
+
}
|
|
29
|
+
/** No kind reaches `floor`, the lowest score that suggests one: the scores of every kind, best first. The app words it. */
|
|
30
|
+
export type KindDiagnostic = Diagnostic<'noKind', {
|
|
31
|
+
readonly scores: readonly KindScore[];
|
|
32
|
+
readonly floor: number;
|
|
33
|
+
}>;
|
|
34
|
+
/** The kind scores of a table, best first, and the suggested kind with its tier, or the refusal when none reaches the floor. */
|
|
35
|
+
export interface KindSuggestion {
|
|
36
|
+
scores: KindScore[];
|
|
37
|
+
kind?: TableKind | undefined;
|
|
38
|
+
tier?: Tier | undefined;
|
|
39
|
+
refusal?: KindDiagnostic | undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The kind a table suggests from its header words and value ranges: high from 0.80, medium from
|
|
43
|
+
* 0.60, low from 0.40. Below 0.40 no kind is suggested and the refusal carries the scores and the floor.
|
|
44
|
+
*/
|
|
45
|
+
export declare function suggestKind(table: Table): KindSuggestion;
|
|
46
|
+
/** The column map the headers and values suggest for `kind`, one entry per column. */
|
|
47
|
+
export declare function autoMap(table: Table, kind: TableKind): TableColumnMap[];
|
|
48
|
+
/** Why a row of a table is rejected or warned, as a code and the values its message names. */
|
|
49
|
+
export type TableDiagnostic = ReaderDiagnostic<'emptyCell' | 'noUnit' | 'unitOther' | 'notNumber' | 'notAboveZero' | 'outsideUsual' | 'notChoice' | 'noColumn' | 'noColumns' | 'sameId' | 'sameBulletId'>;
|
|
50
|
+
/**
|
|
51
|
+
* Where a row was rejected or warned: the 1-based row of the file (the header is row 1), the
|
|
52
|
+
* column's header, the cell and why; `field` params are field keys.
|
|
53
|
+
*/
|
|
54
|
+
export interface RowIssue {
|
|
55
|
+
row: number;
|
|
56
|
+
column: string;
|
|
57
|
+
cell: string;
|
|
58
|
+
reason: TableDiagnostic;
|
|
59
|
+
}
|
|
60
|
+
/** Counts of the row report: rows accepted (those with a warning among them), rows with a warning and rows rejected. */
|
|
61
|
+
export interface RowCounts {
|
|
62
|
+
accepted: number;
|
|
63
|
+
warned: number;
|
|
64
|
+
rejected: number;
|
|
65
|
+
}
|
|
66
|
+
/** The candidate of an accepted row. */
|
|
67
|
+
export interface BuiltEntry {
|
|
68
|
+
row: number;
|
|
69
|
+
candidate: Candidate;
|
|
70
|
+
}
|
|
71
|
+
/** The candidates of a table and its row report. */
|
|
72
|
+
export interface BuiltRecords {
|
|
73
|
+
/** One entry per accepted row. */
|
|
74
|
+
entries: BuiltEntry[];
|
|
75
|
+
/** The makers the rows name, as manufacturer candidates the entries refer to. */
|
|
76
|
+
makers: Candidate[];
|
|
77
|
+
counts: RowCounts;
|
|
78
|
+
rejected: RowIssue[];
|
|
79
|
+
warnings: RowIssue[];
|
|
80
|
+
}
|
|
81
|
+
/** Lower case, accents and extra spaces folded: the form of a name in a key. */
|
|
82
|
+
export declare const keyText: (s: string) => string;
|
|
83
|
+
/**
|
|
84
|
+
* The record candidates of `table` read with `map` as `kind`. A row that fails is listed with row,
|
|
85
|
+
* column, cell and reason and never blocks the others. Keys are deterministic (kind, name, maker
|
|
86
|
+
* and, for a bullet, diameter and mass), so the same row read again gets the same id
|
|
87
|
+
* (`idOfKey(key)`). A row whose key repeats an earlier row's gets a warning naming both rows; the
|
|
88
|
+
* caller keeps the first record of an id. The caller makes each candidate a record and parses it
|
|
89
|
+
* with the user record schema before storing it.
|
|
90
|
+
*/
|
|
91
|
+
export declare function buildRecords(table: Table, kind: TableKind, map: TableColumnMap[]): BuiltRecords;
|