<commit_before>/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.analytics.esb.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeFieldType;
import org.joda.time.Days;
import org.joda.time.Hours;
import org.joda.time.Minutes;
import org.joda.time.Months;
import org.joda.time.MutableDateTime;
import org.wso2.carbon.analytics.esb.bean.TimeRange;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TimeRangeUtils {

    private static final int INTERVAL = 6;
    private static final Log log = LogFactory.getLog(TimeRangeUtils.class);
    private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");

    private TimeRangeUtils() {
    }

    public static String getSuitableTimeRangeUnit(long from, long to) {
        DateTime fromTime = new DateTime(from);
        DateTime toTime = new DateTime(to);
        RangeUnit range;
        if (Months.monthsBetween(fromTime, toTime).getMonths() >= INTERVAL) {
            range = RangeUnit.MONTH;
        } else if (Days.daysBetween(fromTime, toTime).getDays() >= INTERVAL) {
            range = RangeUnit.DAY;
        } else if (Hours.hoursBetween(fromTime, toTime).getHours() >= INTERVAL) {
            range = RangeUnit.HOUR;
        } else if (Minutes.minutesBetween(fromTime, toTime).getMinutes() >= INTERVAL) {
            range = RangeUnit.MINUTE;
        } else {
            range = RangeUnit.SECOND;
        }
        return range.name();
    }

    public static int getNoOfSecondForMonthInGivenTimestamp(long timestamp) {
        DateTime time = new DateTime(timestamp);
        return time.dayOfMonth().getMaximumValue() * DateTimeConstants.SECONDS_PER_DAY;
    }

    public static List<TimeRange> getDateTimeRanges(long from, long to) {
        List<TimeRange> ranges = new ArrayList<>(10);
        MutableDateTime fromDate = new MutableDateTime(from);
        fromDate.set(DateTimeFieldType.millisOfSecond(), 0);
        MutableDateTime toDate = new MutableDateTime(to);
        toDate.set(DateTimeFieldType.millisOfSecond(), 0);
        MutableDateTime tempFromTime = fromDate.copy();
        MutableDateTime tempToTime = toDate.copy();

        if (log.isDebugEnabled()) {
            log.debug("Time range: " + formatter.format(fromDate.toDate()) + "->" + formatter.format(toDate.toDate()));
        }

        if (toDate.getMillis() - fromDate.getMillis() < DateTimeConstants.MILLIS_PER_MINUTE) {<commit_msg>Test commit<commit_after>/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.analytics.esb.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeFieldType;
import org.joda.time.Days;
import org.joda.time.Hours;
import org.joda.time.Minutes;
import org.joda.time.Months;
import org.joda.time.MutableDateTime;
import org.wso2.carbon.analytics.esb.bean.TimeRange;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TimeRangeUtils {

    private static final int INTERVAL = 6;
    private static final Log log = LogFactory.getLog(TimeRangeUtils.class);
    private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");

    private TimeRangeUtils() {
    }

    public static String getSuitableTimeRangeUnit(long from, long to) {
        DateTime fromTime = new DateTime(from);
        DateTime toTime = new DateTime(to);
        RangeUnit range;
        if (Months.monthsBetween(fromTime, toTime).getMonths() >= INTERVAL) {
            range = RangeUnit.MONTH;
        } else if (Days.daysBetween(fromTime, toTime).getDays() >= INTERVAL) {
            range = RangeUnit.DAY;
        } else if (Hours.hoursBetween(fromTime, toTime).getHours() >= INTERVAL) {
            range = RangeUnit.HOUR;
        } else if (Minutes.minutesBetween(fromTime, toTime).getMinutes() >= INTERVAL) {
            range = RangeUnit.MINUTE;
        } else {
            range = RangeUnit.SECOND;
        }
        return range.name();
    }

    public static int getNoOfSecondForMonthInGivenTimestamp(long timestamp) {
        DateTime time = new DateTime(timestamp);
        return time.dayOfMonth().getMaximumValue() * DateTimeConstants.SECONDS_PER_DAY;
    }

    public static List<TimeRange> getDateTimeRanges(long from, long to) {
        List<TimeRange> ranges = new ArrayList<>(10);
        MutableDateTime fromDate = new MutableDateTime(from);
        fromDate.set(DateTimeFieldType.millisOfSecond(), 0);
        MutableDateTime toDate = new MutableDateTime(to);
        toDate.set(DateTimeFieldType.millisOfSecond(), 0);
        MutableDateTime tempFromTime = fromDate.copy();
        MutableDateTime tempToTime = toDate.copy();

        if (log.isDebugEnabled()) {
            log.debug("Time range: " + formatter.format(fromDate.toDate()) + " -> " + formatter.format(toDate.toDate()));
        }

        if (toDate.getMillis() - fromDate.getMillis() < DateTimeConstants.MILLIS_PER_MINUTE) {
{'fraction_non_alphanumeric': 0.10642879114118732, 'fraction_numerical': 0.005536757920639803, 'mean_word_length': 3.460219478737997, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4236170', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1887, 'n_words': 503}