19 package org.sleuthkit.autopsy.report.modules.datasourcesummaryexport;
21 import java.awt.Color;
22 import java.text.DateFormat;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.Date;
27 import java.util.List;
28 import org.apache.commons.collections.CollectionUtils;
29 import org.openide.util.NbBundle.Messages;
45 "TimelinePanel_earliestLabel_title=Earliest",
46 "TimelinePanel_latestLabel_title=Latest",
47 "TimlinePanel_last30DaysChart_title=Last 30 Days",
48 "TimlinePanel_last30DaysChart_fileEvts_title=File Events",
49 "TimlinePanel_last30DaysChart_artifactEvts_title=Result Events",})
50 class ExportTimeline {
52 private final TimelineSummary timelineSummary;
54 private static final String EARLIEST_LATEST_FORMAT_STR =
"MMM d, yyyy";
55 private static final DateFormat EARLIEST_LATEST_FORMAT = TimelineSummary.getUtcFormat(EARLIEST_LATEST_FORMAT_STR);
56 private static final DateFormat CHART_FORMAT = TimelineSummary.getUtcFormat(
"MMM d, yyyy");
57 private static final int MOST_RECENT_DAYS_COUNT = 30;
59 private static final Color FILE_EVT_COLOR =
new Color(228, 22, 28);
60 private static final Color ARTIFACT_EVT_COLOR =
new Color(21, 227, 100);
66 timelineSummary =
new TimelineSummary();
80 private static List<BarChartSeries> parseChartData(List<DailyActivityAmount> recentDaysActivity,
boolean showIntermediateDates) {
82 if (CollectionUtils.isEmpty(recentDaysActivity)) {
87 List<BarChartItem> fileEvtCounts =
new ArrayList<>();
88 List<BarChartItem> artifactEvtCounts =
new ArrayList<>();
90 for (
int i = 0; i < recentDaysActivity.size(); i++) {
91 DailyActivityAmount curItem = recentDaysActivity.get(i);
93 long fileAmt = curItem.getFileActivityCount();
94 long artifactAmt = curItem.getArtifactActivityCount() * 100;
95 String formattedDate = (showIntermediateDates || i == 0 || i == recentDaysActivity.size() - 1)
96 ? TimelineSummary.formatDate(curItem.getDay(), CHART_FORMAT) :
"";
98 OrderedKey thisKey =
new OrderedKey(formattedDate, i);
99 fileEvtCounts.add(
new BarChartItem(thisKey, fileAmt));
100 artifactEvtCounts.add(
new BarChartItem(thisKey, artifactAmt));
103 return Arrays.asList(
104 new BarChartSeries(Bundle.TimlinePanel_last30DaysChart_fileEvts_title(), FILE_EVT_COLOR, fileEvtCounts),
105 new BarChartSeries(Bundle.TimlinePanel_last30DaysChart_artifactEvts_title(), ARTIFACT_EVT_COLOR, artifactEvtCounts));
115 private static DefaultCellModel<?> getEarliestLatestCell(Date date) {
116 return new DefaultCellModel<>(date, (dt) -> dt == null ?
"" : EARLIEST_LATEST_FORMAT.format(dt), EARLIEST_LATEST_FORMAT_STR);
120 "TimelinePanel_getExports_sheetName=Timeline",
121 "TimelinePanel_getExports_activityRange=Activity Range",
122 "TimelinePanel_getExports_earliest=Earliest:",
123 "TimelinePanel_getExports_latest=Latest:",
124 "TimelinePanel_getExports_dateColumnHeader=Date",
125 "TimelinePanel_getExports_chartName=Last 30 Days",})
126 List<ExcelExport.ExcelSheetExport> getExports(DataSource dataSource) {
127 DataFetcher<DataSource, TimelineSummaryData> dataFetcher = (ds) -> timelineSummary.getTimelineSummaryData(ds, MOST_RECENT_DAYS_COUNT);
128 TimelineSummaryData summaryData = ExcelExportAction.getFetchResult(dataFetcher,
"Timeline", dataSource);
129 if (summaryData == null) {
130 return Collections.emptyList();
133 return Arrays.asList(
134 new ExcelSpecialFormatExport(Bundle.TimelinePanel_getExports_sheetName(),
136 new TitledExportable(Bundle.TimelinePanel_getExports_activityRange(), Collections.emptyList()),
137 new KeyValueItemExportable(Bundle.TimelinePanel_getExports_earliest(), getEarliestLatestCell(summaryData.getMinDate())),
138 new KeyValueItemExportable(Bundle.TimelinePanel_getExports_latest(), getEarliestLatestCell(summaryData.getMaxDate())),
139 new BarChartExport(Bundle.TimelinePanel_getExports_dateColumnHeader(),
141 Bundle.TimelinePanel_getExports_chartName(),
142 parseChartData(summaryData.getMostRecentDaysActivity(),
true)))));