Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<ScadaHistogram> prepareHistogram(HistogramDTO histogramDTO) {
- if (histogramDTO == null) {
- return Collections.emptyList();
- }
- Double min = histogramDTO.getMin();
- Double max = histogramDTO.getMax();
- if (min == null || max == null) {
- return Collections.emptyList();
- }
- List<ScadaHistogram> result = new ArrayList<>();
- List<E5ScadaIntervalData> points = new ArrayList<>();
- List<E5ScadaIntervalData> allPoints = new ArrayList<>();
- //pierwszy histogram jest histogramem globalnym
- result.add(generateHistogram(histogramDTO, points, true, null));
- result.get(0).setId((long) -1);
- result.get(0).setType("global");
- //dla serii
- if(histogramDTO.getSeries() != null){
- for(HistogramSerieConfigurationDTO idWithTimeRange : histogramDTO.getSeries()){
- if(idWithTimeRange != null){
- ChartSerieDTO chartSerieDTOArg = new ChartSerieDTO();
- chartSerieDTOArg.setTimeRange(idWithTimeRange.getTimeRange());
- chartSerieDTOArg.setId(idWithTimeRange.getId());
- chartSerieDTOArg.setName(idWithTimeRange.getName());
- //pobierz punkty
- ChartSerieData data = chartSerieDataProvider.getData(chartSerieDTOArg);
- points = data.getData();
- result.add(generateHistogram(histogramDTO, points, true, idWithTimeRange.getColor()));
- result.get(result.size() - 1).setId(idWithTimeRange.getId());
- result.get(result.size() - 1).setType("serie");
- result.get(result.size() - 1).setName(idWithTimeRange.getName());
- allPoints.addAll(points);
- }
- }
- }
- if(histogramDTO.getEquations() != null){
- for(HistogramSerieConfigurationDTO idWithTimeRange : histogramDTO.getEquations()){
- if(idWithTimeRange.getId() != null){
- points = getEquationPoints(idWithTimeRange.getId());
- if (points == null)
- return null;
- result.add(generateHistogram(histogramDTO, points, true, idWithTimeRange.getColor()));
- result.get(result.size() - 1).setId(idWithTimeRange.getId());
- result.get(result.size() - 1).setType("calculation");
- result.get(result.size() - 1).setName(idWithTimeRange.getName());
- allPoints.addAll(points);
- }
- }
- }
- result.get(0).setStatistics(chartDataStatisticsService.calcStatistics(allPoints));
- fillHistogram(result.get(0), allPoints);
- return result;
- }
- private ScadaHistogram generateHistogram(HistogramDTO histogramDTO, List<E5ScadaIntervalData> points, boolean useGlobalMinMax, String color) {
- //min/max do wyznaczenia granic histogramu
- double min, max;
- StatisticsDTO statistics;
- if(points.size() > 0){
- statistics = chartDataStatisticsService.calcStatistics(points);
- }
- else {
- statistics = new StatisticsDTO();
- }
- if(useGlobalMinMax){
- min = histogramDTO.getMin();
- max = histogramDTO.getMax();
- }
- else {
- min = statistics.getMin().getValue();
- max = statistics.getMax().getValue();
- }
- ScadaHistogram histogram = new ScadaHistogram();
- histogram.setColor(color);
- List<ScadaContinuousHistogramData> cols = new ArrayList<>();
- if(histogramDTO.getSplitPoints() != null && !histogramDTO.getSplitPoints().isEmpty()){
- cols = prepareEmptyHistogramColumnsByListOfSplitpoints(histogramDTO.getSplitPoints());
- }
- else if (histogramDTO.getNumOfSplitPoints() > 0){
- cols = prepareEmptyHistogramColumnsByRange(min, max, histogramDTO.getNumOfSplitPoints());
- }
- for(ScadaContinuousHistogramData d : cols) {
- histogram.addColumn(d);
- }
- if(histogram.getColumns().size() > 0){
- fillHistogram(histogram, points);
- ((ScadaContinuousHistogramData)histogram.getColumns().get(0)).setMinRange(min);
- ((ScadaContinuousHistogramData)histogram.getColumns().get(histogram.getColumns().size() - 1)).setMaxRange(max);
- histogram.setStatistics(statistics);
- }
- return histogram;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement