<commit_before>package org.opennms.netmgt.jasper.jrobin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import net.sf.jasperreports.engine.JRDataSource;

import org.jrobin.core.RrdException;
import org.jrobin.core.Util;
import org.jrobin.data.DataProcessor;
import org.jrobin.graph.RrdGraphConstants;

class RrdXportCmd extends RrdToolCmd implements RrdGraphConstants {
    private DataProcessor dproc;
    private List<XPort> xports;

    String getCmdType() {
        return "xport";
    }

    JRDataSource execute() throws RrdException, IOException {
        String startStr = getOptionValue("s", "start", DEFAULT_START);
        String endStr = getOptionValue("e", "end", DEFAULT_END);
        long span[] = Util.getTimestamps(startStr, endStr);
        dproc = new DataProcessor(span[0], span[1]);
        xports = new ArrayList<XPort>();
        long step = parseLong(getOptionValue(null, "step", "1"));
        int maxRows = parseInt(getOptionValue("m", "maxrows", "400"));
        long minStep = (long) Math.ceil((span[1] - span[0]) / (double) (maxRows - 1));
        step = Math.max(step, minStep);
        dproc.setStep(step);
        String[] words = getRemainingWords();
        if (words.length < 1) {
            throw new RrdException("Incomplete XPORT command");
        }
        for (int i = 0; i < words.length; i++) {
            if (words[i].startsWith("DEF:")) {
                parseDef(words[i]);
            }
            else if (words[i].startsWith("CDEF:")) {
                parseCDef(words[i]);
            }
            else if (words[i].startsWith("XPORT:")) {
                parseXport(words[i]);
            }
            else {
                throw new RrdException("Invalid XPORT syntax: " + words[i]);
            }
        }
        JRDataSource result = xports.size() == 0 ? null : xport();
        println(xports.size() == 0 ? "No XPORT statement found, nothing done" : result.toString());
        return result;
    }

    private JRDataSource xport() throws IOException, RrdException {
        dproc.processData();
        long[] timestamps = dproc.getTimestamps();
        for (XPort xport : xports) {
            xport.values = dproc.getValues(xport.name);
        }
        return new JRobinDataSource(timestamps, xports);<commit_msg>set FetchRequestResolution in RrdXportCmd with the step from the query  so that the resulting fetch has the correct resolution to use<commit_after>package org.opennms.netmgt.jasper.jrobin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import net.sf.jasperreports.engine.JRDataSource;

import org.jrobin.core.RrdException;
import org.jrobin.core.Util;
import org.jrobin.data.DataProcessor;
import org.jrobin.graph.RrdGraphConstants;

class RrdXportCmd extends RrdToolCmd implements RrdGraphConstants {
    private DataProcessor dproc;
    private List<XPort> xports;

    String getCmdType() {
        return "xport";
    }

    JRDataSource execute() throws RrdException, IOException {
        String startStr = getOptionValue("s", "start", DEFAULT_START);
        String endStr = getOptionValue("e", "end", DEFAULT_END);
        long span[] = Util.getTimestamps(startStr, endStr);
        dproc = new DataProcessor(span[0], span[1]);
        xports = new ArrayList<XPort>();
        long step = parseLong(getOptionValue(null, "step", "1"));
        int maxRows = parseInt(getOptionValue("m", "maxrows", "400"));
        long minStep = (long) Math.ceil((span[1] - span[0]) / (double) (maxRows - 1));
        step = Math.max(step, minStep);
        dproc.setFetchRequestResolution(step);
        dproc.setStep(step);
        String[] words = getRemainingWords();
        if (words.length < 1) {
            throw new RrdException("Incomplete XPORT command");
        }
        for (int i = 0; i < words.length; i++) {
            if (words[i].startsWith("DEF:")) {
                parseDef(words[i]);
            }
            else if (words[i].startsWith("CDEF:")) {
                parseCDef(words[i]);
            }
            else if (words[i].startsWith("XPORT:")) {
                parseXport(words[i]);
            }
            else {
                throw new RrdException("Invalid XPORT syntax: " + words[i]);
            }
        }
        JRDataSource result = xports.size() == 0 ? null : xport();
        println(xports.size() == 0 ? "No XPORT statement found, nothing done" : result.toString());
        return result;
    }

    private JRDataSource xport() throws IOException, RrdException {
        dproc.processData();
        long[] timestamps = dproc.getTimestamps();
        for (XPort xport : xports) {
            xport.values = dproc.getValues(xport.name);
        }
        return new JRobinDataSource(timestamps, xports);
{'fraction_non_alphanumeric': 0.1271098145446968, 'fraction_numerical': 0.005417795374036257, 'mean_word_length': 2.5555555555555554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '6005302', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1426, 'n_words': 330}