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