Improve typing, remove unused parameter

This commit is contained in:
Pieter Vander Vennet 2023-01-13 02:43:21 +01:00
parent ee575a9c42
commit 55788c00ae

View file

@ -17,7 +17,7 @@ class StatsDownloader {
this._targetDirectory = targetDirectory this._targetDirectory = targetDirectory
} }
public async DownloadStats(startYear = 2020, startMonth = 5, startDay = 1) { public async DownloadStats(startYear = 2020, startMonth = 5, startDay = 1): Promise<void> {
const today = new Date() const today = new Date()
const currentYear = today.getFullYear() const currentYear = today.getFullYear()
const currentMonth = today.getMonth() + 1 const currentMonth = today.getMonth() + 1
@ -62,7 +62,7 @@ class StatsDownloader {
console.log( console.log(
"Loaded ", "Loaded ",
path, path,
"from disk, has", "from disk, which has",
features.length, features.length,
"features now" "features now"
) )
@ -70,7 +70,7 @@ class StatsDownloader {
} }
let dayFeatures: any[] = undefined let dayFeatures: any[] = undefined
try { try {
dayFeatures = await this.DownloadStatsForDay(year, month, day, path) dayFeatures = await this.DownloadStatsForDay(year, month, day)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
console.error( console.error(
@ -82,7 +82,7 @@ class StatsDownloader {
day + day +
"... Trying again" "... Trying again"
) )
dayFeatures = await this.DownloadStatsForDay(year, month, day, path) dayFeatures = await this.DownloadStatsForDay(year, month, day)
} }
writeFileSync(path, JSON.stringify(dayFeatures)) writeFileSync(path, JSON.stringify(dayFeatures))
features.push(...dayFeatures) features.push(...dayFeatures)
@ -101,11 +101,10 @@ class StatsDownloader {
public async DownloadStatsForDay( public async DownloadStatsForDay(
year: number, year: number,
month: number, month: number,
day: number, day: number
path: string ): Promise<ChangeSetData[]> {
): Promise<any[]> {
let page = 1 let page = 1
let allFeatures = [] let allFeatures: ChangeSetData[] = []
let endDay = new Date(year, month - 1 /* Zero-indexed: 0 = january*/, day + 1) let endDay = new Date(year, month - 1 /* Zero-indexed: 0 = january*/, day + 1)
let endDate = `${endDay.getFullYear()}-${Utils.TwoDigits( let endDate = `${endDay.getFullYear()}-${Utils.TwoDigits(
endDay.getMonth() + 1 endDay.getMonth() + 1
@ -146,16 +145,11 @@ class StatsDownloader {
} }
url = result.next url = result.next
} }
console.log(
`Writing ${allFeatures.length} features to `,
path,
Utils.Times((_) => " ", 80)
)
allFeatures = Utils.NoNull(allFeatures) allFeatures = Utils.NoNull(allFeatures)
allFeatures.forEach((f) => { allFeatures.forEach((f) => {
f.properties = { ...f.properties, ...f.properties.metadata } f.properties = { ...f.properties, ...f.properties.metadata }
delete f.properties.metadata delete f.properties.metadata
f.properties.id = f.id f.properties["id"] = f.id
}) })
return allFeatures return allFeatures
} }