Commit 93bdd15e authored by Sonja Happ's avatar Sonja Happ
Browse files

add scalingFactor parameter to Signal data model #33

parent aea28c71
......@@ -107,6 +107,8 @@ type Signal struct {
Index uint `json:"index"`
// Direction of the signal (in or out)
Direction string `json:"direction"`
// Scaling factor for the signal raw value (defaults to 1.0)
ScalingFactor float32 `json:"scalingFactor" gorm:"default:1"`
// ID of Component Configuration
ConfigID uint `json:"configID"`
}
......
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2020-06-26 09:52:23.901926224 +0200 CEST m=+0.077245770
// 2020-06-26 10:15:00.429442173 +0200 CEST m=+0.087249443
package docs
......@@ -3149,6 +3149,10 @@ var doc = `{
"description": "Name of Signal",
"type": "string"
},
"scalingFactor": {
"description": "Scaling factor for the signal raw value (defaults to 1.0)",
"type": "number"
},
"unit": {
"description": "Unit of Signal",
"type": "string"
......@@ -3600,6 +3604,9 @@ var doc = `{
"Name": {
"type": "string"
},
"ScalingFactor": {
"type": "number"
},
"Unit": {
"type": "string"
}
......@@ -3614,6 +3621,9 @@ var doc = `{
"Name": {
"type": "string"
},
"ScalingFactor": {
"type": "number"
},
"Unit": {
"type": "string"
}
......
......@@ -3132,6 +3132,10 @@
"description": "Name of Signal",
"type": "string"
},
"scalingFactor": {
"description": "Scaling factor for the signal raw value (defaults to 1.0)",
"type": "number"
},
"unit": {
"description": "Unit of Signal",
"type": "string"
......@@ -3583,6 +3587,9 @@
"Name": {
"type": "string"
},
"ScalingFactor": {
"type": "number"
},
"Unit": {
"type": "string"
}
......@@ -3597,6 +3604,9 @@
"Name": {
"type": "string"
},
"ScalingFactor": {
"type": "number"
},
"Unit": {
"type": "string"
}
......
......@@ -208,6 +208,9 @@ definitions:
name:
description: Name of Signal
type: string
scalingFactor:
description: Scaling factor for the signal raw value (defaults to 1.0)
type: number
unit:
description: Unit of Signal
type: string
......@@ -508,6 +511,8 @@ definitions:
type: integer
Name:
type: string
ScalingFactor:
type: number
Unit:
type: string
required:
......@@ -522,6 +527,8 @@ definitions:
type: integer
Name:
type: string
ScalingFactor:
type: number
Unit:
type: string
type: object
......
......@@ -87,9 +87,10 @@ func (s *Signal) update(modifiedSignal Signal) error {
db := database.GetDB()
err := db.Model(s).Updates(map[string]interface{}{
"Name": modifiedSignal.Name,
"Unit": modifiedSignal.Unit,
"Index": modifiedSignal.Index,
"Name": modifiedSignal.Name,
"Unit": modifiedSignal.Unit,
"Index": modifiedSignal.Index,
"ScalingFactor": modifiedSignal.ScalingFactor,
}).Error
return err
......
......@@ -40,11 +40,12 @@ import (
var router *gin.Engine
type SignalRequest struct {
Name string `json:"name,omitempty"`
Unit string `json:"unit,omitempty"`
Index uint `json:"index,omitempty"`
Direction string `json:"direction,omitempty"`
ConfigID uint `json:"configID,omitempty"`
Name string `json:"name,omitempty"`
Unit string `json:"unit,omitempty"`
Index uint `json:"index,omitempty"`
Direction string `json:"direction,omitempty"`
ScalingFactor float32 `json:"scalingFactor,omitempty"`
ConfigID uint `json:"configID,omitempty"`
}
type ConfigRequest struct {
......
......@@ -28,17 +28,19 @@ import (
var validate *validator.Validate
type validNewSignal struct {
Name string `form:"Name" validate:"required"`
Unit string `form:"unit" validate:"omitempty"`
Index uint `form:"index" validate:"required"`
Direction string `form:"direction" validate:"required,oneof=in out"`
ConfigID uint `form:"configID" validate:"required"`
Name string `form:"Name" validate:"required"`
Unit string `form:"unit" validate:"omitempty"`
Index uint `form:"index" validate:"required"`
Direction string `form:"direction" validate:"required,oneof=in out"`
ScalingFactor float32 `form:"scalingFactor" validate:"omitempty"`
ConfigID uint `form:"configID" validate:"required"`
}
type validUpdatedSignal struct {
Name string `form:"Name" validate:"omitempty"`
Unit string `form:"unit" validate:"omitempty"`
Index uint `form:"index" validate:"omitempty"`
Name string `form:"Name" validate:"omitempty"`
Unit string `form:"unit" validate:"omitempty"`
Index uint `form:"index" validate:"omitempty"`
ScalingFactor float32 `form:"scalingFactor" validate:"omitempty"`
}
type addSignalRequest struct {
......@@ -68,6 +70,7 @@ func (r *addSignalRequest) createSignal() Signal {
s.Unit = r.Signal.Unit
s.Index = r.Signal.Index
s.Direction = r.Signal.Direction
s.ScalingFactor = r.Signal.ScalingFactor
s.ConfigID = r.Signal.ConfigID
return s
......@@ -90,5 +93,10 @@ func (r *updateSignalRequest) updatedSignal(oldSignal Signal) Signal {
s.Unit = r.Signal.Unit
}
if r.Signal.ScalingFactor != 0 {
// scaling factor of 0 is not allowed
s.ScalingFactor = r.Signal.ScalingFactor
}
return s
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment