TD 表示待定(TBD),不再按日期推断城市
This commit is contained in:
@@ -22,11 +22,11 @@ describe('mediaCaption', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('infers city for early TD photos by date', () => {
|
test('shows TBD for photos whose city is to be determined', () => {
|
||||||
expect(mediaCaption('20220806@TD000001.jpg')?.city).toBe('珠海')
|
expect(mediaCaption('20220806@TD000001.jpg')?.city).toBe('TBD')
|
||||||
expect(mediaCaption('20230910@TD000020.jpg')?.city).toBe('拉萨')
|
expect(mediaCaption('20230910@TD000020.jpg')?.city).toBe('TBD')
|
||||||
expect(mediaCaption('20240616@TD000054.jpg')?.city).toBe('广州')
|
expect(mediaCaption('20240616@TD000054.jpg')?.city).toBe('TBD')
|
||||||
expect(mediaCaption('20260913@TD000115.jpg')?.city).toBe('北京')
|
expect(mediaCaption('20260913@TD000115.jpg')?.city).toBe('TBD')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('returns null when no date can be parsed', () => {
|
test('returns null when no date can be parsed', () => {
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ const CITY_BY_CODE: Record<string, string> = {
|
|||||||
HEB: '哈尔滨',
|
HEB: '哈尔滨',
|
||||||
CC: '长春',
|
CC: '长春',
|
||||||
HHHT: '呼和浩特',
|
HHHT: '呼和浩特',
|
||||||
|
// `TD` means the city is still to be determined.
|
||||||
|
TD: 'TBD',
|
||||||
}
|
}
|
||||||
|
|
||||||
const CITY_NAMES = Array.from(new Set(Object.values(CITY_BY_CODE)))
|
const CITY_NAMES = Array.from(new Set(Object.values(CITY_BY_CODE)))
|
||||||
@@ -79,21 +81,9 @@ function parseDate(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Early photos could not be assigned a city when they were renamed and were all
|
// Early photos whose city could not be determined were tagged as `TD`
|
||||||
// tagged as `TD`. Infer their city from the shooting date, matching the
|
// ("to be determined") when they were renamed, so they are shown as `TBD`.
|
||||||
// inference done by `photos/_plan.py`.
|
function parseCity(title: string): string | null {
|
||||||
function cityForTd(year: number, month: number, day: number): string {
|
|
||||||
const ymd = year * 10000 + month * 100 + day
|
|
||||||
if (ymd <= 20221231) return '珠海'
|
|
||||||
if (ymd <= 20240113) return '拉萨'
|
|
||||||
if (ymd <= 20260501) return '广州'
|
|
||||||
return '北京'
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCity(
|
|
||||||
title: string,
|
|
||||||
[year, month, day]: [number, number, number]
|
|
||||||
): string | null {
|
|
||||||
// Some original filenames contain the city name directly.
|
// Some original filenames contain the city name directly.
|
||||||
const namedCity = CITY_NAMES.find(name => title.includes(name))
|
const namedCity = CITY_NAMES.find(name => title.includes(name))
|
||||||
if (namedCity) return namedCity
|
if (namedCity) return namedCity
|
||||||
@@ -102,8 +92,6 @@ function parseCity(
|
|||||||
if (!codeMatch) return null
|
if (!codeMatch) return null
|
||||||
|
|
||||||
const code = codeMatch[1].toUpperCase()
|
const code = codeMatch[1].toUpperCase()
|
||||||
if (code === 'TD') return cityForTd(year, month, day)
|
|
||||||
|
|
||||||
return CITY_BY_CODE[code] ?? null
|
return CITY_BY_CODE[code] ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +108,6 @@ export function mediaCaption(title?: string | null): MediaCaption | null {
|
|||||||
const [year, month, day] = date
|
const [year, month, day] = date
|
||||||
return {
|
return {
|
||||||
date: `${year}/${pad(month)}/${pad(day)}`,
|
date: `${year}/${pad(month)}/${pad(day)}`,
|
||||||
city: parseCity(title, date),
|
city: parseCity(title),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user