calculate speed (test pull request)#3
calculate speed (test pull request)#3killer415tv wants to merge 1 commit intoelectaco:feature/speedometerfrom
Conversation
| calculateSpeed() { | ||
|
|
||
| this.setState({now_position: this.state.gw2data_ws?.coordinates.playerPosition}) | ||
| this.setState({now_timestamp: new Date().getTime()}) |
There was a problem hiding this comment.
Should use https://developer.mozilla.org/en-US/docs/Web/API/Performance/now for more accurate timings instead of Date().getTime()
https://stackoverflow.com/questions/6233927/microsecond-timing-in-javascript
|
|
||
| calculateSpeed() { | ||
|
|
||
| this.setState({now_position: this.state.gw2data_ws?.coordinates.playerPosition}) |
There was a problem hiding this comment.
You're not using now_position and now_timestamp, so might want to skip these :)
| let speed = (distance * 39.3700787) / 0.01 ; | ||
| speed = Math.round((speed*100/10000)*99/72) | ||
|
|
||
| this.setState({speed: speed}) |
There was a problem hiding this comment.
These three setstate can be done in one call :)
| interface IState { | ||
| gw2data_ipc: IGw2MumbleLinkData | null; | ||
| gw2data_ws: IGw2MumbleLinkData | null; | ||
| now_position: any; |
There was a problem hiding this comment.
Would be nice if you had type here, it's an interface IPosition that has this structure.
That would also highlight a bug on line 28 where you use small xyz instead of capital XYZ
| now_timestamp: any; | ||
| last_position: any; | ||
| last_timestamp: any; | ||
| speed: any; |
There was a problem hiding this comment.
speed is number :) Also consider if it should be null before calculating speed the first time.
just a test for pull request