Metadata: Never estimate when place was set otherwise #1668
This commit is contained in:
parent
cba8bd6164
commit
9ddd853234
6 changed files with 119 additions and 17 deletions
|
@ -2,7 +2,7 @@ PhotoPrism: Browse Your Life in Pictures
|
|||
========================================
|
||||
|
||||
[][license]
|
||||
[][ci]
|
||||

|
||||
[](https://github.com/photoprism/photoprism/graphs/contributors/)
|
||||
[][docs]
|
||||
[][chat]
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
// EstimateCountry updates the photo with an estimated country if possible.
|
||||
func (m *Photo) EstimateCountry() {
|
||||
if m.HasLocation() || m.HasPlace() || m.HasCountry() && m.PlaceSrc != SrcAuto && m.PlaceSrc != SrcEstimate {
|
||||
if SrcPriority[m.PlaceSrc] > SrcPriority[SrcEstimate] || m.HasLocation() || m.HasPlace() {
|
||||
// Do nothing.
|
||||
return
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ func (m *Photo) EstimateCountry() {
|
|||
|
||||
// EstimatePlace updates the photo with an estimated place and country if possible.
|
||||
func (m *Photo) EstimatePlace(force bool) {
|
||||
if m.HasLocation() || m.HasPlace() && m.PlaceSrc != SrcAuto && m.PlaceSrc != SrcEstimate {
|
||||
// Don't estimate if location is known.
|
||||
if SrcPriority[m.PlaceSrc] > SrcPriority[SrcEstimate] || m.HasLocation() {
|
||||
// Don't estimate if location is known or set otherwise.
|
||||
return
|
||||
} else if force || m.EstimatedAt == nil {
|
||||
// Proceed.
|
||||
|
|
|
@ -1714,6 +1714,72 @@ var PhotoFixtures = PhotoMap{
|
|||
PhotoStack: IsStackable,
|
||||
PhotoFaces: 3,
|
||||
},
|
||||
"EstimateTimeZone": {
|
||||
ID: 1000028,
|
||||
PhotoUID: "pr2xmef3ki00x54g", // 2015-05-17T23:02:46Z
|
||||
TakenAt: time.Date(2015, 5, 17, 23, 2, 46, 0, time.UTC),
|
||||
TakenAtLocal: time.Date(2015, 5, 17, 23, 2, 46, 0, time.UTC),
|
||||
TakenSrc: SrcMeta,
|
||||
PhotoType: "image",
|
||||
TypeSrc: "",
|
||||
PhotoTitle: "Estimate / 2015",
|
||||
TitleSrc: SrcName,
|
||||
PhotoDescription: "",
|
||||
DescriptionSrc: "",
|
||||
PhotoPath: "2015/05",
|
||||
PhotoName: "Estimate",
|
||||
OriginalName: "",
|
||||
PhotoFavorite: false,
|
||||
PhotoPrivate: false,
|
||||
PhotoScan: false,
|
||||
PhotoPanorama: false,
|
||||
TimeZone: "",
|
||||
Place: &UnknownPlace,
|
||||
PlaceID: UnknownPlace.ID,
|
||||
PlaceSrc: SrcAuto,
|
||||
Cell: nil,
|
||||
CellID: UnknownPlace.ID,
|
||||
CellAccuracy: 0,
|
||||
PhotoAltitude: 0,
|
||||
PhotoLat: 0,
|
||||
PhotoLng: 0,
|
||||
PhotoCountry: UnknownCountry.ID,
|
||||
PhotoYear: 2015,
|
||||
PhotoMonth: 5,
|
||||
PhotoDay: 17,
|
||||
PhotoIso: 100,
|
||||
PhotoExposure: "1/50",
|
||||
PhotoFNumber: 2.6,
|
||||
PhotoFocalLength: 3,
|
||||
PhotoQuality: 3,
|
||||
PhotoResolution: 0,
|
||||
Camera: CameraFixtures.Pointer("canon-eos-6d"),
|
||||
CameraID: CameraFixtures.Pointer("canon-eos-6d").ID,
|
||||
CameraSerial: "",
|
||||
CameraSrc: "",
|
||||
Lens: LensFixtures.Pointer("lens-f-380"),
|
||||
LensID: LensFixtures.Pointer("lens-f-380").ID,
|
||||
Details: &Details{
|
||||
PhotoID: 1000028,
|
||||
CreatedAt: TimeStamp(),
|
||||
UpdatedAt: TimeStamp(),
|
||||
},
|
||||
Keywords: []Keyword{},
|
||||
Albums: []Album{},
|
||||
Files: []File{},
|
||||
Labels: []PhotoLabel{
|
||||
LabelFixtures.PhotoLabel(10000018, "landscape", 20, "image"),
|
||||
LabelFixtures.PhotoLabel(10000018, "likeLabel", 20, "image")},
|
||||
CreatedAt: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
UpdatedAt: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
EditedAt: nil,
|
||||
CheckedAt: nil,
|
||||
EstimatedAt: nil,
|
||||
DeletedAt: nil,
|
||||
PhotoColor: 12,
|
||||
PhotoStack: IsStackable,
|
||||
PhotoFaces: 0,
|
||||
},
|
||||
}
|
||||
|
||||
// CreatePhotoFixtures inserts known entities into the database for testing.
|
||||
|
|
|
@ -28,7 +28,8 @@ func (m *Photo) Optimize(mergeMeta, mergeUuid, estimatePlace, force bool) (updat
|
|||
return false, photos, nil
|
||||
}
|
||||
|
||||
if estimatePlace {
|
||||
// Estimate if feature is enabled and place wasn't set otherwise.
|
||||
if estimatePlace && SrcPriority[m.PlaceSrc] <= SrcPriority[SrcEstimate] {
|
||||
m.EstimatePlace(force)
|
||||
}
|
||||
|
||||
|
|
|
@ -395,6 +395,41 @@ func TestPhoto_SetTakenAt(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPhoto_UpdateTimeZone(t *testing.T) {
|
||||
t.Run("Estimate", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("EstimateTimeZone")
|
||||
|
||||
takenLocal := time.Date(2015, time.May, 17, 23, 2, 46, 0, time.UTC)
|
||||
takenJerusalemUtc := time.Date(2015, time.May, 17, 20, 2, 46, 0, time.UTC)
|
||||
takenShanghaiUtc := time.Date(2015, time.May, 17, 15, 2, 46, 0, time.UTC)
|
||||
|
||||
assert.Equal(t, "", m.TimeZone)
|
||||
assert.Equal(t, takenLocal, m.TakenAt)
|
||||
assert.Equal(t, takenLocal, m.TakenAtLocal)
|
||||
|
||||
zone1 := "Asia/Jerusalem"
|
||||
|
||||
m.UpdateTimeZone(zone1)
|
||||
|
||||
assert.Equal(t, zone1, m.TimeZone)
|
||||
assert.Equal(t, takenJerusalemUtc, m.TakenAt)
|
||||
assert.Equal(t, takenLocal, m.TakenAtLocal)
|
||||
|
||||
zone2 := "Asia/Shanghai"
|
||||
|
||||
m.UpdateTimeZone(zone2)
|
||||
|
||||
assert.Equal(t, zone2, m.TimeZone)
|
||||
assert.Equal(t, takenShanghaiUtc, m.TakenAt)
|
||||
assert.Equal(t, takenLocal, m.TakenAtLocal)
|
||||
|
||||
zone3 := "UTC"
|
||||
|
||||
m.UpdateTimeZone(zone3)
|
||||
|
||||
assert.Equal(t, zone2, m.TimeZone)
|
||||
assert.Equal(t, takenShanghaiUtc, m.TakenAt)
|
||||
assert.Equal(t, takenLocal, m.TakenAtLocal)
|
||||
})
|
||||
t.Run("UTC", func(t *testing.T) {
|
||||
m := PhotoFixtures.Get("Photo12")
|
||||
m.TimeZone = "UTC"
|
||||
|
|
|
@ -6,18 +6,18 @@ type Priorities map[string]int
|
|||
|
||||
// Data source names.
|
||||
const (
|
||||
SrcAuto = ""
|
||||
SrcDefault = "default"
|
||||
SrcManual = "manual"
|
||||
SrcEstimate = "estimate"
|
||||
SrcName = "name"
|
||||
SrcMeta = "meta"
|
||||
SrcXmp = "xmp"
|
||||
SrcYaml = "yaml"
|
||||
SrcMarker = "marker"
|
||||
SrcImage = classify.SrcImage
|
||||
SrcKeyword = classify.SrcKeyword
|
||||
SrcLocation = classify.SrcLocation
|
||||
SrcAuto = "" // Prio 1
|
||||
SrcDefault = "default" // Prio 1
|
||||
SrcEstimate = "estimate" // Prio 2
|
||||
SrcName = "name" // Prio 4
|
||||
SrcYaml = "yaml" // Prio 8
|
||||
SrcLocation = classify.SrcLocation // Prio 8
|
||||
SrcMarker = "marker" // Prio 8
|
||||
SrcImage = classify.SrcImage // Prio 8
|
||||
SrcKeyword = classify.SrcKeyword // Prio 16
|
||||
SrcMeta = "meta" // Prio 16
|
||||
SrcXmp = "xmp" // Prio 32
|
||||
SrcManual = "manual" // Prio 64
|
||||
)
|
||||
|
||||
// SrcString returns a source string for logging.
|
||||
|
|
Loading…
Add table
Reference in a new issue