diff --git a/main.go b/main.go index d601b63..2ea6055 100644 --- a/main.go +++ b/main.go @@ -1899,7 +1899,7 @@ func sendStatusChangeEmail(app *pocketbase.PocketBase, record *models.Record, ne body = fmt.Sprintf(`
Dear %s,
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.
-Please access your account using the following link: "Access Your Account.
+Please access your account using the following link: Access Your Account.
If you have any questions, please feel free to contact us for further clarification.
Best regards,
diff --git a/pb_data/data.db b/pb_data/data.db index a750f8f..1d0bcdd 100644 Binary files a/pb_data/data.db and b/pb_data/data.db differ diff --git a/pb_data/logs.db b/pb_data/logs.db index 598055a..7018cf0 100644 Binary files a/pb_data/logs.db and b/pb_data/logs.db differ diff --git a/utils/card_calculation.go b/utils/card_calculation.go index 0cb8bef..ae861c8 100644 --- a/utils/card_calculation.go +++ b/utils/card_calculation.go @@ -20,12 +20,13 @@ type Observation struct { // ------------------------------------------------------------ card calculation--------------------------------------------------- type CardCalculationRequest struct { - Formula string `json:"formula"` - RecordCount string `json:"record_count"` - RecodeIndex string `json:"record_index"` - RecordKey string `json:"record_key"` - NumberFormat string `json:"number_format"` - Conversion string `json:"conversion"` + Formula string `json:"formula"` + RecordCount string `json:"record_count"` + RecodeIndex string `json:"record_index"` + RecordKey string `json:"record_key"` + AdditionalRecordKey string `json:"additional_record_key"` + NumberFormat string `json:"number_format"` + Conversion string `json:"conversion"` } 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) - 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{ "value": convertedValue, "display_value": displayValue, + "calculation": req.Formula, + "font_color": color, }, 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 { return "" } @@ -248,10 +269,18 @@ func extractRecordKeyValue(data []Observation, key string, formula string, targe value, err := obs.ObsValue.Value.Float64() if err == nil && value == targetValue { 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": if val1, exists1 := data[0].ObsKey[key]; exists1 { if val2, exists2 := data[len(data)-1].ObsKey[key]; exists2 {