support per-field transformations#359
support per-field transformations#359patrickdemers6 wants to merge 1 commit intoteslamotors:mainfrom
Conversation
7b85230 to
a28760d
Compare
telemetry/transform.go
Outdated
| ) | ||
|
|
||
| var ( | ||
| pacificTimeLoc *time.Location |
There was a problem hiding this comment.
nit: pacificTimeLocation
telemetry/transform.go
Outdated
| func transformTimestamp(d *protos.Datum, _ semver.Version) { | ||
| if timestamp := d.GetValue().GetDoubleValue(); timestamp != 0 { | ||
| _, offset := time.Now().In(pacificTimeLoc).Zone() | ||
| d.Value = &protos.Value{Value: &protos.Value_DoubleValue{DoubleValue: timestamp + float64(offset)}} |
There was a problem hiding this comment.
I don't think this correctly handles daylight savings transitions, because it's getting the offset of the current time then applying it to a time that may be on a different day?
Then again, I don't know how the vehicle handles this situation either.
aaf6206 to
9bf61d6
Compare
|
Ok this actually isn't going to work at all since we need the vehicle's timezone. Working on a firmware fix. |
I don't understand this comment. As reported in #251, it appears that interpreting the timestamp in Pacific Time then using the result at a vehicle local time works. If so, converting from Pacific Time to UTC should work, except perhaps for the daylight savings issue I mentioned? I'd like to fully understand this issue because I'd like to use |
|
Converting to UTC will yield a time in the local vehicle timezone, but there's no way for me to give a true unix timestamp from the backend. Adding a conversion here that still gives a unix timestamp that is wrong doesn't feel like the right move. Open to your thoughts of course though. |
|
I do think adding the ability for per-field transformations by version is still valuable, but maybe not for time. |
9bf61d6 to
1104459
Compare
|
FWIW, in our case, for
We don't actually need the date-and-time of the next (or current) scheduled charge, we just need the time-of-day, so we don't need a complete timestamp. An even better field for us would be an indicator that the vehicle is currently in the 6 hour schedule window or not, since that is actually all we care about. (We are trying to detect if a charging vehicle may be charging due to the schedule) |
|
SoftwareUpdateScheduledStartTime has the same issue. I think reporting a Unix UTC timestamp (regardless of how it's achieved) is the most friendly and sane thing to do. But considering this is already in the wild, and affecting multiple fields, maybe leave this in as a systematic quirk and tell devs to interpret all fleet telemetry timestamps as America/Los_Angeles. |
|
Actually, I don't think timezone interpretation fixes this. Example with SoftwareUpdateScheduledStartTime: Fleet API: 1739692800553 - Sunday, February 16, 2025 8:00:00.553 AM GMT - Correct @jbanyer any guidance here? Some simple JS code or something would help understand how you're fixing this. |
|
Example for ScheduledChargingStartTime... Fleet API: 1739650500 - Saturday, February 15, 2025 8:15:00 PM GMT - Correct |
@patrickdemers6 - my 2 cents would be that I agree that sending a unix timestamp that is still wrong is likely the wrong move. I struggle to think of any reason that anything other than a correct unix timestamp would be the 'right' move here. Given the need to work around this pending a firmware update, it would be ideal if we could get some kind of notification when this is changed and at what firmware version, but it should absolutely be changed IMO. I'd be willing to bet that pretty much nobody would expect a unix timestamp to have been derived improperly and therefore not be able to be implicitly trusted. 🤷🏻♂️ Workaround (which we'll use for now) seems possible provided the vehicle's timezone is known (at least I can't think of a way to do it without that given the inputs that would have been used to create the incorrect timestamp in the first place). |
|
@stx the way we use the Per the example from #251:
Unix time 1736756100 interpreted using various timezones is:
The "LA time" interpretation gives the correct time-of-day for the vehicle, and that's all we need. We combine this with the vehicle's timezone (which we obtain separately from the user, not from the vehicle) in order to obtain an actual timestamp. |
|
@patrickdemers6 In addition to the timezone mismatch, it seems like there's an additional 2-minute offset happening: Scheduled time: Friday, February 21, 2025 11:55 AM PT Appears to be exactly 2 minutes ahead no matter which time is set. edit: looks like this is because Fleet Telemetry is including the additional warning countdown time and Fleet API isn't. |
Description
Introduces the ability to define per-field transformations.
Transformation functions receive the device version, allowing a transformation to only impact specific vehicle versions.
Type of change
Please select all options that apply to this change:
Checklist:
Confirm you have completed the following steps: