Dictionary import count details (#1935)
* Store count information when importing a dictionary * Add importDate * Update property ordering * Update tests * Update importDate
This commit is contained in:
parent
c91831a817
commit
ac12b50939
@ -128,7 +128,15 @@ class DictionaryImporter {
|
|||||||
// Add dictionary descriptor
|
// Add dictionary descriptor
|
||||||
this._progressNextStep(termList.length + termMetaList.length + kanjiList.length + kanjiMetaList.length + tagList.length + media.length);
|
this._progressNextStep(termList.length + termMetaList.length + kanjiList.length + kanjiMetaList.length + tagList.length + media.length);
|
||||||
|
|
||||||
const summary = this._createSummary(dictionaryTitle, version, index, {prefixWildcardsSupported});
|
const counts = {
|
||||||
|
terms: {total: termList.length},
|
||||||
|
termMeta: this._getMetaCounts(termMetaList),
|
||||||
|
kanji: {total: kanjiList.length},
|
||||||
|
kanjiMeta: this._getMetaCounts(kanjiMetaList),
|
||||||
|
tagMeta: {total: tagList.length},
|
||||||
|
media: {total: media.length}
|
||||||
|
};
|
||||||
|
const summary = this._createSummary(dictionaryTitle, version, index, {prefixWildcardsSupported, counts});
|
||||||
dictionaryDatabase.bulkAdd('dictionaries', [summary], 0, 1);
|
dictionaryDatabase.bulkAdd('dictionaries', [summary], 0, 1);
|
||||||
|
|
||||||
// Add data
|
// Add data
|
||||||
@ -189,7 +197,8 @@ class DictionaryImporter {
|
|||||||
title: dictionaryTitle,
|
title: dictionaryTitle,
|
||||||
revision: index.revision,
|
revision: index.revision,
|
||||||
sequenced: index.sequenced,
|
sequenced: index.sequenced,
|
||||||
version
|
version,
|
||||||
|
importDate: Date.now()
|
||||||
};
|
};
|
||||||
|
|
||||||
const {author, url, description, attribution} = index;
|
const {author, url, description, attribution} = index;
|
||||||
@ -556,4 +565,19 @@ class DictionaryImporter {
|
|||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getMetaCounts(metaList) {
|
||||||
|
const countsMap = new Map();
|
||||||
|
for (const {mode} of metaList) {
|
||||||
|
let count = countsMap.get(mode);
|
||||||
|
count = typeof count !== 'undefined' ? count + 1 : 1;
|
||||||
|
countsMap.set(mode, count);
|
||||||
|
}
|
||||||
|
const counts = {total: metaList.length};
|
||||||
|
for (const [key, value] of countsMap.entries()) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(counts, key)) { continue; }
|
||||||
|
counts[key] = value;
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,16 @@ async function testDatabase1() {
|
|||||||
revision: 'test',
|
revision: 'test',
|
||||||
sequenced: true,
|
sequenced: true,
|
||||||
version: 3,
|
version: 3,
|
||||||
prefixWildcardsSupported: true
|
importDate: 0,
|
||||||
|
prefixWildcardsSupported: true,
|
||||||
|
counts: {
|
||||||
|
kanji: {total: 2},
|
||||||
|
kanjiMeta: {total: 2, freq: 2},
|
||||||
|
media: {total: 4},
|
||||||
|
tagMeta: {total: 15},
|
||||||
|
termMeta: {total: 16, freq: 9, pitch: 7},
|
||||||
|
terms: {total: 20}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Import data
|
// Import data
|
||||||
@ -158,6 +167,7 @@ async function testDatabase1() {
|
|||||||
testDictionarySource,
|
testDictionarySource,
|
||||||
{prefixWildcardsSupported: true}
|
{prefixWildcardsSupported: true}
|
||||||
);
|
);
|
||||||
|
expectedSummary.importDate = result.importDate;
|
||||||
vm.assert.deepStrictEqual(errors, []);
|
vm.assert.deepStrictEqual(errors, []);
|
||||||
vm.assert.deepStrictEqual(result, expectedSummary);
|
vm.assert.deepStrictEqual(result, expectedSummary);
|
||||||
assert.ok(progressEvent);
|
assert.ok(progressEvent);
|
||||||
|
Loading…
Reference in New Issue
Block a user