Additional display value in card : GWM
This commit is contained in:
parent
f8135bfb8f
commit
932ff77bd1
2
main.go
2
main.go
@ -1899,7 +1899,7 @@ func sendStatusChangeEmail(app *pocketbase.PocketBase, record *models.Record, ne
|
|||||||
body = fmt.Sprintf(`
|
body = fmt.Sprintf(`
|
||||||
<p>Dear %s,</p>
|
<p>Dear %s,</p>
|
||||||
<p>We are pleased to inform you that your registration with FCSC has been approved. You can now log in using the credentials that you had created.</p>
|
<p>We are pleased to inform you that your registration with FCSC has been approved. You can now log in using the credentials that you had created.</p>
|
||||||
<p>Please access your account using the following link: <a href="http://your-login-url.com">"Access Your Account</a>.</p>
|
<p>Please access your account using the following link: <a href="http://your-login-url.com"> Access Your Account</a>.</p>
|
||||||
<p>If you have any questions, please feel free to contact us for further clarification.</p>
|
<p>If you have any questions, please feel free to contact us for further clarification.</p>
|
||||||
</br>
|
</br>
|
||||||
<p>Best regards,</p>
|
<p>Best regards,</p>
|
||||||
|
|||||||
BIN
pb_data/data.db
BIN
pb_data/data.db
Binary file not shown.
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
@ -20,12 +20,13 @@ type Observation struct {
|
|||||||
|
|
||||||
// ------------------------------------------------------------ card calculation---------------------------------------------------
|
// ------------------------------------------------------------ card calculation---------------------------------------------------
|
||||||
type CardCalculationRequest struct {
|
type CardCalculationRequest struct {
|
||||||
Formula string `json:"formula"`
|
Formula string `json:"formula"`
|
||||||
RecordCount string `json:"record_count"`
|
RecordCount string `json:"record_count"`
|
||||||
RecodeIndex string `json:"record_index"`
|
RecodeIndex string `json:"record_index"`
|
||||||
RecordKey string `json:"record_key"`
|
RecordKey string `json:"record_key"`
|
||||||
NumberFormat string `json:"number_format"`
|
AdditionalRecordKey string `json:"additional_record_key"`
|
||||||
Conversion string `json:"conversion"`
|
NumberFormat string `json:"number_format"`
|
||||||
|
Conversion string `json:"conversion"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CardCalculation(data []Observation, req CardCalculationRequest) (map[string]string, error) {
|
func CardCalculation(data []Observation, req CardCalculationRequest) (map[string]string, error) {
|
||||||
@ -76,11 +77,31 @@ func CardCalculation(data []Observation, req CardCalculationRequest) (map[string
|
|||||||
}
|
}
|
||||||
|
|
||||||
convertedValue := applyConversion(result, req.Conversion, req.NumberFormat)
|
convertedValue := applyConversion(result, req.Conversion, req.NumberFormat)
|
||||||
displayValue := extractRecordKeyValue(selectedData, req.RecordKey, req.Formula, result)
|
fmt.Println("AdditionalRecordKey:", req.AdditionalRecordKey)
|
||||||
|
displayValue := extractRecordKeyValue(selectedData, req.RecordKey, req.AdditionalRecordKey, req.Formula, result)
|
||||||
|
|
||||||
|
color := ""
|
||||||
|
if req.Formula == "different" {
|
||||||
|
// Remove the percentage sign if present
|
||||||
|
convertedValueStr := strings.TrimSuffix(convertedValue, "%")
|
||||||
|
|
||||||
|
// Convert to float
|
||||||
|
convertedValue, err := strconv.ParseFloat(convertedValueStr, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err // Handle error if conversion fails
|
||||||
|
}
|
||||||
|
if convertedValue > 0 {
|
||||||
|
color = "#11AF22"
|
||||||
|
} else if convertedValue < 0 {
|
||||||
|
color = "#D83731"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"value": convertedValue,
|
"value": convertedValue,
|
||||||
"display_value": displayValue,
|
"display_value": displayValue,
|
||||||
|
"calculation": req.Formula,
|
||||||
|
"font_color": color,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +258,7 @@ func applyConversion(value float64, conversion string, numberFormat string) stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractRecordKeyValue(data []Observation, key string, formula string, targetValue float64) string {
|
func extractRecordKeyValue(data []Observation, key string, additionalkey string, formula string, targetValue float64) string {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -248,10 +269,18 @@ func extractRecordKeyValue(data []Observation, key string, formula string, targe
|
|||||||
value, err := obs.ObsValue.Value.Float64()
|
value, err := obs.ObsValue.Value.Float64()
|
||||||
if err == nil && value == targetValue {
|
if err == nil && value == targetValue {
|
||||||
if val, exists := obs.ObsKey[key]; exists {
|
if val, exists := obs.ObsKey[key]; exists {
|
||||||
return val
|
fmt.Println("additionalkey:", additionalkey)
|
||||||
|
// Check if additionalkey exists in obs.ObsKey
|
||||||
|
if val2, exists2 := obs.ObsKey[additionalkey]; exists2 {
|
||||||
|
fmt.Println("val2:", val2)
|
||||||
|
return val + " - " + val2
|
||||||
|
} else {
|
||||||
|
return val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "total", "average", "different":
|
case "total", "average", "different":
|
||||||
if val1, exists1 := data[0].ObsKey[key]; exists1 {
|
if val1, exists1 := data[0].ObsKey[key]; exists1 {
|
||||||
if val2, exists2 := data[len(data)-1].ObsKey[key]; exists2 {
|
if val2, exists2 := data[len(data)-1].ObsKey[key]; exists2 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user