Skip to content

Commit

Permalink
Galleries dates (#4)
Browse files Browse the repository at this point in the history
* snapshot: add tests that fail to work out date wrangling for galleries

* bug fix: don't break when appending matches; still some date issues to sort out

* snapshot: filter galleries down to current galleries; still need to sort multiple gallery records with the same ID/name (AML 06 AML Photography)

* improved tests for galleries; handle overlapping gallery dates better; recompile data

---------

Co-authored-by: sfomuseumbot <sfomuseumbot@localhost>
  • Loading branch information
thisisaaronland and sfomuseumbot authored Jul 26, 2024
1 parent add3512 commit a867c9f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
3 changes: 2 additions & 1 deletion data/galleries.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/gates.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/terminals.json

Large diffs are not rendered by default.

56 changes: 54 additions & 2 deletions galleries/galleries.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,61 @@ func FindAllGalleriesForDateWithLookup(ctx context.Context, lookup architecture.
continue
}

slog.Debug("Gallery DOES match date conditions", "code", code, "date", date, "gallery", g.Name, "inception", inception, "cessation", cessation)
slog.Debug("Gallery DOES match date conditions", "code", code, "date", date, "gallery id", g.WhosOnFirstId, "gallery", g.Name, "inception", inception, "cessation", cessation)
galleries = append(galleries, g)
break
}

if len(galleries) > 1 {

/*
Given the following scenario:
2024/07/26 15:50:27 DEBUG Gallery DOES match date conditions code=42 date=2024-06-17 "gallery id"=1914589529 gallery="AML 06 AML Photography" inception=2021-11-09 cessation=2024-06-17
2024/07/26 15:50:27 DEBUG Gallery DOES match date conditions code=42 date=2024-06-17 "gallery id"=1914601189 gallery="AML 06 AML Photography" inception=2024-06-17 cessation=..
Where, by virtue of 2024-06-17 being "between" the end date of one gallery and the start date of another, then
filter out matches that are not considered to be "current".
*/

current_galleries := make([]*Gallery, 0)

for _, g := range galleries {

if g.IsCurrent == 1 {
current_galleries = append(current_galleries, g)
}
}

if len(current_galleries) > 0 {
galleries = current_galleries
} else {

/*
But wait, there's more. What if the same situation exists (matching inception/cessation dates) but
none of the candidate galleries are "current" ? In that situation give precedence to records whose
inception date matches the date being queried against.
2024/07/26 16:07:56 DEBUG Gallery DOES match date conditions code=3 date=2021-11-09 "gallery id"=1745882483 gallery="3E Gate 76" inception=2021-05-25 cessation=2021-11-09
2024/07/26 16:07:56 DEBUG Gallery DOES match date conditions code=3 date=2021-11-09 "gallery id"=1763588523 gallery="F-03 Gate 76" inception=2021-11-09 cessation=2024-06-17
*/

starting_galleries := make([]*Gallery, 0)

for _, g := range galleries {

if g.Inception == date {
starting_galleries = append(starting_galleries, g)
}
}

if len(starting_galleries) > 0 {
galleries = starting_galleries
}
}
}

slog.Debug("Return galleries", "code", code, "date", date, "count", len(galleries))
Expand Down
11 changes: 10 additions & 1 deletion galleries/galleries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ func TestFindGalleryForDate(t *testing.T) {
&galleryTest{Id: 1914650743, Code: "1G", Date: "2024-07-23"},
&galleryTest{Id: 1914600907, Code: "3F", Date: "2024-06-18"},
&galleryTest{Id: 1360392589, Code: "F04", Date: "2002"},
// &galleryTest{Id: 1159157059, Code: "F-04", Date: "2017-12~"},
&galleryTest{Id: 1914601189, Code: "42", Date: "2024-06-17"},
&galleryTest{Id: 1360516127, Code: "2", Date: "1998-01-16"},
&galleryTest{Id: 1763588523, Code: "3", Date: "2021-11-09"},
// This test is known/expected to fail until it is determined
// how to handle this. It is entirely possible that there is
// no good way to deal with this in an automated fashion and
// it simply requires human intervention.
// 2024/07/26 16:25:58 DEBUG Gallery DOES match date conditions code=3 date=2011-09-01 "gallery id"=1360516141 gallery="F-03 Gate 76" inception=2006~ cessation=2011~
// 2024/07/26 16:25:58 DEBUG Gallery DOES match date conditions code=3 date=2011-09-01 "gallery id"=1360516139 gallery="F-03 Gate 76" inception=2011~ cessation=2014~
// &galleryTest{Id: 1360541671, Code: "3", Date: "2011-09-01"},
}

ctx := context.Background()
Expand Down

0 comments on commit a867c9f

Please sign in to comment.