Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. public List<ScadaHistogram> prepareHistogram(HistogramDTO histogramDTO) {
  2. if (histogramDTO == null) {
  3. return Collections.emptyList();
  4. }
  5.  
  6. Double min = histogramDTO.getMin();
  7. Double max = histogramDTO.getMax();
  8.  
  9. if (min == null || max == null) {
  10. return Collections.emptyList();
  11. }
  12.  
  13. List<ScadaHistogram> result = new ArrayList<>();
  14. List<E5ScadaIntervalData> points = new ArrayList<>();
  15. List<E5ScadaIntervalData> allPoints = new ArrayList<>();
  16.  
  17. //pierwszy histogram jest histogramem globalnym
  18. result.add(generateHistogram(histogramDTO, points, true, null));
  19. result.get(0).setId((long) -1);
  20. result.get(0).setType("global");
  21.  
  22. //dla serii
  23. if(histogramDTO.getSeries() != null){
  24. for(HistogramSerieConfigurationDTO idWithTimeRange : histogramDTO.getSeries()){
  25. if(idWithTimeRange != null){
  26. ChartSerieDTO chartSerieDTOArg = new ChartSerieDTO();
  27. chartSerieDTOArg.setTimeRange(idWithTimeRange.getTimeRange());
  28. chartSerieDTOArg.setId(idWithTimeRange.getId());
  29. chartSerieDTOArg.setName(idWithTimeRange.getName());
  30.  
  31. //pobierz punkty
  32. ChartSerieData data = chartSerieDataProvider.getData(chartSerieDTOArg);
  33. points = data.getData();
  34.  
  35.  
  36. result.add(generateHistogram(histogramDTO, points, true, idWithTimeRange.getColor()));
  37. result.get(result.size() - 1).setId(idWithTimeRange.getId());
  38. result.get(result.size() - 1).setType("serie");
  39. result.get(result.size() - 1).setName(idWithTimeRange.getName());
  40. allPoints.addAll(points);
  41. }
  42. }
  43. }
  44. if(histogramDTO.getEquations() != null){
  45. for(HistogramSerieConfigurationDTO idWithTimeRange : histogramDTO.getEquations()){
  46. if(idWithTimeRange.getId() != null){
  47. points = getEquationPoints(idWithTimeRange.getId());
  48. if (points == null)
  49. return null;
  50.  
  51. result.add(generateHistogram(histogramDTO, points, true, idWithTimeRange.getColor()));
  52. result.get(result.size() - 1).setId(idWithTimeRange.getId());
  53. result.get(result.size() - 1).setType("calculation");
  54. result.get(result.size() - 1).setName(idWithTimeRange.getName());
  55. allPoints.addAll(points);
  56. }
  57. }
  58. }
  59.  
  60. result.get(0).setStatistics(chartDataStatisticsService.calcStatistics(allPoints));
  61. fillHistogram(result.get(0), allPoints);
  62. return result;
  63. }
  64.  
  65.  
  66. private ScadaHistogram generateHistogram(HistogramDTO histogramDTO, List<E5ScadaIntervalData> points, boolean useGlobalMinMax, String color) {
  67. //min/max do wyznaczenia granic histogramu
  68. double min, max;
  69.  
  70. StatisticsDTO statistics;
  71. if(points.size() > 0){
  72. statistics = chartDataStatisticsService.calcStatistics(points);
  73. }
  74. else {
  75. statistics = new StatisticsDTO();
  76. }
  77.  
  78. if(useGlobalMinMax){
  79. min = histogramDTO.getMin();
  80. max = histogramDTO.getMax();
  81. }
  82. else {
  83. min = statistics.getMin().getValue();
  84. max = statistics.getMax().getValue();
  85. }
  86.  
  87. ScadaHistogram histogram = new ScadaHistogram();
  88. histogram.setColor(color);
  89. List<ScadaContinuousHistogramData> cols = new ArrayList<>();
  90.  
  91. if(histogramDTO.getSplitPoints() != null && !histogramDTO.getSplitPoints().isEmpty()){
  92. cols = prepareEmptyHistogramColumnsByListOfSplitpoints(histogramDTO.getSplitPoints());
  93. }
  94. else if (histogramDTO.getNumOfSplitPoints() > 0){
  95. cols = prepareEmptyHistogramColumnsByRange(min, max, histogramDTO.getNumOfSplitPoints());
  96. }
  97.  
  98. for(ScadaContinuousHistogramData d : cols) {
  99. histogram.addColumn(d);
  100. }
  101.  
  102. if(histogram.getColumns().size() > 0){
  103. fillHistogram(histogram, points);
  104. ((ScadaContinuousHistogramData)histogram.getColumns().get(0)).setMinRange(min);
  105. ((ScadaContinuousHistogramData)histogram.getColumns().get(histogram.getColumns().size() - 1)).setMaxRange(max);
  106.  
  107. histogram.setStatistics(statistics);
  108. }
  109. return histogram;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement