Skip to content

Commit ccb76de

Browse files
committed
fixes
1 parent a84dfe6 commit ccb76de

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

website/src/components/Submission/FileUpload/ColumnMapping.spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ describe('ColumnMapping', () => {
1818
]);
1919
});
2020

21+
it('should create a mapping from columns with sensible column mapping', () => {
22+
const sourceColumns = ['state', 'geoLocAdmin2'];
23+
const inputFields = [
24+
{ name: 'date' },
25+
{ name: 'geoLocAdmin1', displayName: 'Collection subdivision level 1' },
26+
{ name: 'geoLocAdmin2', displayName: 'Collection subdivision level 2' }
27+
];
28+
29+
const mapping = ColumnMapping.fromColumns(sourceColumns, inputFields);
30+
const entries = mapping.entries();
31+
32+
expect(entries).toEqual([
33+
['state', null],
34+
['geoLocAdmin2', 'geoLocAdmin2']
35+
]);
36+
});
37+
2138
it('should create a mapping from columns without duplicates', () => {
2239
const sourceColumns = ['date', 'Date'];
2340
const inputFields = [{ name: 'date', displayName: 'Date' }, { name: 'location' }, { name: 'foo' }];

website/src/components/Submission/FileUpload/ColumnMapping.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class ColumnMapping {
1919
return [field.name, score];
2020
})
2121
.reduce((maxItem, currentItem) => (currentItem[1] > maxItem[1] ? currentItem : maxItem));
22-
return score > 0.5 ? bestMatch : null;
22+
return score > 0.8 ? bestMatch : null;
2323
}
2424

2525
/* Create a new mapping with the given columns, doing a best-effort to pre-match columns. */

website/src/utils/stringSimilarity.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ export const stringSimilarity = (
3838

3939
const map = new Map<string, number>();
4040
for (let i = 0; i < str1.length - (substringLength - 1); i++) {
41-
const substr1 = str1.substring(i, substringLength);
41+
const substr1 = str1.substring(i, i + substringLength);
4242
map.set(substr1, (map.get(substr1) ?? 0) + 1);
4343
}
4444

4545
let match = 0;
4646
for (let j = 0; j < str2.length - (substringLength - 1); j++) {
47-
const substr2 = str2.substring(j, substringLength);
47+
const substr2 = str2.substring(j, j + substringLength);
4848
const count = map.get(substr2) ?? 0;
4949
if (count > 0) {
5050
map.set(substr2, count - 1);

0 commit comments

Comments
 (0)