in pkg/exporter/configmap.go [27:52]
func (e *Exporter) CreateConfigMapFromEmissionForecast(ctx context.Context, configMapName string, emissionForecast []client.EmissionsForecastDto) error {
if emissionForecast == nil {
return errors.New("emission forecast cannot be nil")
}
forecast := emissionForecast[0]
binaryData, err := json.Marshal(forecast.ForecastData)
if err != nil {
return err
}
if forecast.ForecastData == nil || len(forecast.ForecastData) == 0 {
return errors.New("forecast data cannot be nil or empty")
}
minForecast, maxForeCast := getMinMaxForecast(ctx, forecast.ForecastData)
return e.CreateConfigMapFromProperties(ctx, configMapName,
map[string]string{
ConfigMapLastHeartbeatTime: time.Now().String(), // The latest time that the data exporter controller sends the data.
ConfigMapMessage: "", // Additional information for user notification, if any.
ConfigMapNumOfRecords: strconv.Itoa(len(forecast.ForecastData)), // The number can be any value between 0 (no records for the current location) and 24(hours) * 12(5 min interval per hour).
ConfigMapForecastDateTime: forecast.DataStartAt.String(), // The time when the data was started by the GSF SDK.
ConfigMapMinForecast: fmt.Sprintf("%f", minForecast), // min forecast in the forecastData.
ConfigMapMaxForecast: fmt.Sprintf("%f", maxForeCast), // max forecast in the forecastData.
}, binaryData)
}