<commit_before>package com.amee.platform.science;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.*;

/**
 * A class representing a series of {@link DataPoint} values. Provides various mathematical operations
 * such as plus, subtract and multiply along with the crucial integrate method.
 */
public class DataSeries {

    private final Log log = LogFactory.getLog("science");
    private SortedSet<DataPoint> dataPoints = new TreeSet<DataPoint>();

    /// These dates will be used to define a query window on the series.
    private DateTime seriesStartDate;
    private DateTime seriesEndDate;

    /**
     * Construct an empty series.
     */
    public DataSeries() {
        this(new TreeSet<DataPoint>());
    }

    /**
     * Construct a series from the set of {@link DataPoint} values.
     *
     * @param dataPoints - the list of {@link DataPoint} values
     */
    public DataSeries(Set<DataPoint> dataPoints) {
        this.dataPoints = new TreeSet<DataPoint>(dataPoints);
    }

    /**
     * A copy constructor.
     *
     * @param dataSeries to copy
     */
    protected DataSeries(DataSeries dataSeries) {
        for (DataPoint dataPoint : dataSeries.dataPoints) {
            this.addDataPoint(new DataPoint(dataPoint));
        }
    }

    /**
     * Return a copy of this object.
     *
     * @return a copy
     */
    public DataSeries copy() {
        return new DataSeries(this);
    }

    public String toString() {
        try {
            return getJSONObject().toString();
        } catch (JSONException e) {
            throw new RuntimeException("Caught JSONException: " + e.getMessage(), e);
        }
    }

    public JSONObject getJSONObject() throws JSONException {
        JSONObject obj = new JSONObject();
        JSONArray arr = new JSONArray();
        for (DataPoint dataPoint : dataPoints) {
            arr.put(dataPoint.getJSONArray());
        }
        obj.put("dataPoints", arr);
        if (seriesStartDate != null) {
            obj.put("seriesStartDate", seriesStartDate.toString());
        }
        if (seriesEndDate != null) {
            obj.put("seriesEndDate", seriesEndDate.toString());
        }
        return obj;
    }

    protected Long getSeriesTimeInMillis() {
        if (dataPoints.isEmpty()) {
            return 0l;
        }
        DateTime seriesStart = getSeriesStartDate();
        DateTime seriesEnd = getSeriesEndDate();
        if ((seriesEnd == null || seriesStart == null)) {
            // the range of interest is undef
            return null;
        }
        return seriesEnd.getMillis() - seriesStart.getMillis();
    }

    DateTime getSeriesStartDate() {
        if (!dataPoints.isEmpty()) {
            DateTime first = dataPoints.first().getDateTime();
            return (seriesStartDate != null) && seriesStartDate.isAfter(first) ? seriesStartDate : first;
        } else {
            return null;
        }
    }

    DateTime getSeriesEndDate() {
        if (!dataPoints.isEmpty()) {<commit_msg>Make date getters public in DataSeries. PL-10852.<commit_after>package com.amee.platform.science;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.*;

/**
 * A class representing a series of {@link DataPoint} values. Provides various mathematical operations
 * such as plus, subtract and multiply along with the crucial integrate method.
 */
public class DataSeries {

    private final Log log = LogFactory.getLog("science");
    private SortedSet<DataPoint> dataPoints = new TreeSet<DataPoint>();

    /// These dates will be used to define a query window on the series.
    private DateTime seriesStartDate;
    private DateTime seriesEndDate;

    /**
     * Construct an empty series.
     */
    public DataSeries() {
        this(new TreeSet<DataPoint>());
    }

    /**
     * Construct a series from the set of {@link DataPoint} values.
     *
     * @param dataPoints - the list of {@link DataPoint} values
     */
    public DataSeries(Set<DataPoint> dataPoints) {
        this.dataPoints = new TreeSet<DataPoint>(dataPoints);
    }

    /**
     * A copy constructor.
     *
     * @param dataSeries to copy
     */
    protected DataSeries(DataSeries dataSeries) {
        for (DataPoint dataPoint : dataSeries.dataPoints) {
            this.addDataPoint(new DataPoint(dataPoint));
        }
    }

    /**
     * Return a copy of this object.
     *
     * @return a copy
     */
    public DataSeries copy() {
        return new DataSeries(this);
    }

    public String toString() {
        try {
            return getJSONObject().toString();
        } catch (JSONException e) {
            throw new RuntimeException("Caught JSONException: " + e.getMessage(), e);
        }
    }

    public JSONObject getJSONObject() throws JSONException {
        JSONObject obj = new JSONObject();
        JSONArray arr = new JSONArray();
        for (DataPoint dataPoint : dataPoints) {
            arr.put(dataPoint.getJSONArray());
        }
        obj.put("dataPoints", arr);
        if (seriesStartDate != null) {
            obj.put("seriesStartDate", seriesStartDate.toString());
        }
        if (seriesEndDate != null) {
            obj.put("seriesEndDate", seriesEndDate.toString());
        }
        return obj;
    }

    protected Long getSeriesTimeInMillis() {
        if (dataPoints.isEmpty()) {
            return 0l;
        }
        DateTime seriesStart = getSeriesStartDate();
        DateTime seriesEnd = getSeriesEndDate();
        if ((seriesEnd == null || seriesStart == null)) {
            // the range of interest is undef
            return null;
        }
        return seriesEnd.getMillis() - seriesStart.getMillis();
    }

    /**
     * Gets the seriesStartDate.
     *
     * @return return the seriesStartDate if set and after the first DataPoint, otherwise the date of the first DataPoint.
     */
    public DateTime getSeriesStartDate() {
        if (!dataPoints.isEmpty()) {
            DateTime first = dataPoints.first().getDateTime();
            return (seriesStartDate != null) && seriesStartDate.isAfter(first) ? seriesStartDate : first;
        } else {
            return null;
        }
    }

    /**
     * Gets the seriesEndDate.
     *
     * @return return the seriesEndDate if set, otherwise the date of the last DataPoint.
     */
    public DateTime getSeriesEndDate() {
        if (!dataPoints.isEmpty()) {
{'fraction_non_alphanumeric': 0.10451203690356062, 'fraction_numerical': 0.0010090817356205853, 'mean_word_length': 2.3993140617344437, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4260619', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1830, 'n_words': 517}