forked from MapComplete/MapComplete
Performance: prepare dropping the NSI-logos from the repo
This commit is contained in:
parent
164b02c8ff
commit
555075edfe
3 changed files with 17 additions and 26 deletions
|
@ -9,19 +9,8 @@ import { And } from "../src/Logic/Tags/And"
|
|||
import Script from "./Script"
|
||||
import NameSuggestionIndex from "../src/Logic/Web/NameSuggestionIndex"
|
||||
import TagInfo from "../src/Logic/Web/TagInfo"
|
||||
import { TagsFilter } from "../src/Logic/Tags/TagsFilter"
|
||||
|
||||
class Utilities {
|
||||
static mapValues<X extends string | number, T, TOut>(
|
||||
record: Record<X, T>,
|
||||
f: (t: T) => TOut
|
||||
): Record<X, TOut> {
|
||||
const newR = <Record<X, TOut>>{}
|
||||
for (const x in record) {
|
||||
newR[x] = f(record[x])
|
||||
}
|
||||
return newR
|
||||
}
|
||||
}
|
||||
|
||||
class GenerateStats extends Script {
|
||||
async createOptimizationFile(includeTags = true) {
|
||||
|
@ -38,7 +27,7 @@ class GenerateStats extends Script {
|
|||
continue
|
||||
}
|
||||
|
||||
const sourcesList = [TagUtils.Tag(layer.source["osmTags"])]
|
||||
const sourcesList: TagsFilter[] = [TagUtils.Tag(layer.source["osmTags"])]
|
||||
if (layer?.title) {
|
||||
sourcesList.push(...new TagRenderingConfig(layer.title).usedTags())
|
||||
}
|
||||
|
@ -120,7 +109,7 @@ class GenerateStats extends Script {
|
|||
|
||||
const allBrands = Object.keys(data)
|
||||
allBrands.sort()
|
||||
for (const country of allCountries) {
|
||||
for (const country of Array.from(allCountries)) {
|
||||
const summary = <Record<string, number>>{}
|
||||
for (const brand of allBrands) {
|
||||
const count = data[brand][country]
|
||||
|
@ -150,7 +139,7 @@ class GenerateStats extends Script {
|
|||
path
|
||||
)
|
||||
}
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex()
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
|
||||
const allBrandNames: string[] = Utils.Dedup(
|
||||
nsi.allPossible(<any>type).map((item) => item.tags[type])
|
||||
)
|
||||
|
|
|
@ -42,7 +42,7 @@ class NsiLogos extends Script {
|
|||
let path = basePath + nsiItem.id
|
||||
|
||||
const logos = nsiWD["wikidata"][nsiItem?.tags?.[type + ":wikidata"]]?.logos
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex()
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
|
||||
if (nsi.isSvg(nsiItem, type)) {
|
||||
path = path + ".svg"
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class NsiLogos extends Script {
|
|||
* @param type
|
||||
*/
|
||||
async downloadFor(type: string): Promise<{ downloadCount: number; errored: number }> {
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex()
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
|
||||
const items = nsi.allPossible(type)
|
||||
const basePath = "./public/assets/data/nsi/logos/"
|
||||
let downloadCount = 0
|
||||
|
@ -158,7 +158,7 @@ class NsiLogos extends Script {
|
|||
}
|
||||
|
||||
private async generateRendering(type: string) {
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex()
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
|
||||
const items = nsi.allPossible(type)
|
||||
const filterOptions: FilterConfigOptionJson[] = items.map((item) => {
|
||||
return {
|
||||
|
@ -278,7 +278,7 @@ class NsiLogos extends Script {
|
|||
* @private
|
||||
*/
|
||||
private static async prune() {
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex()
|
||||
const nsi = await NameSuggestionIndex.getNsiIndex("./assets/data/nsi/")
|
||||
const types = nsi.supportedTypes()
|
||||
const ids = new Set<string>()
|
||||
for (const t of types) {
|
||||
|
|
|
@ -262,14 +262,15 @@ export class NameSuggestionIndexLight {
|
|||
if (NameSuggestionIndexLight.initedLight) {
|
||||
return NameSuggestionIndexLight.initedLight
|
||||
}
|
||||
const endpoint = Constants.nsiLogosEndpoint ?? "./assets/data/nsi/"
|
||||
const [nsi, features] = await Promise.all(
|
||||
[
|
||||
"./assets/data/nsi/nsi.min.json",
|
||||
"./assets/data/nsi/featureCollection.min.json"
|
||||
endpoint + "nsi.min.json",
|
||||
endpoint + "featureCollection.min.json"
|
||||
].map((url) => Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30))
|
||||
)
|
||||
return new NameSuggestionIndexLight(
|
||||
Constants.nsiLogosEndpoint,
|
||||
endpoint,
|
||||
<any>nsi,
|
||||
<any>features
|
||||
)
|
||||
|
@ -310,15 +311,16 @@ export default class NameSuggestionIndex extends NameSuggestionIndexLight {
|
|||
}
|
||||
|
||||
|
||||
public static async getNsiIndex(): Promise<NameSuggestionIndex> {
|
||||
public static async getNsiIndex(endPoint ?: string): Promise<NameSuggestionIndex> {
|
||||
if (NameSuggestionIndex.inited) {
|
||||
return NameSuggestionIndex.inited
|
||||
}
|
||||
endPoint ??= Constants.nsiLogosEndpoint ?? "./assets/data/nsi/"
|
||||
const [nsi, nsiWd, features] = await Promise.all(
|
||||
[
|
||||
"./assets/data/nsi/nsi.min.json",
|
||||
"./assets/data/nsi/wikidata.min.json",
|
||||
"./assets/data/nsi/featureCollection.min.json"
|
||||
endPoint + "nsi.min.json",
|
||||
endPoint + "wikidata.min.json",
|
||||
endPoint + "featureCollection.min.json"
|
||||
].map((url) => Utils.downloadJsonCached(url, 1000 * 60 * 60 * 24 * 30))
|
||||
)
|
||||
return new NameSuggestionIndex(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue