String buildDynamicSection() { StringBuilder sb = new StringBuilder(); sb.append("Report name: ").append(getReportName()).append("<br>"); reportType.buildDynamicSection(sb, tzName); return sb.toString(); }
public long getFetchCount(GraphGranularityType granularity) { switch (granularity) { case DAILY: return TimeUnit.DAYS.toDays(getDuration()); case HOURLY: return TimeUnit.DAYS.toHours(getDuration()); default: return TimeUnit.DAYS.toMinutes(getDuration()); } }
private ReportResult generateReport(Path userCsvFolder, Profile profile, DashBoard dash, long now) throws Exception { int fetchCount = (int) report.reportType.getFetchCount(report.granularityType); long startFrom = now - TimeUnit.DAYS.toMillis(report.reportType.getDuration()); //truncate second, minute, hour, depending of granularity in order to do not filter first point. //https://github.com/blynkkk/blynk-server/issues/1149 startFrom = (startFrom / report.granularityType.period) * report.granularityType.period; Path output = Paths.get(userCsvFolder.toString() + ".zip"); boolean hasData = generateReport(output, profile, dash, fetchCount, startFrom); if (hasData) { sendEmail(output); return ReportResult.OK; } log.info("No data for report for user {} and reportId {}.", key.user.email, report.id); return ReportResult.NO_DATA; }
public boolean isValid() { return reportType != null && reportType.isValid() && reportSources != null && reportSources.length > 0 && BlynkEmailValidator.isValidEmails(recipients); }
private void sendEmail(Path output) throws Exception { String durationLabel = report.reportType.getDurationLabel().toLowerCase(); String subj = "Your " + durationLabel + " " + report.getReportName() + " is ready"; String gzipDownloadUrl = downloadUrl + output.getFileName(); String dynamicSection = report.buildDynamicSection(); mailWrapper.sendReportEmail(report.recipients, subj, gzipDownloadUrl, dynamicSection); }