Search in sources :

Example 46 with DateTimeZone

use of org.joda.time.DateTimeZone in project SeriesGuide by UweTrottmann.

the class TimeToolsTest method test_parseEpisodeReleaseTime_NoHourPastMidnight.

@Test
public void test_parseEpisodeReleaseTime_NoHourPastMidnight() {
    // ensure episodes releasing in the hour past midnight are NOT moved to the next day
    // if it is a Netflix show
    DateTimeZone showTimeZone = DateTimeZone.forID(AMERICA_NEW_YORK);
    String deviceTimeZone = AMERICA_LOS_ANGELES;
    long episodeReleaseTime = TimeTools.parseEpisodeReleaseDate(null, showTimeZone, // +one day here
    "2013-06-01", // 00:35
    new LocalTime(0, 35), UNITED_STATES, "Netflix", deviceTimeZone);
    System.out.println("Release time: " + episodeReleaseTime + " " + new Date(episodeReleaseTime));
    assertThat(episodeReleaseTime).isEqualTo(1370072100000L);
}
Also used : LocalTime(org.joda.time.LocalTime) DateTimeZone(org.joda.time.DateTimeZone) Date(java.util.Date) Test(org.junit.Test)

Example 47 with DateTimeZone

use of org.joda.time.DateTimeZone in project SeriesGuide by UweTrottmann.

the class TimeToolsTest method test_parseEpisodeReleaseTime_HourPastMidnight.

@Test
public void test_parseEpisodeReleaseTime_HourPastMidnight() {
    // ensure episodes releasing in the hour past midnight are moved to the next day
    // e.g. if 00:35, the episode date is typically (wrongly) that of the previous day
    // this is common for late night shows, e.g. "Monday night" is technically "early Tuesday"
    DateTimeZone showTimeZone = DateTimeZone.forID(AMERICA_NEW_YORK);
    String deviceTimeZone = AMERICA_LOS_ANGELES;
    long episodeReleaseTime = TimeTools.parseEpisodeReleaseDate(null, showTimeZone, "2013-05-31", // 00:35
    new LocalTime(0, 35), UNITED_STATES, null, deviceTimeZone);
    System.out.println("Release time: " + episodeReleaseTime + " " + new Date(episodeReleaseTime));
    assertThat(episodeReleaseTime).isEqualTo(1370072100000L);
}
Also used : LocalTime(org.joda.time.LocalTime) DateTimeZone(org.joda.time.DateTimeZone) Date(java.util.Date) Test(org.junit.Test)

Example 48 with DateTimeZone

use of org.joda.time.DateTimeZone in project SeriesGuide by UweTrottmann.

the class TimeToolsTest method test_parseEpisodeReleaseTime_Country.

@Test
public void test_parseEpisodeReleaseTime_Country() {
    // ensure a German show has its local release time correctly converted to UTC time
    // (we can be sure that in May there is always DST in effect in Europe/Berlin
    // so this test will likely not break if DST rules change)
    DateTimeZone showTimeZone = DateTimeZone.forID(EUROPE_BERLIN);
    String deviceTimeZone = AMERICA_LOS_ANGELES;
    long episodeReleaseTime = TimeTools.parseEpisodeReleaseDate(null, showTimeZone, "2013-05-31", // 20:00
    new LocalTime(20, 0), GERMANY, null, deviceTimeZone);
    System.out.println("Release time: " + episodeReleaseTime + " " + new Date(episodeReleaseTime));
    assertThat(episodeReleaseTime).isEqualTo(1370023200000L);
}
Also used : LocalTime(org.joda.time.LocalTime) DateTimeZone(org.joda.time.DateTimeZone) Date(java.util.Date) Test(org.junit.Test)

Example 49 with DateTimeZone

use of org.joda.time.DateTimeZone in project pinot by linkedin.

the class AnomalyReportGenerator method buildReport.

public void buildReport(long startTime, long endTime, List<MergedAnomalyResultDTO> anomalies, String subject, ThirdEyeAnomalyConfiguration configuration, boolean includeSentAnomaliesOnly, String emailRecipients, String fromEmail, String alertConfigName, boolean includeSummary) {
    if (anomalies == null || anomalies.size() == 0) {
        LOG.info("No anomalies found to send email, please check the parameters.. exiting");
    } else {
        Set<String> metrics = new HashSet<>();
        int alertedAnomalies = 0;
        int feedbackCollected = 0;
        int trueAlert = 0;
        int falseAlert = 0;
        int nonActionable = 0;
        List<AnomalyReportDTO> anomalyReportDTOList = new ArrayList<>();
        List<String> anomalyIds = new ArrayList<>();
        for (MergedAnomalyResultDTO anomaly : anomalies) {
            metrics.add(anomaly.getMetric());
            if (anomaly.getFeedback() != null) {
                feedbackCollected++;
                if (anomaly.getFeedback().getFeedbackType().equals(AnomalyFeedbackType.ANOMALY)) {
                    trueAlert++;
                } else if (anomaly.getFeedback().getFeedbackType().equals(AnomalyFeedbackType.NOT_ANOMALY)) {
                    falseAlert++;
                } else {
                    nonActionable++;
                }
            }
            String feedbackVal = getFeedback(anomaly.getFeedback() == null ? "Not Resolved" : "Resolved(" + anomaly.getFeedback().getFeedbackType().name() + ")");
            DateTimeZone dateTimeZone = Utils.getDataTimeZone(anomaly.getCollection());
            AnomalyReportDTO anomalyReportDTO = new AnomalyReportDTO(String.valueOf(anomaly.getId()), getAnomalyURL(anomaly, configuration.getDashboardHost()), String.format("%.2f", anomaly.getAvgBaselineVal()), String.format("%.2f", anomaly.getAvgCurrentVal()), getDimensionsString(anomaly.getDimensions()), String.format("%.2f hours (%s to %s) %s", getTimeDiffInHours(anomaly.getStartTime(), anomaly.getEndTime()), getDateString(anomaly.getStartTime(), dateTimeZone), getDateString(anomaly.getEndTime(), dateTimeZone), // duration
            getTimezoneString(dateTimeZone)), feedbackVal, anomaly.getFunction().getFunctionName(), // lift
            String.format("%+.2f%%", anomaly.getWeight() * 100), getLiftDirection(anomaly.getWeight()), anomaly.getMetric());
            if (anomaly.isNotified()) {
                alertedAnomalies++;
            }
            // include notified alerts only in the email
            if (includeSentAnomaliesOnly) {
                if (anomaly.isNotified()) {
                    anomalyReportDTOList.add(anomalyReportDTO);
                    anomalyIds.add(anomalyReportDTO.getAnomalyId());
                }
            } else {
                anomalyReportDTOList.add(anomalyReportDTO);
                anomalyIds.add(anomalyReportDTO.getAnomalyId());
            }
        }
        HtmlEmail email = new HtmlEmail();
        DateTimeZone timeZone = DateTimeZone.forTimeZone(AlertTaskRunnerV2.DEFAULT_TIME_ZONE);
        DataReportHelper.DateFormatMethod dateFormatMethod = new DataReportHelper.DateFormatMethod(timeZone);
        Map<String, Object> templateData = new HashMap<>();
        templateData.put("timeZone", timeZone);
        templateData.put("dateFormat", dateFormatMethod);
        templateData.put("startTime", startTime);
        templateData.put("endTime", endTime);
        templateData.put("anomalyCount", anomalies.size());
        templateData.put("metricsCount", metrics.size());
        templateData.put("notifiedCount", alertedAnomalies);
        templateData.put("feedbackCount", feedbackCollected);
        templateData.put("trueAlertCount", trueAlert);
        templateData.put("falseAlertCount", falseAlert);
        templateData.put("nonActionableCount", nonActionable);
        templateData.put("anomalyDetails", anomalyReportDTOList);
        templateData.put("alertConfigName", alertConfigName);
        templateData.put("includeSummary", includeSummary);
        templateData.put("reportGenerationTimeMillis", System.currentTimeMillis());
        templateData.put("dashboardHost", configuration.getDashboardHost());
        templateData.put("anomalyIds", Joiner.on(",").join(anomalyIds));
        boolean isSingleAnomalyEmail = false;
        String imgPath = null;
        if (anomalyReportDTOList.size() == 1) {
            isSingleAnomalyEmail = true;
            AnomalyReportDTO singleAnomaly = anomalyReportDTOList.get(0);
            subject = subject + " - " + singleAnomaly.getMetric();
            imgPath = EmailScreenshotHelper.takeGraphScreenShot(singleAnomaly.getAnomalyId(), configuration);
            String cid = "";
            try {
                cid = email.embed(new File(imgPath));
            } catch (Exception e) {
                LOG.error("Exception while embedding screenshot for anomaly {}", singleAnomaly.getAnomalyId(), e);
            }
            templateData.put("cid", cid);
        }
        buildEmailTemplateAndSendAlert(templateData, configuration.getSmtpConfiguration(), subject, emailRecipients, fromEmail, isSingleAnomalyEmail, email);
        if (StringUtils.isNotBlank(imgPath)) {
            try {
                Files.deleteIfExists(new File(imgPath).toPath());
            } catch (IOException e) {
                LOG.error("Exception in deleting screenshot {}", imgPath, e);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HtmlEmail(org.apache.commons.mail.HtmlEmail) IOException(java.io.IOException) DateTimeZone(org.joda.time.DateTimeZone) IOException(java.io.IOException) MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) File(java.io.File) HashSet(java.util.HashSet)

Example 50 with DateTimeZone

use of org.joda.time.DateTimeZone in project pinot by linkedin.

the class DetectionJobRunner method alignTimestampsToDataTimezone.

private DateTime alignTimestampsToDataTimezone(DateTime inputDateTime, String collection) {
    try {
        DatasetConfigDTO datasetConfig = DAO_REGISTRY.getDatasetConfigDAO().findByDataset(collection);
        TimeSpec timespec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
        TimeGranularity dataGranularity = timespec.getDataGranularity();
        String timeFormat = timespec.getFormat();
        if (dataGranularity.getUnit().equals(TimeUnit.DAYS)) {
            DateTimeZone dataTimeZone = Utils.getDataTimeZone(collection);
            DateTimeFormatter inputDataDateTimeFormatter = DateTimeFormat.forPattern(timeFormat).withZone(dataTimeZone);
            long inputMillis = inputDateTime.getMillis();
            String inputDateTimeString = inputDataDateTimeFormatter.print(inputMillis);
            long timeZoneOffsetMillis = inputDataDateTimeFormatter.parseMillis(inputDateTimeString);
            inputDateTime = new DateTime(timeZoneOffsetMillis);
        }
    } catch (Exception e) {
        LOG.error("Exception in aligning timestamp to data time zone", e);
    }
    return inputDateTime;
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Aggregations

DateTimeZone (org.joda.time.DateTimeZone)263 DateTime (org.joda.time.DateTime)123 ArrayList (java.util.ArrayList)36 Test (org.testng.annotations.Test)35 LocalDate (org.joda.time.LocalDate)27 Test (org.junit.Test)21 TimeIntervalRounding (org.elasticsearch.common.rounding.Rounding.TimeIntervalRounding)18 TimeUnitRounding (org.elasticsearch.common.rounding.Rounding.TimeUnitRounding)18 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)17 IOException (java.io.IOException)16 HashMap (java.util.HashMap)15 UUID (java.util.UUID)14 TimeFormat (org.gephi.graph.api.TimeFormat)13 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)12 Date (java.util.Date)12 Chronology (org.joda.time.Chronology)12 LocalDateTime (org.joda.time.LocalDateTime)12 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)11 LocalTime (org.joda.time.LocalTime)10 SubscriptionBaseTransition (org.killbill.billing.subscription.api.user.SubscriptionBaseTransition)10