Skip to content

Commit

Permalink
Better location tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
zach-capalbo committed Apr 29, 2023
1 parent 1fd4f6d commit b7cbb32
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
10 changes: 8 additions & 2 deletions internal/image/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"sync"
"time"
"math"

"photofield/internal/clip"
"photofield/internal/metrics"
Expand Down Expand Up @@ -303,8 +304,13 @@ func (source *Database) writePendingInfosSqlite() {
updateMeta.BindInt64(4, (int64)(imageInfo.Orientation))
updateMeta.BindInt64(5, imageInfo.DateTime.Unix())
updateMeta.BindInt64(6, int64(timezoneOffsetSeconds/60))
updateMeta.BindFloat(7, imageInfo.Latitude)
updateMeta.BindFloat(8, imageInfo.Longitude)
if math.IsNaN(imageInfo.Latitude) {
updateMeta.BindNull(7)
updateMeta.BindNull(8)
} else {
updateMeta.BindFloat(7, imageInfo.Latitude)
updateMeta.BindFloat(8, imageInfo.Longitude)
}
updateMeta.BindText(9, imageInfo.Location)
updateMeta.BindText(10, dir)

Expand Down
4 changes: 3 additions & 1 deletion internal/image/indexMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func (source *Source) indexMetadata(in <-chan interface{}) {
fmt.Println("RGEO ERR", err)
}
fmt.Println("RGeo", loc.City, loc.Province, loc.Country)
if loc.City != "" {
if loc.City == "" && loc.Country == "" {
info.Location = ""
} else if loc.City != "" {
info.Location = fmt.Sprintf("%s, %s, %s", loc.City, loc.Province, loc.Country)
} else {
info.Location = fmt.Sprintf("%s, %s", loc.Province, loc.Country)
Expand Down
21 changes: 20 additions & 1 deletion internal/layout/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,32 @@ func LayoutTimeline(layout Layout, collection collection.Collection, scene *rend
Interval: 1 * time.Second,
}

locations := make(map[string]bool)

index := 0
for info := range infos {
event.Location = event.Location + info.Location
if limit > 0 && index >= limit {
break
}

if info.Location != "" {
locations[info.Location] = true
}

photoTime := info.DateTime
elapsed := lastPhotoTime.Sub(photoTime)
if elapsed > 30*time.Minute {
event.StartTime = lastPhotoTime
for location := range locations {
if event.Location != "" {
event.Location = event.Location + ", " + location
} else {
event.Location = location
}
}

locations = make(map[string]bool)

rect = LayoutTimelineEvent(layout, rect, &event, scene, source)
eventCount++
event = TimelineEvent{
Expand All @@ -135,6 +149,11 @@ func LayoutTimeline(layout Layout, collection collection.Collection, scene *rend

if len(event.Section.infos) > 0 {
event.StartTime = lastPhotoTime
for location := range locations {
event.Location = event.Location + ", " + location
}

locations = make(map[string]bool)
rect = LayoutTimelineEvent(layout, rect, &event, scene, source)
eventCount++
}
Expand Down

0 comments on commit b7cbb32

Please sign in to comment.