diff --git a/core/model/buildings.go b/core/model/buildings.go index 1a56968..8ebbca0 100644 --- a/core/model/buildings.go +++ b/core/model/buildings.go @@ -51,7 +51,7 @@ type Building struct { Latitude float64 Longitude float64 Floors []string - Features []BuildingFeature + Features []BuildingFeatureLocation } // CompactBuilding represents minimal building informaiton needed to display a builgins details on the details panel @@ -63,6 +63,19 @@ type CompactBuilding struct { ImageURL string Latitude float64 Longitude float64 + Features []BuildingFeatureLocation +} + +// BuildingFeatureLocation represents a list of where each feature belonging to a building can be found +type BuildingFeatureLocation struct { + Key string `json:"key" bson:"key"` + Value FeatureMapEntry `json:"value" bson:"value"` +} + +// FeatureMapEntry represents the floor data associated with a feature key for a building +type FeatureMapEntry struct { + Name string `json:"name" bson:"name"` + Floors []string `json:"floors" bson:"floors"` } // BuildingFeature represents a feature found in buildings diff --git a/core/model/uiuc/buildingdata.go b/core/model/uiuc/buildingdata.go index 480db71..f72e033 100644 --- a/core/model/uiuc/buildingdata.go +++ b/core/model/uiuc/buildingdata.go @@ -16,6 +16,7 @@ package uiuc import ( model "application/core/model" + "slices" "strconv" ) @@ -153,9 +154,28 @@ func NewBuilding(bldg CampusBuilding) *model.Building { } newBldg.Floors = append(newBldg.Floors, bldg.Floors...) + var featuredata = make(map[string]model.FeatureMapEntry, 0) + for _, n := range bldg.Features { - newBldg.Features = append(newBldg.Features, *NewFeature(n)) + val, ok := featuredata[n.EQIndicator] + if ok { + if !slices.Contains(val.Floors, n.FoundOnFloor) { + val.Floors = append(val.Floors, n.FoundOnFloor) + featuredata[n.EQIndicator] = val + } + + } else { + var floors = make([]string, 1) + floors[0] = n.FoundOnFloor + fme := model.FeatureMapEntry{Name: n.Name, Floors: floors} + featuredata[n.EQIndicator] = fme + } + //newBldg.Features = append(newBldg.Features, *NewFeature(n)) + } + for key, value := range featuredata { + var feature = model.BuildingFeatureLocation{Key: key, Value: value} + newBldg.Features = append(newBldg.Features, feature) } return &newBldg @@ -184,3 +204,5 @@ func NewFeature(f CampusBuildingFeature) *model.BuildingFeature { IsADA: f.IsADA, IsExternal: f.IsExternal, Latitude: f.Latitude, Longitude: f.Longitude, Comments: f.Comments} return &newFeature } + +// AddToFeatureMap adds the features floor and name