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