Skip to content

Commit

Permalink
add campus package
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Sep 29, 2021
1 parent ccbe8e3 commit 1a9cbec
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
compile-all:
@make compile-gates
@make compile-galleries

compile-gates:
go run -mod vendor cmd/compile-gates-data/main.go

compile-galleries:
go run -mod vendor cmd/compile-galleries-data/main.go
87 changes: 87 additions & 0 deletions campus/campus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package campus

// type Campus is a lightweight data structure to represent the SFO campus with pointers its descendants.
type Campus struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
Complex *Complex `json:"complex"`
Garages []*Garage `json:"garages"`
// Buildings []*Building `json:"buildings,omitempty"`
PublicArt []*PublicArt `json:"buildings,omitempty"`
}

// type Garage is a lightweight data structure to represent garages at SFO with pointers its descendants.
type Garage struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
PublicArt []*PublicArt `json:"publicart"`
}

// type Complex is a lightweight data structure to represent the terminal complex at SFO with pointers its descendants.
type Complex struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
Terminals []*Terminal `json:"terminals"`
}

// type ObservationDeck is a lightweight data structure to represent observation decks at SFO with pointers its descendants.
type ObservationDeck struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
PublicArt []*PublicArt `json:"publicart"`
Galleries []*Gallery `json:"galleries"`
}

// type Terminal is a lightweight data structure to represent terminals at SFO with pointers its descendants.
type Terminal struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
CommonAreas []*CommonArea `json:"commonareas"`
BoardingAreas []*BoardingArea `json:"boardingareas"`
}

// type CommonArea is a lightweight data structure to represent common areas at SFO with pointers its descendants.
type CommonArea struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
Gates []*Gate `json:"gates"`
Checkpoints []*Checkpoint `json:"checkpoints"`
Galleries []*Gallery `json:"galleries"`
PublicArt []*PublicArt `json:"publicart"`
ObservationDecks []*ObservationDeck `json:"observationdecks"` // for example T2
}

// type BoardingArea is a lightweight data structure to represent boarding areas at SFO with pointers its descendants.
type BoardingArea struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
Gates []*Gate `json:"gates"`
Checkpoints []*Checkpoint `json:"checkpoints"`
Galleries []*Gallery `json:"galleries"`
PublicArt []*PublicArt `json:"publicart"`
ObservationDecks []*ObservationDeck `json:"observationdecks"`
}

// type Gallery is a lightweight data structure to represent SFO Museum galleries at SFO.
type Gallery struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfomuseum:id"`
}

// type Gate is a lightweight data structure to represent passenger gates at SFO.
type Gate struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
}

// type Checkpoint is a lightweight data structure to represent security checkpoints at SFO.
type Checkpoint struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfo:id"`
}

// type PublicArt is a lightweight data structure to represent public art works at SFO.
type PublicArt struct {
WhosOnFirstId int64 `json:"id"`
SFOMuseumId string `json:"sfomuseum:id"`
}
5 changes: 4 additions & 1 deletion cmd/compile-galleries-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"flag"
"fmt"
"github.com/sfomuseum/go-sfomuseum-architecture/galleries"
"io"
"log"
Expand All @@ -12,10 +13,12 @@ import (

func main() {

default_target := fmt.Sprintf("data/%s", galleries.DATA_JSON)

iterator_uri := flag.String("iterator-uri", "repo://?include=properties.sfomuseum:placetype=gallery", "A valid whosonfirst/go-whosonfirst-iterate URI")
iterator_source := flag.String("iterator-source", "/usr/local/data/sfomuseum-data-architecture", "The URI containing documents to iterate.")

target := flag.String("target", "data/galleries.json", "The path to write SFO Museum galleries data.")
target := flag.String("target", default_target, "The path to write SFO Museum galleries data.")
stdout := flag.Bool("stdout", false, "Emit SFO Museum galleries data to SDOUT.")

flag.Parse()
Expand Down
5 changes: 4 additions & 1 deletion cmd/compile-gates-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"flag"
"fmt"
"github.com/sfomuseum/go-sfomuseum-architecture/gates"
"io"
"log"
Expand All @@ -12,10 +13,12 @@ import (

func main() {

default_target := fmt.Sprintf("data/%s", gates.DATA_JSON)

iterator_uri := flag.String("iterator-uri", "repo://?include=properties.sfomuseum:placetype=gate", "A valid whosonfirst/go-whosonfirst-iterate URI")
iterator_source := flag.String("iterator-source", "/usr/local/data/sfomuseum-data-architecture", "The URI containing documents to iterate.")

target := flag.String("target", "data/gates.json", "The path to write SFO Museum gates data.")
target := flag.String("target", default_target, "The path to write SFO Museum gates data.")
stdout := flag.Bool("stdout", false, "Emit SFO Museum gates data to SDOUT.")

flag.Parse()
Expand Down
2 changes: 1 addition & 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.

54 changes: 48 additions & 6 deletions galleries/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import (
"github.com/sfomuseum/go-sfomuseum-architecture/data"
"io"
_ "log"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"sync/atomic"
)

const DATA_JSON string = "galleries.json"

var lookup_table *sync.Map
var lookup_idx int64

Expand All @@ -33,18 +37,56 @@ func init() {
lookup_idx = int64(0)
}

// NewLookup will return an `architecture.Lookup` instance derived from precompiled (embedded) data in `data/galleries.json`
// NewLookup will return an `architecture.Lookup` instance. By default the lookup table is derived from precompiled (embedded) data in `data/galleries.json`
// by passing in `sfomuseum://` as the URI. It is also possible to create a new lookup table with the following URI options:
// `sfomuseum://github`
// This will cause the lookup table to be derived from the data stored at https://raw.githubusercontent.com/sfomuseum/go-sfomuseum-architecture/main/data/galleries.json. This might be desirable if there have been updates to the underlying data that are not reflected in the locally installed package's pre-compiled data.
// `sfomuseum://iterator?uri={URI}&source={SOURCE}`
// This will cause the lookup table to be derived, at runtime, from data emitted by a `whosonfirst/go-whosonfirst-iterate` instance. `{URI}` should be a valid `whosonfirst/go-whosonfirst-iterate/iterator` URI and `{SOURCE}` is one or more URIs for the iterator to process.
func NewLookup(ctx context.Context, uri string) (architecture.Lookup, error) {

fs := data.FS
fh, err := fs.Open("galleries.json")
u, err := url.Parse(uri)

if err != nil {
return nil, fmt.Errorf("Failed to load data, %v", err)
return nil, fmt.Errorf("Failed to parse URI, %w", err)
}

lookup_func := NewLookupFuncWithReader(ctx, fh)
return NewLookupWithLookupFunc(ctx, lookup_func)
// Reminder: u.Scheme is used by the architecture.Lookup constructor

switch u.Host {
case "iterator":

q := u.Query()

iterator_uri := q.Get("uri")
iterator_sources := q["source"]

return NewLookupFromIterator(ctx, iterator_uri, iterator_sources...)

case "github":

data_url := fmt.Sprintf("https://raw.githubusercontent.com/sfomuseum/go-sfomuseum-architecture/main/data/%s", DATA_JSON)
rsp, err := http.Get(data_url)

if err != nil {
return nil, fmt.Errorf("Failed to load remote data from Github, %w", err)
}

lookup_func := NewLookupFuncWithReader(ctx, rsp.Body)
return NewLookupWithLookupFunc(ctx, lookup_func)

default:

fs := data.FS
fh, err := fs.Open(DATA_JSON)

if err != nil {
return nil, fmt.Errorf("Failed to load local precompiled data, %w", err)
}

lookup_func := NewLookupFuncWithReader(ctx, fh)
return NewLookupWithLookupFunc(ctx, lookup_func)
}
}

// NewLookup will return an `GalleriesLookupFunc` function instance that, when invoked, will populate an `architecture.Lookup` instance with data stored in `r`.
Expand Down
54 changes: 48 additions & 6 deletions gates/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import (
"github.com/sfomuseum/go-sfomuseum-architecture/data"
"io"
_ "log"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"sync/atomic"
)

const DATA_JSON string = "gates.json"

var lookup_table *sync.Map
var lookup_idx int64

Expand All @@ -33,18 +37,56 @@ func init() {
lookup_idx = int64(0)
}

// NewLookup will return an `architecture.Lookup` instance derived from precompiled (embedded) data in `data/gates.json`
// NewLookup will return an `architecture.Lookup` instance. By default the lookup table is derived from precompiled (embedded) data in `data/gates.json`
// by passing in `sfomuseum://` as the URI. It is also possible to create a new lookup table with the following URI options:
// `sfomuseum://github`
// This will cause the lookup table to be derived from the data stored at https://raw.githubusercontent.com/sfomuseum/go-sfomuseum-architecture/main/data/gates.json. This might be desirable if there have been updates to the underlying data that are not reflected in the locally installed package's pre-compiled data.
// `sfomuseum://iterator?uri={URI}&source={SOURCE}`
// This will cause the lookup table to be derived, at runtime, from data emitted by a `whosonfirst/go-whosonfirst-iterate` instance. `{URI}` should be a valid `whosonfirst/go-whosonfirst-iterate/iterator` URI and `{SOURCE}` is one or more URIs for the iterator to process.
func NewLookup(ctx context.Context, uri string) (architecture.Lookup, error) {

fs := data.FS
fh, err := fs.Open("gates.json")
u, err := url.Parse(uri)

if err != nil {
return nil, fmt.Errorf("Failed to load data, %v", err)
return nil, fmt.Errorf("Failed to parse URI, %w", err)
}

lookup_func := NewLookupFuncWithReader(ctx, fh)
return NewLookupWithLookupFunc(ctx, lookup_func)
// Reminder: u.Scheme is used by the architecture.Lookup constructor

switch u.Host {
case "iterator":

q := u.Query()

iterator_uri := q.Get("uri")
iterator_sources := q["source"]

return NewLookupFromIterator(ctx, iterator_uri, iterator_sources...)

case "github":

data_url := fmt.Sprintf("https://raw.githubusercontent.com/sfomuseum/go-sfomuseum-architecture/main/data/%s", DATA_JSON)
rsp, err := http.Get(data_url)

if err != nil {
return nil, fmt.Errorf("Failed to load remote data from Github, %w", err)
}

lookup_func := NewLookupFuncWithReader(ctx, rsp.Body)
return NewLookupWithLookupFunc(ctx, lookup_func)

default:

fs := data.FS
fh, err := fs.Open(DATA_JSON)

if err != nil {
return nil, fmt.Errorf("Failed to load local precompiled data, %w", err)
}

lookup_func := NewLookupFuncWithReader(ctx, fh)
return NewLookupWithLookupFunc(ctx, lookup_func)
}
}

// NewLookupWithReader will return an `GatesLookupFunc` function instance that, when invoked, will populate an `architecture.Lookup` instance with data stored in `r`.
Expand Down

0 comments on commit 1a9cbec

Please sign in to comment.