<commit_before>/**
 * 
 */
package com.thinkbiganalytics.metadata.sla.api.core;

import java.text.ParseException;
import java.util.Date;

import javax.inject.Inject;

import org.joda.time.DateTime;
import org.quartz.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thinkbiganalytics.calendar.HolidayCalendarService;
import com.thinkbiganalytics.metadata.sla.api.AssessmentResult;
import com.thinkbiganalytics.metadata.sla.api.Metric;
import com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessmentException;
import com.thinkbiganalytics.metadata.sla.spi.MetricAssessmentBuilder;
import com.thinkbiganalytics.metadata.sla.spi.MetricAssessor;
import com.thinkbiganalytics.pipelinecontroller.repositories.FeedRepository;
import com.thinkbiganalytics.pipelinecontroller.rest.dataobjects.ExecutedFeed;
import com.thinkbiganalytics.scheduler.util.CronExpressionUtil;

/**
 *
 * @author <NAME>
 */
public class FeedOnTimeArrivalMetricAssessor implements MetricAssessor<FeedOnTimeArrivalMetric> {
    private static final Logger LOG = LoggerFactory.getLogger(FeedOnTimeArrivalMetricAssessor.class);
    
    @Inject
    private FeedRepository feedRepository;
    
    @Inject
    private HolidayCalendarService calendarService;
    

    /* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.sla.spi.MetricAssessor#accepts(com.thinkbiganalytics.metadata.sla.api.Metric)
     */
    @Override
    public boolean accepts(Metric metric) {
        return metric instanceof FeedOnTimeArrivalMetric;
    }

    /* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.sla.spi.MetricAssessor#assess(com.thinkbiganalytics.metadata.sla.api.Metric, com.thinkbiganalytics.metadata.sla.spi.MetricAssessmentBuilder)
     */
    @Override
    @SuppressWarnings("unchecked")
    public void assess(FeedOnTimeArrivalMetric metric, MetricAssessmentBuilder builder) {
        LOG.debug("Assessing metric: ", metric);
       
        builder.metric(metric);
        
        Calendar calendar = getCalendar(metric);
        String feedName = metric.getFeedName();
        ExecutedFeed feed = this.feedRepository.findLastCompletedFeed(feedName);
        
        if (feed == null) {
            LOG.debug("No feed with the specified name could be found: {}", feedName);
            
            builder.message("No feed with the specified name could be found: " + feedName)
                   .result(AssessmentResult.FAILURE);
            return;
        }
        
        DateTime lastFeedTime = feed.getEndTime();
        Date expectedDate = CronExpressionUtil.getPreviousFireTime(metric.getExpectedExpression());
        DateTime expectedTime = new DateTime(expectedDate);
        DateTime lateTime = expectedTime.plus(metric.getLatePeriod());
        DateTime asOfTime = expectedTime.minus(metric.getAsOfPeriod());
        boolean isHoliday = ! calendar.isTimeIncluded(asOfTime.getMillis());

        builder.compareWith(expectedDate, feedName);
        
        if (isHoliday) {
            LOG.debug("No data expected for feed {} due to a holiday", feedName);
            
            builder.message("No data expected for feed " + feedName + " due to a holiday")
                   .result(AssessmentResult.SUCCESS);
        } else if (lastFeedTime.isAfter(expectedTime) && lastFeedTime.isBefore(lateTime)) {
            LOG.debug("Data for feed {} arrived on {}, which was before late time: ", feedName, lastFeedTime, lateTime);
            
            builder.message("Data for feed " + feedName + " arrived on " + lastFeedTime + ", which was before late time: " + lateTime)
                   .result(AssessmentResult.SUCCESS);
        } else {
            LOG.debug("Data for feed {} has not arrived before the late time: ", feedName, lateTime);
            
            builder.message("Data for feed " + feedName + " has not arrived before the late time: " + lateTime+"\n The last successful feed was on "+lastFeedTime )
                    .result(AssessmentResult.FAILURE);
        }
    }

    private Calendar getCalendar(FeedOnTimeArrivalMetric metric) {
        return this.calendarService.getCalendar(metric.getCalendarName());
    }

}
<commit_msg>remove pivot chart from jobs page<commit_after>/**
 * 
 */
package com.thinkbiganalytics.metadata.sla.api.core;

import java.text.ParseException;
import java.util.Date;

import javax.inject.Inject;

import org.joda.time.DateTime;
import org.quartz.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thinkbiganalytics.calendar.HolidayCalendarService;
import com.thinkbiganalytics.metadata.sla.api.AssessmentResult;
import com.thinkbiganalytics.metadata.sla.api.Metric;
import com.thinkbiganalytics.metadata.sla.api.ServiceLevelAssessmentException;
import com.thinkbiganalytics.metadata.sla.spi.MetricAssessmentBuilder;
import com.thinkbiganalytics.metadata.sla.spi.MetricAssessor;
import com.thinkbiganalytics.pipelinecontroller.repositories.FeedRepository;
import com.thinkbiganalytics.pipelinecontroller.rest.dataobjects.ExecutedFeed;
import com.thinkbiganalytics.scheduler.util.CronExpressionUtil;

/**
 *
 * @author <NAME>
 */
public class FeedOnTimeArrivalMetricAssessor implements MetricAssessor<FeedOnTimeArrivalMetric> {
    private static final Logger LOG = LoggerFactory.getLogger(FeedOnTimeArrivalMetricAssessor.class);
    
    @Inject
    private FeedRepository feedRepository;
    
    @Inject
    private HolidayCalendarService calendarService;
    

    /* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.sla.spi.MetricAssessor#accepts(com.thinkbiganalytics.metadata.sla.api.Metric)
     */
    @Override
    public boolean accepts(Metric metric) {
        return metric instanceof FeedOnTimeArrivalMetric;
    }

    /* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.sla.spi.MetricAssessor#assess(com.thinkbiganalytics.metadata.sla.api.Metric, com.thinkbiganalytics.metadata.sla.spi.MetricAssessmentBuilder)
     */
    @Override
    @SuppressWarnings("unchecked")
    public void assess(FeedOnTimeArrivalMetric metric, MetricAssessmentBuilder builder) {
        LOG.debug("Assessing metric: ", metric);
       
        builder.metric(metric);
        
        Calendar calendar = getCalendar(metric);
        String feedName = metric.getFeedName();
        ExecutedFeed feed = this.feedRepository.findLastCompletedFeed(feedName);
        
        if (feed == null) {
            LOG.debug("No feed with the specified name could be found: {}", feedName);
            
            builder.message("No feed with the specified name could be found: " + feedName)
                   .result(AssessmentResult.FAILURE);
            return;
        }
        
        DateTime lastFeedTime = feed.getEndTime();
        Date expectedDate = CronExpressionUtil.getPreviousFireTime(metric.getExpectedExpression());
        DateTime expectedTime = new DateTime(expectedDate);
        DateTime lateTime = expectedTime.plus(metric.getLatePeriod());
        DateTime asOfTime = expectedTime.minus(metric.getAsOfPeriod());
        boolean isHoliday = !calendar.isTimeIncluded(asOfTime.getMillis());

        builder.compareWith(expectedDate, feedName);

       // LOG.info("isHoliday for "+feed.getName()+" returned "+isHoliday+" for Calendar "+metric.getCalendarName()+" with asOfDate as "+asOfTime);
        if (isHoliday) {
            LOG.debug("No data expected for feed {} due to a holiday", feedName);
            
            builder.message("No data expected for feed " + feedName + " due to a holiday")
                   .result(AssessmentResult.SUCCESS);
        } else if (lastFeedTime.isAfter(expectedTime) && lastFeedTime.isBefore(lateTime)) {
            LOG.debug("Data for feed {} arrived on {}, which was before late time: ", feedName, lastFeedTime, lateTime);
            
            builder.message("Data for feed " + feedName + " arrived on " + lastFeedTime + ", which was before late time: " + lateTime)
                   .result(AssessmentResult.SUCCESS);
        } else {
            LOG.debug("Data for feed {} has not arrived before the late time: ", feedName, lateTime);
            
            builder.message("Data for feed " + feedName + " has not arrived before the late time: " + lateTime+"\n The last successful feed was on "+lastFeedTime )
                    .result(AssessmentResult.FAILURE);
        }
    }

    private Calendar getCalendar(FeedOnTimeArrivalMetric metric) {
        return this.calendarService.getCalendar(metric.getCalendarName());
    }

}

{'fraction_non_alphanumeric': 0.09736379613356766, 'fraction_numerical': 0.00046865846514352667, 'mean_word_length': 3.242544731610338, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2410930', 'n_tokens_mistral': 2370, 'n_tokens_neox': 2332, 'n_words': 481}