Remove duplicate device name

Display "dev" for "dev/dev" device names.
This commit is contained in:
Felix Niederwanger 2022-01-05 20:54:40 +01:00
parent 0385389252
commit a1381b2d1a
Signed by: phoenix
GPG key ID: 6E77A590E3F6D71C

View file

@ -187,8 +187,20 @@ func timeDeltastr(now int64, tsmp int64) string {
}
}
}
t_unix := time.Unix(tsmp, 0)
return t_unix.Format("2006-01-02-15:04:05")
tUnix := time.Unix(tsmp, 0)
return tUnix.Format("2006-01-02-15:04:05")
}
func nameFormat(name string) string {
// Return "dev" for names like "dev/dev"
i := strings.Index(name, "/")
if i > 0 && i < (len(name)-1) {
left, right := name[:i], name[i+1:]
if left == right {
return left
}
}
return name
}
func handlerLocations(w http.ResponseWriter, r *http.Request) {
@ -196,7 +208,7 @@ func handlerLocations(w http.ResponseWriter, r *http.Request) {
now := time.Now().Unix()
for dev, loc := range devices {
point := CreatePoint(loc.Lon, loc.Lat)
point.Properties["name"] = dev
point.Properties["name"] = nameFormat(dev)
point.Properties["id"] = dev
point.Properties["time"] = fmt.Sprintf("%d", loc.Timestamp)
point.Properties["altitude"] = fmt.Sprintf("%f", loc.Alt)