Files
old-backend/models/device_info.go

95 lines
2.6 KiB
Go
Raw Normal View History

2023-09-12 18:28:18 +02:00
package models
// Location holds latitude and longitude.
type Location struct {
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
}
// ImportantInfo holds fields that are important for quick access.
type SensorData struct {
2023-10-13 11:48:14 +02:00
IMEI string `json:"imei"`
IMSI string `json:"imsi"`
Timestamp int64 `json:"timestamp"`
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
WifiLoc Location `json:"wifiLocation"`
CellLoc Location `json:"cellLocation"`
Temperature float64 `json:"temperature"`
AccInfo AccelerometerInfo `json:"accelerometerInfo"`
2023-09-19 08:15:42 +02:00
AccelerometerInfo
2023-09-12 18:28:18 +02:00
}
type DeviceInfo struct {
2023-10-13 11:48:14 +02:00
BaseModel
2023-09-12 18:28:18 +02:00
RawJSON string `json:"raw_json" gorm:"type:json"`
2023-09-18 12:27:40 +02:00
SensorData
2023-10-13 11:48:14 +02:00
DeviceID uint
2023-09-19 08:15:42 +02:00
ExternalDeviceID string `json:"deviceId"`
2023-09-12 18:28:18 +02:00
}
2023-10-06 10:47:26 +02:00
type DeviceInfoResponse struct {
BaseModel
RawJSON string `json:"rawJson" gorm:"type:json"`
SensorData
2023-10-13 11:48:14 +02:00
DeviceID uint `json:"deviceId"`
2023-10-06 10:47:26 +02:00
ExternalDeviceID string `json:"externalDeviceId"`
}
type NormalAndBreachedDevicesResponse struct {
Breached int64 `json:"breached"`
Normal int64 `json:"normal"`
MonthlyCounts map[string]map[string]int64 `json:"monthly_counts"`
}
2023-10-06 10:47:26 +02:00
func ConvertDeviceInfoToResponse(deviceInfos []DeviceInfo) []DeviceInfoResponse {
var deviceInfoResponses []DeviceInfoResponse
for _, deviceInfo := range deviceInfos {
deviceInfoResponse := DeviceInfoResponse{
BaseModel: BaseModel{
ID: deviceInfo.ID,
CreatedAt: deviceInfo.CreatedAt,
UpdatedAt: deviceInfo.UpdatedAt,
},
RawJSON: deviceInfo.RawJSON,
2023-10-13 11:48:14 +02:00
SensorData: deviceInfo.SensorData,
2023-10-06 10:47:26 +02:00
DeviceID: deviceInfo.DeviceID,
ExternalDeviceID: deviceInfo.ExternalDeviceID,
}
deviceInfoResponses = append(deviceInfoResponses, deviceInfoResponse)
}
return deviceInfoResponses
2023-09-19 08:15:42 +02:00
}
2023-10-06 10:47:26 +02:00
type AccelerometerInfo struct {
X int64 `json:"x"`
Y int64 `json:"y"`
Z int64 `json:"z"`
}
2023-09-19 08:15:42 +02:00
type GeoJSONFeatureCollection struct {
Type string `json:"type"`
Features []GeoJSONFeature `json:"features"`
}
type GeoJSONFeature struct {
2023-10-13 11:48:14 +02:00
Type string `json:"type"`
Geometry GeoJSONGeometry `json:"geometry"`
DeviceInfoResponse *DeviceInfoResponse `json:"deviceInfo,omitempty"`
Properties map[string]interface{} `json:"properties"`
2023-09-19 08:15:42 +02:00
}
type GeoJSONGeometry struct {
Type string `json:"type"`
Coordinates []float64 `json:"coordinates"`
}
2023-09-18 12:27:40 +02:00
func (DeviceInfo) Update() (bool, error) {
2023-09-12 18:28:18 +02:00
return false, nil
}
2023-09-18 12:27:40 +02:00
func (DeviceInfo) Create() (bool, error) {
2023-09-12 18:28:18 +02:00
return false, nil
}
2023-09-18 12:27:40 +02:00
func (DeviceInfo) Delete() (bool, error) {
2023-09-12 18:28:18 +02:00
return false, nil
}