<commit_before>package org.jboss.windup.config.operation;

import java.util.logging.Logger;

import org.jboss.forge.furnace.util.Iterators;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.operation.iteration.AbstractIterationOperation;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.util.Logging;
import org.jboss.windup.util.ProgressEstimate;
import org.ocpsoft.rewrite.context.EvaluationContext;

/**
 * Provides a simplistic way of printing a message to the log every {@link IterationProgress#interval} iterations.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class IterationProgress extends AbstractIterationOperation<WindupVertexFrame>
{
    private static final Logger LOG = Logging.get(IterationProgress.class);

    private String messagePrefix;
    private int interval;
    private int totalIterations = -1;
    private boolean estimateTimeRemaining = true;
    private ProgressEstimate progressEstimate;

    public IterationProgress(String messagePrefix, int interval)
    {
        this.messagePrefix = messagePrefix;
        this.interval = interval;
    }

    public static IterationProgress monitoring(String messagePrefix, int interval)
    {
        return new IterationProgress(messagePrefix, interval);
    }

    public IterationProgress disableTimeEstimation()
    {
        estimateTimeRemaining = false;
        return this;
    }

    @Override
    public void perform(GraphRewrite event, EvaluationContext context, WindupVertexFrame payload)
    {
        if (totalIterations == -1)
        {
            @SuppressWarnings("unchecked")
            Iterable<WindupVertexFrame> frames = (Iterable<WindupVertexFrame>) event.getRewriteContext().get(
                        Iteration.DEFAULT_VARIABLE_LIST_STRING);
            totalIterations = Iterators.asList(frames).size();
            progressEstimate = new ProgressEstimate(totalIterations);
        }
        progressEstimate.addWork(1);
        if (progressEstimate.getWorked() % interval == 0)
        {
            if (estimateTimeRemaining)
            {
                long remainingTimeMillis = progressEstimate.getTimeRemainingInMillis();
                if (remainingTimeMillis > 1000)
                    event.ruleEvaluationProgress(messagePrefix, progressEstimate.getWorked(), totalIterations, (int) remainingTimeMillis / 1000);
            }
            LOG.info(messagePrefix + ": " + progressEstimate.getWorked() + " / " + totalIterations);
        }<commit_msg>IterationProgress has default variable name hardcoded<commit_after>package org.jboss.windup.config.operation;

import java.util.logging.Logger;

import org.jboss.forge.furnace.util.Iterators;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.operation.iteration.AbstractIterationOperation;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.util.Logging;
import org.jboss.windup.util.ProgressEstimate;
import org.ocpsoft.rewrite.context.EvaluationContext;

/**
 * Provides a simplistic way of printing a message to the log every {@link IterationProgress#interval} iterations.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class IterationProgress extends AbstractIterationOperation<WindupVertexFrame>
{
    private static final Logger LOG = Logging.get(IterationProgress.class);

    private String messagePrefix;
    private int interval;
    private int totalIterations = -1;
    private boolean estimateTimeRemaining = true;
    private ProgressEstimate progressEstimate;
    private String variableListName = Iteration.DEFAULT_VARIABLE_LIST_STRING;

    public IterationProgress(String messagePrefix, int interval)
    {
        this.messagePrefix = messagePrefix;
        this.interval = interval;
    }

    public static IterationProgress monitoring(String messagePrefix, int interval)
    {
        return new IterationProgress(messagePrefix, interval);
    }

    public IterationProgress over(String iterableName) {
        variableListName = iterableName;
        return this;
    }

    public IterationProgress disableTimeEstimation()
    {
        estimateTimeRemaining = false;
        return this;
    }

    @Override
    public void perform(GraphRewrite event, EvaluationContext context, WindupVertexFrame payload)
    {
        if (totalIterations == -1)
        {
            @SuppressWarnings("unchecked")
            Iterable<WindupVertexFrame> frames = (Iterable<WindupVertexFrame>) event.getRewriteContext().get(
                    variableListName);
            totalIterations = Iterators.asList(frames).size();
            progressEstimate = new ProgressEstimate(totalIterations);
        }
        progressEstimate.addWork(1);
        if (progressEstimate.getWorked() % interval == 0)
        {
            if (estimateTimeRemaining)
            {
                long remainingTimeMillis = progressEstimate.getTimeRemainingInMillis();
                if (remainingTimeMillis > 1000)
                    event.ruleEvaluationProgress(messagePrefix, progressEstimate.getWorked(), totalIterations, (int) remainingTimeMillis / 1000);
            }
            LOG.info(messagePrefix + ": " + progressEstimate.getWorked() + " / " + totalIterations);
        }
{'fraction_non_alphanumeric': 0.0863567649281935, 'fraction_numerical': 0.0045351473922902496, 'mean_word_length': 3.271993543179984, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1922206', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1393, 'n_words': 289}