| | |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | |
| | | blocks.add(new HolidayTrendWordService.ChartBlock( |
| | | "“" + holidayLabel + "”假期铁路客运量情况", |
| | | chartService.lineChart("万人次", |
| | | series(years, yearData, item -> item.rail), false, 1100, 445), |
| | | // Pin the 2026 rail label for day 3 above its point so the |
| | | // 2024 label (70.6) no longer covers it; other charts keep |
| | | // automatic placement. |
| | | series(years, yearData, item -> item.rail), false, 2, |
| | | HolidayTrendChartService.DAY_LABELS, 1100, 445, |
| | | Collections.singletonList(new HolidayTrendChartService.LineLabelOverride( |
| | | 0, 2, HolidayTrendChartService.LineLabelAnchor.ABOVE))), |
| | | lineImageSize(5264785L, 2129155L))); |
| | | blocks.add(new HolidayTrendWordService.ChartBlock( |
| | | "“" + holidayLabel + "”假期水路客运量情况", |
| | |
| | | blocks.add(new HolidayTrendWordService.ChartBlock( |
| | | prefix + "普通国省道观测站平均机动车速度", |
| | | chartService.lineChart("公里/小时", |
| | | Collections.singletonList(series("平均速度", observation.speed)), false, 1100, 590), |
| | | Collections.singletonList(series("平均速度", observation.speed)), false, 2, |
| | | observation.labels, 1100, 590), |
| | | lineImageSize(5268595L, 2821305L))); |
| | | blocks.add(new HolidayTrendWordService.ChartBlock( |
| | | prefix + "普通国省道观测站平均拥挤度", |
| | | chartService.lineChart("拥挤度", |
| | | Collections.singletonList(series("平均拥挤度", observation.congestion)), false, 1100, 590), |
| | | Collections.singletonList(series("平均拥挤度", observation.congestion)), false, 2, |
| | | observation.labels, 1100, 590), |
| | | lineImageSize(5268595L, 2821305L))); |
| | | |
| | | File template = resolveTemplateFile(); |
| | |
| | | private ObservationData observationData(int year, String holidayType) { |
| | | List<HolidayCalendar> days = configService.findHolidayDays(year, holidayType); |
| | | if (days.isEmpty()) { |
| | | return new ObservationData(nulls(), nulls()); |
| | | return new ObservationData(nulls(), nulls(), HolidayTrendChartService.DAY_LABELS); |
| | | } |
| | | LocalDate start = days.get(0).getHolidayDate(); |
| | | LocalDate end = start.plusDays(HolidayTrendChartService.DAY_LABELS.size() - 1L); |
| | | LocalDate end = days.get(days.size() - 1).getHolidayDate(); |
| | | List<ObservationDailyOperation> rows = observationStationFlowMapper.selectDailyOperations(start, end); |
| | | Map<LocalDate, ObservationDailyOperation> byDate = new LinkedHashMap<>(); |
| | | for (ObservationDailyOperation row : rows) { |
| | | byDate.put(row.getObsDate(), row); |
| | | } |
| | | DateTimeFormatter labelFormat = DateTimeFormatter.ofPattern("M月d日"); |
| | | List<BigDecimal> speed = new ArrayList<>(); |
| | | List<BigDecimal> congestion = new ArrayList<>(); |
| | | for (int i = 0; i < HolidayTrendChartService.DAY_LABELS.size(); i++) { |
| | | ObservationDailyOperation row = byDate.get(start.plusDays(i)); |
| | | List<String> labels = new ArrayList<>(); |
| | | for (HolidayCalendar day : days) { |
| | | LocalDate date = day.getHolidayDate(); |
| | | ObservationDailyOperation row = byDate.get(date); |
| | | speed.add(row == null ? null : row.getAverageSpeed()); |
| | | congestion.add(row == null ? null : row.getAverageCongestion()); |
| | | labels.add(date.format(labelFormat)); |
| | | } |
| | | return new ObservationData(speed, congestion); |
| | | return new ObservationData(speed, congestion, labels); |
| | | } |
| | | |
| | | private HolidayTrendChartService.ChartSeries series(String name, List<BigDecimal> values) { |
| | |
| | | private static class ObservationData { |
| | | private final List<BigDecimal> speed; |
| | | private final List<BigDecimal> congestion; |
| | | private final List<String> labels; |
| | | |
| | | private ObservationData(List<BigDecimal> speed, List<BigDecimal> congestion) { |
| | | private ObservationData(List<BigDecimal> speed, List<BigDecimal> congestion, List<String> labels) { |
| | | this.speed = speed; |
| | | this.congestion = congestion; |
| | | this.labels = labels; |
| | | } |
| | | } |
| | | } |