Skip to content

Commit f30f613

Browse files
authored
#111 - make feaures list a compact list of floors per feature (#112)
make feaures list a compact list of floors per feature
1 parent 19a0798 commit f30f613

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

core/model/buildings.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type Building struct {
5151
Latitude float64
5252
Longitude float64
5353
Floors []string
54-
Features []BuildingFeature
54+
Features []BuildingFeatureLocation
5555
}
5656

5757
// CompactBuilding represents minimal building informaiton needed to display a builgins details on the details panel
@@ -63,6 +63,19 @@ type CompactBuilding struct {
6363
ImageURL string
6464
Latitude float64
6565
Longitude float64
66+
Features []BuildingFeatureLocation
67+
}
68+
69+
// BuildingFeatureLocation represents a list of where each feature belonging to a building can be found
70+
type BuildingFeatureLocation struct {
71+
Key string `json:"key" bson:"key"`
72+
Value FeatureMapEntry `json:"value" bson:"value"`
73+
}
74+
75+
// FeatureMapEntry represents the floor data associated with a feature key for a building
76+
type FeatureMapEntry struct {
77+
Name string `json:"name" bson:"name"`
78+
Floors []string `json:"floors" bson:"floors"`
6679
}
6780

6881
// BuildingFeature represents a feature found in buildings

core/model/uiuc/buildingdata.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package uiuc
1616

1717
import (
1818
model "application/core/model"
19+
"slices"
1920
"strconv"
2021
)
2122

@@ -153,9 +154,28 @@ func NewBuilding(bldg CampusBuilding) *model.Building {
153154
}
154155

155156
newBldg.Floors = append(newBldg.Floors, bldg.Floors...)
157+
var featuredata = make(map[string]model.FeatureMapEntry, 0)
158+
156159
for _, n := range bldg.Features {
157160

158-
newBldg.Features = append(newBldg.Features, *NewFeature(n))
161+
val, ok := featuredata[n.EQIndicator]
162+
if ok {
163+
if !slices.Contains(val.Floors, n.FoundOnFloor) {
164+
val.Floors = append(val.Floors, n.FoundOnFloor)
165+
featuredata[n.EQIndicator] = val
166+
}
167+
168+
} else {
169+
var floors = make([]string, 1)
170+
floors[0] = n.FoundOnFloor
171+
fme := model.FeatureMapEntry{Name: n.Name, Floors: floors}
172+
featuredata[n.EQIndicator] = fme
173+
}
174+
//newBldg.Features = append(newBldg.Features, *NewFeature(n))
175+
}
176+
for key, value := range featuredata {
177+
var feature = model.BuildingFeatureLocation{Key: key, Value: value}
178+
newBldg.Features = append(newBldg.Features, feature)
159179
}
160180

161181
return &newBldg
@@ -184,3 +204,5 @@ func NewFeature(f CampusBuildingFeature) *model.BuildingFeature {
184204
IsADA: f.IsADA, IsExternal: f.IsExternal, Latitude: f.Latitude, Longitude: f.Longitude, Comments: f.Comments}
185205
return &newFeature
186206
}
207+
208+
// AddToFeatureMap adds the features floor and name

0 commit comments

Comments
 (0)