Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(asset): calibration forecast timezone issues on datalinks #111

Merged
merged 3 commits into from
Nov 14, 2024

Conversation

kkerezsi
Copy link
Collaborator

@kkerezsi kkerezsi commented Nov 14, 2024

Pull Request

🤨 Rationale

  • Due to a reported issue in the CST time zone, it seems that the calibration forecast dashboard doesn't build the datalinks properly
  • The bucket label was also built in local time instead of UTC

👩‍💻 Implementation

  • The datalink time building algorithm was adjusted to account for the actual values from the backend when building the links
  • The Buckets labels respect the UTC values now

🧪 Testing

  • Unit testing
  • Manual testing on different time zones

✅ Checklist

@mure mure merged commit f5209e8 into main Nov 14, 2024
1 check passed
@mure mure deleted the users/alkerezs/fix-timezone-related-issues branch November 14, 2024 16:24
mure pushed a commit that referenced this pull request Nov 14, 2024
## [3.43.5](v3.43.4...v3.43.5) (2024-11-14)

### Bug Fixes

* **asset:** calibration forecast timezone issues on datalinks ([#111](#111)) ([f5209e8](f5209e8))
@mure
Copy link
Collaborator

mure commented Nov 14, 2024

🎉 This PR is included in version 3.43.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mure mure added the released label Nov 14, 2024
@@ -101,7 +101,8 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
return null;
}

processResultsGroupedByTime(result: DataFrameDTO, timeGrouping: AssetCalibrationForecastKey) {
processResultsGroupedByTime(result: DataFrameDTO, timeGrouping: AssetCalibrationForecastKey, options: DataQueryRequest) {
const originalValuesMap = this.constructDataLinkValuesMap(result, options);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the method name is constructDataLinkValuesMap, maybe dataLinkValuesMap would be more suitable name.

@@ -101,7 +101,8 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
return null;
}

processResultsGroupedByTime(result: DataFrameDTO, timeGrouping: AssetCalibrationForecastKey) {
processResultsGroupedByTime(result: DataFrameDTO, timeGrouping: AssetCalibrationForecastKey, options: DataQueryRequest) {
const originalValuesMap = this.constructDataLinkValuesMap(result, options);
result.fields.forEach(field => {
field.name = this.createColumnNameFromDescriptor(field as FieldDTOWithDescriptor);
const formatter = this.forecastDateFormatterMap.get(field.name as AssetCalibrationForecastKey);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While here, dateFormatter might be a better name for this as well.

}
});
}

private constructDataLinkBaseUrl(){
private constructDataLinkValuesMap(result: DataFrameDTO, options: DataQueryRequest): Map<string, { from: number, to: number }> {
const originalValuesMap = new Map<string, { from: number, to: number }>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataLinkValuesMap might be more suited here as well.

if (formatter) {
let value = { from: 0, to: 0 }
const formattedValues: string[] = field.values!.map(formatter);
if (originalValues.length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the available timeGrouping or the current condition along with timeGrouping might make it easier to understand. I believe length 1 is Week and the else statement has logic for both Day and Month.

}

private createDataLinks(timeGrouping: AssetCalibrationForecastKey): DataLink[] {
private createDataLinks(timeGrouping: AssetCalibrationForecastKey, originalValuesMap: Map<string, { from: any, to: any }>): DataLink[] {
Copy link
Collaborator

@saradei-ni saradei-ni Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type I think is { from: number, to: number }, so we can avoid any.

@@ -130,36 +172,12 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
if (!options.replaceVariables) {
return url;
}

const value = options.replaceVariables(`\${__data.fields.${timeGrouping}}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have something like this if we don't have a value for the map every time.

                    const value = options.replaceVariables(`\${__data.fields.${timeGrouping}}`);
                    const valueAsDate = originalValuesMap.get(value);
                    if (!value && !valueAsDate) {
                        return url;
                    }

                    return `${url}&from=${valueAsDate.from}&to=${valueAsDate.to}`;

If we do have a value every time, what about something like this?

                    const value = options.replaceVariables(`\${__data.fields.${timeGrouping}}`);
                    if (!value) {
                        return url;
                    }

                    const [from, to] = originalValuesMap.get(value)!;
                    return `${url}&from=${from}&to=${to}`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants