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