{"size": 1410, "ext": "js", "max_stars_repo_path": "modules/dreamview/frontend/src/store/meters.js", "max_stars_repo_name": "Orientlee/apollo", "max_stars_repo_stars_event_min_datetime": "2017-07-06T02:53:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T12:03:09.000Z", "max_issues_repo_path": "modules/dreamview/frontend/src/store/meters.js", "max_issues_repo_name": "yk-fujii/apollo", "max_issues_repo_issues_event_min_datetime": "2021-03-09T15:58:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T16:45:57.000Z", "max_forks_repo_path": "modules/dreamview/frontend/src/store/meters.js", "max_forks_repo_name": "yk-fujii/apollo", "max_forks_repo_forks_event_min_datetime": "2017-07-05T08:45:42.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T06:43:16.000Z"}
{"max_stars_count": 9, "max_issues_count": 3, "max_forks_count": 10, "avg_line_length": 32.0454545455, "max_line_length": 79, "alphanum_fraction": 0.6255319149}
import { observable, computed, action, runInAction } from "mobx";

function roundToTens(percent) {
    return Math.round(percent / 10.0) * 10;
}

function toDrivingMode(disengageType) {
    if (disengageType === "DISENGAGE_MANUAL") {
        return "MANUAL";
    } else if (disengageType === "DISENGAGE_NONE") {
        return "AUTO";
    }
    return "?";
}

function meterPerSecondToKmPerHour(speed) {
    return Math.round(speed * 3600 / 1000.0);
}

export default class Meters {
    @observable throttlePercent = 0;
    @observable brakePercent = 0;
    @observable speed = 0;
    @observable steeringAngle = 0;
    @observable drivingMode = "?";

    @action update(world) {
        if (world.autoDrivingCar) {
            this.throttlePercent = roundToTens(
                world.autoDrivingCar.throttlePercentage);
            this.brakePercent = roundToTens(
                world.autoDrivingCar.brakePercentage);
            // Convert the unit from m/s to mph.
            this.speed = meterPerSecondToKmPerHour(world.autoDrivingCar.speed);
            this.steeringAngle =
                -Math.round(world.autoDrivingCar.steeringAngle / 100 * 470);
            this.drivingMode =
                toDrivingMode(world.autoDrivingCar.disengageType);
            /* TODO Turn signal is not working. Please check and make sure
             * that it is set correctly in the backend.*/
        }
    }
}
