Search in sources :

Example 1 with ProgressCapable

use of io.engineblock.activityimpl.input.ProgressCapable in project engineblock by engineblock.

the class ActivityExecutor method getProgress.

@Override
public synchronized double getProgress() {
    ArrayList<Input> inputs = motors.stream().map(Motor::getInput).distinct().collect(Collectors.toCollection(ArrayList::new));
    double startCycle = getActivityDef().getStartCycle();
    double endCycle = getActivityDef().getEndCycle();
    double totalCycles = endCycle - startCycle;
    double total = 0.0D;
    double progress = 0.0D;
    for (Input input : inputs) {
        if (input instanceof ProgressCapable) {
            ProgressCapable progressInput = (ProgressCapable) input;
            total += progressInput.getTotal();
            progress += progressInput.getProgress();
        } else {
            logger.warn("input does not support activity progress: " + input);
            return Double.NaN;
        }
    }
    return progress / total;
}
Also used : Input(io.engineblock.activityapi.input.Input) ProgressCapable(io.engineblock.activityimpl.input.ProgressCapable)

Aggregations

Input (io.engineblock.activityapi.input.Input)1 ProgressCapable (io.engineblock.activityimpl.input.ProgressCapable)1