Rev 1992 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1830 | jmachado | 1 | package pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components; |
2 | |||
1887 | grupo5 | 3 | import jomm.utils.BytesUtils; |
4 | import jomm.utils.MimeTypeGuesser; |
||
5 | import org.jfree.chart.ChartFactory; |
||
6 | import org.jfree.chart.JFreeChart; |
||
7 | import org.jfree.chart.plot.PiePlot; |
||
8 | import org.jfree.chart.plot.RingPlot; |
||
9 | import org.jfree.data.general.DefaultPieDataset; |
||
10 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
||
11 | import pt.estgp.estgweb.utils.Globals; |
||
12 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
||
13 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
||
1830 | jmachado | 14 | |
1887 | grupo5 | 15 | import javax.imageio.ImageIO; |
16 | import java.awt.*; |
||
17 | import java.awt.image.BufferedImage; |
||
18 | import java.io.FileOutputStream; |
||
19 | import java.io.IOException; |
||
20 | |||
1830 | jmachado | 21 | /** |
22 | * Created by jorgemachado on 31/10/17. |
||
23 | */ |
||
1887 | grupo5 | 24 | public class GlobalLearningResultsChartImg extends ImageComponent |
1830 | jmachado | 25 | { |
1887 | grupo5 | 26 | /** |
27 | * |
||
28 | * @param results |
||
29 | * @return the tmp path for generated chart |
||
30 | * @throws IOException |
||
31 | */ |
||
32 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results,CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
||
33 | { |
||
34 | float aprovados = results.getAprovados(); |
||
35 | float reprovados = results.getReprovados(); |
||
36 | float semElementos = results.getSemElementos(); |
||
37 | double aprovadosPercent = ((int)(results.getAprovadosPercent()*100.0))/100.0; |
||
38 | double reprovadosPercent = ((int)(results.getReprovadosPercent()*100.0))/100.0; |
||
39 | double semElementosPercent = ((int)(results.getSemElementosPercent()*100.0))/100.0; |
||
1830 | jmachado | 40 | |
1887 | grupo5 | 41 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
42 | |||
1974 | grupo5 | 43 | DefaultPieDataset data = new DefaultPieDataset(); |
1887 | grupo5 | 44 | if(reprovados > 0) |
1974 | grupo5 | 45 | data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados)); |
1887 | grupo5 | 46 | if(aprovados > 0) |
1974 | grupo5 | 47 | data.setValue("Aprovados " + aprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados)); |
1887 | grupo5 | 48 | if(semElementos > 0) |
1974 | grupo5 | 49 | data.setValue("Sem Elementos " + semElementosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos)); |
1927 | grupo5 | 50 | |
1974 | grupo5 | 51 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
1887 | grupo5 | 52 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
1974 | grupo5 | 53 | PiePlot plot = (RingPlot) chart.getPlot(); |
54 | plot.setLabelBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 249, 235)); |
||
55 | plot.setLabelPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(88, 88, 90)); |
||
1887 | grupo5 | 56 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
1974 | grupo5 | 57 | |
1887 | grupo5 | 58 | plot.setSectionPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 0, 0)); |
59 | plot.setSectionPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(15, 218, 10)); |
||
60 | plot.setSectionPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(200, 200, 200)); |
||
1992 | grupo5 | 61 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(249, 231, 236)); |
1974 | grupo5 | 62 | plot.setOutlineVisible(true); |
1887 | grupo5 | 63 | |
1974 | grupo5 | 64 | |
65 | |||
1887 | grupo5 | 66 | plot.setLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font( |
67 | "Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
||
68 | |||
69 | |||
70 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
||
71 | 1.5.0/docs/api/java/lang/String.html">String pathGraficoTiposAlunos = Globals.TMP_DIR + java.io.1.5.0/docs/api/java/io/File.html">File.separator + tempName; |
||
72 | java.io.1.5.0/docs/api/java/io/File.html">File output = new java.io.1.5.0/docs/api/java/io/File.html">File(pathGraficoTiposAlunos); |
||
73 | 1.5.0/docs/api/javax/imageio/ImageIO.html">ImageIO.write(image, "png", new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(output)); |
||
74 | |||
75 | FileUploaded fileUploaded = new FileUploaded(); |
||
76 | fileUploaded.setTmpName(tempName); |
||
77 | fileUploaded.setTitle("Taxa global de aproveitamento"); |
||
78 | fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear()); |
||
79 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
||
80 | fileUploaded.setFileSize(output.length()); |
||
81 | fileUploaded.setExtension("png"); |
||
82 | return fileUploaded; |
||
83 | } |
||
84 | |||
85 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
||
1974 | grupo5 | 86 | |
87 | /*float aprovados = 10; |
||
1887 | grupo5 | 88 | float reprovados = 2; |
89 | float semElementos = 4; |
||
90 | double aprovadosPercent = ((int)10/16*100.0)/100.0; |
||
91 | double reprovadosPercent = ((int)2/16*100.0)/100.0; |
||
92 | double semElementosPercent = ((int)4/16*100.0)/100.0; |
||
93 | |||
94 | String tempName = BytesUtils.generateHexKey() + ".png"; |
||
95 | |||
1974 | grupo5 | 96 | DefaultPieDataset data = new DefaultPieDataset(); |
1887 | grupo5 | 97 | if(reprovados > 0) |
1974 | grupo5 | 98 | data.setValue("Reprovados " + reprovadosPercent + "%", new Double(reprovados)); |
1887 | grupo5 | 99 | if(aprovados > 0) |
1974 | grupo5 | 100 | data.setValue("Aprovados " + aprovadosPercent + "%", new Double(aprovados)); |
1887 | grupo5 | 101 | if(semElementos > 0) |
1974 | grupo5 | 102 | data.setValue("Sem Elementos " + semElementosPercent + "%", new Double(semElementos)); |
1927 | grupo5 | 103 | |
1974 | grupo5 | 104 | //Grafico Circulo |
105 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
||
106 | |||
1927 | grupo5 | 107 | //Grafico Barras |
1974 | grupo5 | 108 | //JFreeChart chart = ChartFactory.createBarChart("OLA", null,null,null, PlotOrientation.VERTICAL, true,true,false); |
1927 | grupo5 | 109 | |
1887 | grupo5 | 110 | chart.setBackgroundPaint(new Color(255,255,255)); |
1974 | grupo5 | 111 | PiePlot plot = (RingPlot) chart.getPlot(); |
1887 | grupo5 | 112 | plot.setLabelBackgroundPaint(new Color(255, 249, 235)); |
113 | plot.setLabelPaint(new Color(88, 88, 90)); |
||
114 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
||
115 | |||
116 | plot.setSectionPaint(0, new Color(255, 0, 0)); |
||
117 | plot.setSectionPaint(1, new Color(15, 218, 10)); |
||
118 | plot.setSectionPaint(2, new Color(200, 200, 200)); |
||
119 | plot.setBackgroundPaint(new Color(255, 255, 255)); |
||
120 | plot.setOutlineVisible(false); |
||
121 | |||
122 | |||
123 | |||
124 | plot.setLabelFont(new Font( |
||
125 | "Helvetica", Font.PLAIN, 30)); |
||
126 | |||
1974 | grupo5 | 127 | |
1887 | grupo5 | 128 | BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
129 | String pathGraficoTiposAlunos = Globals.TMP_DIR + java.io.File.separator + tempName; |
||
130 | java.io.File output = new java.io.File(pathGraficoTiposAlunos); |
||
1974 | grupo5 | 131 | ImageIO.write(image, "png", new FileOutputStream(output));*/ |
1887 | grupo5 | 132 | |
133 | } |
||
134 | |||
135 | |||
136 | } |