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