Peter Riegel formula time prediction

I would like to create a data field for Peter Riegel formula race time prediction: https://en.wikipedia.org/wiki/Peter_Riegel

I am not familiar with the MonkeyC programming language, how should the source code look like?

estimatedTime = ( elapsedTime * pow( (42195/elapsedDistance) , 1.06) );


Thank you.
  • I think 42195 is the number of meters in a marathon, so this would be a marathon predictor. Your code would end up looking something like this...

    using Toybox.Math as Math;
    using Toybox.WatchUi as Ui;
    using Toybox.Application as App;

    class MyDataField extends Ui.SimpleDataField
    {
    function initialize() {
    SimpleDataField.initialize();
    label = "Riegel Time";
    }

    function compute(info) {
    return (info.elapsedTime * Math.pow((42195 / info.elapsedDistance), 1.06));
    }
    }

    class MyApp extends App.AppBase
    {
    function initialize() {
    AppBase.initialize();
    }

    function getInitialView() {
    return [ new MyDataField() ];
    }
    }
  • Thank you very much! Had to do some aditional edits, but I think I've got it.

    using Toybox.Application as App;
    using Toybox.WatchUi as Ui;
    using Toybox.Math as Math;
    using Toybox.Time as Time;


    class MarathonEstimateView extends Ui.SimpleDataField {

    function initialize() {
    SimpleDataField.initialize();
    label = "Marathon";
    }

    function compute(info) {
    var _estimate_sec = 0;
    if ( info.elapsedDistance != null ) {
    _estimate_sec = (( info.elapsedTime * Math.pow((42195 / info.elapsedDistance), 1.06)) / 1000 );
    }
    var options = { :seconds => (_estimate_sec) };
    var _estimate = Time.Gregorian.duration(options);
    return _estimate;
    }

    }

    class MarathonEstimate extends App.AppBase
    {
    function initialize() {
    AppBase.initialize();
    }
    function getInitialView()
    {
    return new MarathonEstimateView();
    }
    }