Rev 1872 | 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 | |||
1872 | grupo2 | 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 | |
1872 | grupo2 | 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 | */ |
||
1872 | grupo2 | 24 | public class GlobalLearningResultsChartImg extends ImageComponent |
1830 | jmachado | 25 | { |
1934 | grupo2 | 26 | public GlobalLearningResultsChartImg() { |
27 | setWidth(200); |
||
28 | setHeight(200); |
||
29 | } |
||
30 | |||
1872 | grupo2 | 31 | /** |
32 | * |
||
33 | * @param results |
||
34 | * @return the tmp path for generated chart |
||
35 | * @throws IOException |
||
36 | */ |
||
37 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results,CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
||
38 | { |
||
39 | float aprovados = results.getAprovados(); |
||
40 | float reprovados = results.getReprovados(); |
||
41 | float semElementos = results.getSemElementos(); |
||
42 | double aprovadosPercent = ((int)(results.getAprovadosPercent()*100.0))/100.0; |
||
43 | double reprovadosPercent = ((int)(results.getReprovadosPercent()*100.0))/100.0; |
||
44 | double semElementosPercent = ((int)(results.getSemElementosPercent()*100.0))/100.0; |
||
1830 | jmachado | 45 | |
1872 | grupo2 | 46 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
47 | |||
48 | DefaultPieDataset data = new DefaultPieDataset(); |
||
49 | if(reprovados > 0) |
||
50 | data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados)); |
||
51 | if(aprovados > 0) |
||
52 | data.setValue("Aprovados " + aprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados)); |
||
53 | if(semElementos > 0) |
||
54 | data.setValue("Sem Elementos " + semElementosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos)); |
||
55 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
||
56 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
||
57 | PiePlot plot = (RingPlot) chart.getPlot(); |
||
58 | plot.setLabelBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 249, 235)); |
||
59 | plot.setLabelPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(88, 88, 90)); |
||
60 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
||
61 | |||
62 | plot.setSectionPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 0, 0)); |
||
63 | plot.setSectionPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(15, 218, 10)); |
||
64 | plot.setSectionPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(200, 200, 200)); |
||
65 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 255, 255)); |
||
66 | plot.setOutlineVisible(false); |
||
67 | |||
68 | |||
69 | |||
70 | plot.setLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font( |
||
71 | "Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
||
72 | |||
73 | |||
74 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
||
75 | 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; |
||
76 | 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); |
||
77 | 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)); |
||
78 | |||
79 | FileUploaded fileUploaded = new FileUploaded(); |
||
80 | fileUploaded.setTmpName(tempName); |
||
81 | fileUploaded.setTitle("Taxa global de aproveitamento"); |
||
82 | fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear()); |
||
83 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
||
84 | fileUploaded.setFileSize(output.length()); |
||
85 | fileUploaded.setExtension("png"); |
||
86 | return fileUploaded; |
||
87 | } |
||
88 | |||
89 | 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 { |
||
90 | float aprovados = 10; |
||
91 | float reprovados = 2; |
||
92 | float semElementos = 4; |
||
93 | double aprovadosPercent = ((int)10/16*100.0)/100.0; |
||
94 | double reprovadosPercent = ((int)2/16*100.0)/100.0; |
||
95 | double semElementosPercent = ((int)4/16*100.0)/100.0; |
||
96 | |||
97 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
||
98 | |||
99 | DefaultPieDataset data = new DefaultPieDataset(); |
||
100 | if(reprovados > 0) |
||
101 | data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados)); |
||
102 | if(aprovados > 0) |
||
103 | data.setValue("Aprovados " + aprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados)); |
||
104 | if(semElementos > 0) |
||
105 | data.setValue("Sem Elementos " + semElementosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos)); |
||
106 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
||
107 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
||
108 | PiePlot plot = (RingPlot) chart.getPlot(); |
||
109 | plot.setLabelBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 249, 235)); |
||
110 | plot.setLabelPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(88, 88, 90)); |
||
111 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
||
112 | |||
113 | plot.setSectionPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 0, 0)); |
||
114 | plot.setSectionPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(15, 218, 10)); |
||
115 | plot.setSectionPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(200, 200, 200)); |
||
116 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 255, 255)); |
||
117 | plot.setOutlineVisible(false); |
||
118 | |||
119 | |||
120 | |||
121 | plot.setLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font( |
||
122 | "Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
||
123 | |||
124 | |||
125 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
||
126 | 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; |
||
127 | 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); |
||
128 | 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)); |
||
129 | |||
130 | |||
131 | } |
||
132 | |||
133 | |||
134 | } |