Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 778 | blopes | 1 | package br.com.kronus.web; |
| 2 | |||
| 3 | import org.primefaces.model.chart.Axis; |
||
| 4 | import org.primefaces.model.chart.AxisType; |
||
| 5 | import org.primefaces.model.chart.LineChartModel; |
||
| 6 | import org.primefaces.model.chart.LineChartSeries; |
||
| 7 | |||
| 8 | import javax.annotation.PostConstruct; |
||
| 9 | import javax.faces.bean.ManagedBean; |
||
| 10 | import javax.faces.bean.ViewScoped; |
||
| 11 | import java.io.Serializable; |
||
| 12 | import java.time.LocalDateTime; |
||
| 13 | import java.time.format.DateTimeFormatter; |
||
| 14 | import java.util.ArrayList; |
||
| 15 | import java.util.List; |
||
| 16 | |||
| 17 | @ManagedBean(name = "kronusDashboardBean") |
||
| 18 | @ViewScoped |
||
| 19 | public class KronusDashboardBean implements Serializable { |
||
| 20 | |||
| 21 | private double plDia; |
||
| 22 | private int numeroTrades; |
||
| 23 | private double taxaAcerto; |
||
| 24 | |||
| 25 | private List<TradeDTO> tradesDoDia; |
||
| 26 | |||
| 27 | private LineChartModel plDiaChart; |
||
| 28 | |||
| 29 | private final DateTimeFormatter HORA_FORMATTER = DateTimeFormatter.ofPattern("HH:mm"); |
||
| 30 | |||
| 31 | public KronusDashboardBean() { |
||
| 32 | } |
||
| 33 | |||
| 34 | @PostConstruct |
||
| 35 | public void init() { |
||
| 36 | atualizarDashboard(); |
||
| 37 | } |
||
| 38 | |||
| 39 | public void atualizarDashboard() { |
||
| 40 | tradesDoDia = new ArrayList<>(); |
||
| 41 | |||
| 42 | tradesDoDia.add(new TradeDTO( |
||
| 43 | LocalDateTime.now().minusMinutes(25), |
||
| 44 | "WINZ25", |
||
| 45 | "COMPRA", |
||
| 46 | 1, |
||
| 47 | 125000.0, |
||
| 48 | 125150.0, |
||
| 49 | 150.0 |
||
| 50 | )); |
||
| 51 | |||
| 52 | tradesDoDia.add(new TradeDTO( |
||
| 53 | LocalDateTime.now().minusMinutes(10), |
||
| 54 | "WINZ25", |
||
| 55 | "VENDA", |
||
| 56 | 1, |
||
| 57 | 125180.0, |
||
| 58 | 125130.0, |
||
| 59 | -50.0 |
||
| 60 | )); |
||
| 61 | |||
| 62 | calcularResumo(); |
||
| 63 | montarGraficoPL(); |
||
| 64 | } |
||
| 65 | |||
| 66 | private void calcularResumo() { |
||
| 67 | if (tradesDoDia == null || tradesDoDia.isEmpty()) { |
||
| 68 | plDia = 0.0; |
||
| 69 | numeroTrades = 0; |
||
| 70 | taxaAcerto = 0.0; |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | |||
| 74 | numeroTrades = tradesDoDia.size(); |
||
| 75 | double somaPL = 0.0; |
||
| 76 | int vencedores = 0; |
||
| 77 | |||
| 78 | for (TradeDTO t : tradesDoDia) { |
||
| 79 | somaPL += t.getPl(); |
||
| 80 | if (t.getPl() > 0) { |
||
| 81 | vencedores++; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | plDia = somaPL; |
||
| 86 | taxaAcerto = (vencedores * 100.0) / numeroTrades; |
||
| 87 | } |
||
| 88 | |||
| 89 | private void montarGraficoPL() { |
||
| 90 | plDiaChart = new LineChartModel(); |
||
| 91 | |||
| 92 | LineChartSeries serie = new LineChartSeries(); |
||
| 93 | serie.setLabel("P/L acumulado"); |
||
| 94 | |||
| 95 | double acumulado = 0.0; |
||
| 96 | |||
| 97 | if (tradesDoDia != null) { |
||
| 98 | for (TradeDTO t : tradesDoDia) { |
||
| 99 | acumulado += t.getPl(); |
||
| 100 | String hora = t.getDataHora().format(HORA_FORMATTER); |
||
| 101 | serie.set(hora, acumulado); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | plDiaChart.addSeries(serie); |
||
| 106 | |||
| 107 | plDiaChart.setTitle("P/L Acumulado no Dia"); |
||
| 108 | plDiaChart.setLegendPosition("e"); |
||
| 109 | plDiaChart.setAnimate(true); |
||
| 110 | |||
| 111 | Axis xAxis = plDiaChart.getAxis(AxisType.X); |
||
| 112 | xAxis.setLabel("Hora"); |
||
| 113 | |||
| 114 | Axis yAxis = plDiaChart.getAxis(AxisType.Y); |
||
| 115 | yAxis.setLabel("P/L"); |
||
| 116 | } |
||
| 117 | |||
| 118 | public double getPlDia() { |
||
| 119 | return plDia; |
||
| 120 | } |
||
| 121 | |||
| 122 | public int getNumeroTrades() { |
||
| 123 | return numeroTrades; |
||
| 124 | } |
||
| 125 | |||
| 126 | public double getTaxaAcerto() { |
||
| 127 | return taxaAcerto; |
||
| 128 | } |
||
| 129 | |||
| 130 | public List<TradeDTO> getTradesDoDia() { |
||
| 131 | return tradesDoDia; |
||
| 132 | } |
||
| 133 | |||
| 134 | public LineChartModel getPlDiaChart() { |
||
| 135 | return plDiaChart; |
||
| 136 | } |
||
| 137 | } |