<commit_before>package archimulator.util.chart;

import archimulator.client.GuestStartup;
import archimulator.service.ArchimulatorService;
import archimulator.sim.base.experiment.profile.ExperimentProfile;
import archimulator.sim.base.experiment.profile.ExperimentProfileState;
import archimulator.util.DateHelper;
import archimulator.util.action.Function;
import com.caucho.hessian.client.HessianProxyFactory;
import org.jfree.ui.RefineryUtilities;

import java.net.MalformedURLException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ExperimentPlot {
    private String title;
    private List<ExperimentSubPlot> subPlots;

    public ExperimentPlot(String title) {
        this.title = title;
        this.subPlots = new ArrayList<ExperimentSubPlot>();
    }

    public String getTitle() {
        return title;
    }

    public List<ExperimentSubPlot> getSubPlots() {
        return subPlots;
    }

    public static class ExperimentSubPlot {
        private String titleY;
        private List<ExperimentSubPlotLine> lines;
        
        public ExperimentSubPlot(String titleY) {
            this.titleY = titleY;
            this.lines = new ArrayList<ExperimentSubPlotLine>();
        }

        public String getTitleY() {
            return titleY;
        }

        public List<ExperimentSubPlotLine> getLines() {
            return lines;
        }
    }
    
    public static class ExperimentSubPlotLine {
        private String title;
        private Function<Double> getValueCallback;

        public ExperimentSubPlotLine(String title, Function<Double> getValueCallback) {
            this.title = title;
            this.getValueCallback = getValueCallback;
        }

        public String getTitle() {
            return title;
        }

        public Function<Double> getGetValueCallback() {
            return getValueCallback;
        }
    }

    private static void addExperimentSubPlotInstsPerSecond(final ArchimulatorService archimulatorService, ExperimentPlot experimentPlot) throws SQLException {
        ExperimentSubPlot experimentSubPlotCyclesPerSecond = new ExperimentSubPlot("Insts per Second");

        List<ExperimentProfile> experimentProfiles = archimulatorService.getExperimentProfilesAsList();
        for(final ExperimentProfile experimentProfile : experimentProfiles) {
            if(experimentProfile.getState() == ExperimentProfileState.RUNNING) {
                experimentSubPlotCyclesPerSecond.getLines().add(new ExperimentSubPlotLine("Exp #" + experimentProfile.getId(), new Function<Double>() {
                    @Override
                    public Double apply() {
                        try {
                            String str = (String) archimulatorService.getExperimentStatsById(experimentProfile.getId()).get("detailedSimulation.instsPerSecond");
                            str = str.replaceAll(",", "");
                            return (double)(int)(Double.valueOf(str).doubleValue());
                        } catch (SQLException e) {
                            recordException(e);
                            return 0.0;
                        }
                    }
                }));
            }
        }
        experimentPlot.getSubPlots().add(experimentSubPlotCyclesPerSecond);
    }

    private static void addExperimentSubPlotCyclesPerSecond(final ArchimulatorService archimulatorService, ExperimentPlot experimentPlot) throws SQLException {
        ExperimentSubPlot experimentSubPlotCyclesPerSecond = new ExperimentSubPlot("Cycles per Second");

        List<ExperimentProfile> experimentProfiles = archimulatorService.getExperimentProfilesAsList();
        for(final ExperimentProfile experimentProfile : experimentProfiles) {
            if(experimentProfile.getState() == ExperimentProfileState.RUNNING) {
                experimentSubPlotCyclesPerSecond.getLines().add(new ExperimentSubPlotLine("Exp #" + experimentProfile.getId(), new Function<Double>() {
                    @Override
                    public Double apply() {
                        try {
                            String str = (String) archimulatorService.getExperimentStatsById(experimentProfile.getId()).get("detailedSimulation.cyclesPerSecond");
                            str = str.replaceAll(",", "");
                            return (double)(int)(Double.valueOf(str).doubleValue());
                        } catch (SQLException e) {
                            recordException(e);
                            return 0.0;
                        }
                    }
                }));
            }
        }<commit_msg>fix bugs in ExperimentPlot.<commit_after>package archimulator.util.chart;

import archimulator.client.GuestStartup;
import archimulator.service.ArchimulatorService;
import archimulator.sim.base.experiment.profile.ExperimentProfile;
import archimulator.sim.base.experiment.profile.ExperimentProfileState;
import archimulator.util.DateHelper;
import archimulator.util.action.Function;
import com.caucho.hessian.client.HessianProxyFactory;
import org.jfree.ui.RefineryUtilities;

import java.net.MalformedURLException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class ExperimentPlot {
    private String title;
    private List<ExperimentSubPlot> subPlots;

    public ExperimentPlot(String title) {
        this.title = title;
        this.subPlots = new ArrayList<ExperimentSubPlot>();
    }

    public String getTitle() {
        return title;
    }

    public List<ExperimentSubPlot> getSubPlots() {
        return subPlots;
    }

    public static class ExperimentSubPlot {
        private String titleY;
        private List<ExperimentSubPlotLine> lines;
        
        public ExperimentSubPlot(String titleY) {
            this.titleY = titleY;
            this.lines = new ArrayList<ExperimentSubPlotLine>();
        }

        public String getTitleY() {
            return titleY;
        }

        public List<ExperimentSubPlotLine> getLines() {
            return lines;
        }
    }
    
    public static class ExperimentSubPlotLine {
        private String title;
        private Function<Double> getValueCallback;

        public ExperimentSubPlotLine(String title, Function<Double> getValueCallback) {
            this.title = title;
            this.getValueCallback = getValueCallback;
        }

        public String getTitle() {
            return title;
        }

        public Function<Double> getGetValueCallback() {
            return getValueCallback;
        }
    }

    private static void addExperimentSubPlotInstsPerSecond(final ArchimulatorService archimulatorService, ExperimentPlot experimentPlot) throws SQLException {
        ExperimentSubPlot experimentSubPlotCyclesPerSecond = new ExperimentSubPlot("Insts per Second");

        List<ExperimentProfile> experimentProfiles = archimulatorService.getExperimentProfilesAsList();
        for(final ExperimentProfile experimentProfile : experimentProfiles) {
            if(experimentProfile.getState() == ExperimentProfileState.RUNNING) {
                experimentSubPlotCyclesPerSecond.getLines().add(new ExperimentSubPlotLine("Exp #" + experimentProfile.getId(), new Function<Double>() {
                    @Override
                    public Double apply() {
                        try {
                            Map<String,Object> experimentStatsById = archimulatorService.getExperimentStatsById(experimentProfile.getId());
                            String key = "checkpointedSimulation/phase1.instsPerSecond";
                            if(experimentStatsById.containsKey(key)) {
                                String str = (String) experimentStatsById.get(key);
                                str = str.replaceAll(",", "");
                                return (double)(int)(Double.valueOf(str).doubleValue());
                            }
                            return 0.0;
                        } catch (SQLException e) {
                            recordException(e);
                            return 0.0;
                        }
                    }
                }));
            }
        }
        experimentPlot.getSubPlots().add(experimentSubPlotCyclesPerSecond);
    }

    private static void addExperimentSubPlotCyclesPerSecond(final ArchimulatorService archimulatorService, ExperimentPlot experimentPlot) throws SQLException {
        ExperimentSubPlot experimentSubPlotCyclesPerSecond = new ExperimentSubPlot("Cycles per Second");

        List<ExperimentProfile> experimentProfiles = archimulatorService.getExperimentProfilesAsList();
        for(final ExperimentProfile experimentProfile : experimentProfiles) {
            if(experimentProfile.getState() == ExperimentProfileState.RUNNING) {
                experimentSubPlotCyclesPerSecond.getLines().add(new ExperimentSubPlotLine("Exp #" + experimentProfile.getId(), new Function<Double>() {
                    @Override
                    public Double apply() {
                        try {
                            Map<String, Object> experimentStatsById = archimulatorService.getExperimentStatsById(experimentProfile.getId());
                            String key = "checkpointedSimulation/phase1.cyclesPerSecond";
                            if(experimentStatsById.containsKey(key)) {
                                String str = (String) experimentStatsById.get(key);
                                str = str.replaceAll(",", "");
                                return (double)(int)(Double.valueOf(str).doubleValue());
                            }
                            return 0.0;
                        } catch (SQLException e) {
                            recordException(e);
                            return 0.0;
                        }
                    }
                }));
            }
        }
{'fraction_non_alphanumeric': 0.07952842441802378, 'fraction_numerical': 0.0013987411329803177, 'mean_word_length': 2.1183800623052957, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6957957', 'n_tokens_mistral': 2503, 'n_tokens_neox': 2345, 'n_words': 446}