summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-11-21 16:52:43 -0500
committerSam Anthony <sam@samanthony.xyz>2024-11-21 16:52:43 -0500
commit2f36b360a55d07cd9f087e8202e3ba4fb2d7f874 (patch)
treeab9a3229ccffe824c45a5a7138d81a1e8ce972f2 /server
parentdbc71139a5708b371ffb0b7580f562674707c558 (diff)
downloadsoen422-2f36b360a55d07cd9f087e8202e3ba4fb2d7f874.zip
server dashboard: sort by room id
Diffstat (limited to 'server')
-rw-r--r--server/dashboard.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/server/dashboard.go b/server/dashboard.go
index 0e9cd41..3fc9f88 100644
--- a/server/dashboard.go
+++ b/server/dashboard.go
@@ -17,8 +17,8 @@ const dashboardHtml = `
<p>Average humidity: {{ printf "%.1f %%" .Average }}</p>
<table>
<tr><th>Room</th><th>Humidity</th></tr>
- {{ range .Rooms }}
- <tr><td>{{ .RoomID }}</td><td>{{ printf "%.1f %%" .Humidity }}</td></tr>
+ {{ range $id, $humidity := .Rooms }}
+ <tr><td>{{ $id }}</td><td>{{ printf "%.1f %%" $humidity }}</td></tr>
{{ end }}
</table>
</body>
@@ -28,12 +28,7 @@ var dashboard = template.Must(template.New("dashboard").Parse(dashboardHtml))
type Dashboard struct {
Average Humidity
- Rooms []Room
-}
-
-type Room struct {
- RoomID
- Humidity
+ Rooms map[RoomID]Humidity
}
type DashboardHandler struct {
@@ -62,8 +57,7 @@ func newDashboard(b Building) Dashboard {
average = -1
}
- // TODO: sort by room ID.
- rooms := make([]Room, 0, len(b))
+ rooms := make(map[RoomID]Humidity)
for id, record := range b {
c := make(chan Humidity)
record.getRecent <- c
@@ -71,7 +65,7 @@ func newDashboard(b Building) Dashboard {
if !ok {
humidity = -1
}
- rooms = append(rooms, Room{id, humidity})
+ rooms[id] = humidity
}
return Dashboard{average, rooms}