Rev 1919 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1919 | Rev 1931 | ||
---|---|---|---|
Line 1... | Line 1... | ||
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; |
|
- | 4 | import jomm.utils.MimeTypeGuesser; |
|
3 | import org.apache.commons.fileupload.FileUpload; |
5 | import org.apache.commons.fileupload.FileUpload; |
- | 6 | import org.jfree.chart.ChartFactory; |
|
- | 7 | import org.jfree.chart.JFreeChart; |
|
- | 8 | import org.jfree.chart.axis.CategoryAxis; |
|
- | 9 | import org.jfree.chart.axis.NumberAxis; |
|
- | 10 | import org.jfree.chart.block.BlockBorder; |
|
- | 11 | import org.jfree.chart.labels.ItemLabelAnchor; |
|
- | 12 | import org.jfree.chart.labels.ItemLabelPosition; |
|
- | 13 | import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; |
|
- | 14 | import org.jfree.chart.plot.CategoryPlot; |
|
- | 15 | import org.jfree.chart.plot.PiePlot; |
|
- | 16 | import org.jfree.chart.plot.PlotOrientation; |
|
- | 17 | import org.jfree.chart.plot.RingPlot; |
|
- | 18 | import org.jfree.chart.renderer.category.StackedBarRenderer; |
|
- | 19 | import org.jfree.chart.renderer.category.StandardBarPainter; |
|
- | 20 | import org.jfree.chart.title.LegendTitle; |
|
- | 21 | import org.jfree.data.category.DefaultCategoryDataset; |
|
- | 22 | import org.jfree.data.general.DefaultPieDataset; |
|
- | 23 | import org.jfree.ui.RectangleInsets; |
|
- | 24 | import org.jfree.ui.TextAnchor; |
|
- | 25 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
|
- | 26 | import pt.estgp.estgweb.utils.Globals; |
|
4 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
27 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
- | 28 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
|
- | 29 | ||
- | 30 | import javax.imageio.ImageIO; |
|
- | 31 | import java.awt.*; |
|
- | 32 | import java.awt.image.BufferedImage; |
|
- | 33 | import java.io.FileOutputStream; |
|
- | 34 | import java.io.IOException; |
|
- | 35 | import java.text.DecimalFormat; |
|
- | 36 | import java.text.NumberFormat; |
|
- | 37 | import java.util.List; |
|
5 | 38 | ||
6 | /** |
39 | /** |
7 | * Created by jorgemachado on 31/10/17. |
40 | * Created by jorgemachado on 31/10/17. |
8 | */ |
41 | */ |
9 | public class LearningResultsChartSem extends ImageComponent |
42 | public class LearningResultsChartSem extends ImageComponent |
10 | { |
43 | { |
11 | 1.5.0/docs/api/java/lang/String.html">String semesterCode; |
44 | 1.5.0/docs/api/java/lang/String.html">String semesterCode; |
12 | 45 | ||
- | 46 | @1.5.0/docs/api/java/lang/Override.html">Override |
|
- | 47 | public 1.5.0/docs/api/java/lang/String.html">String getInternalCode() { |
|
- | 48 | return getSemesterCode(); |
|
- | 49 | } |
|
13 | 50 | ||
14 | public LearningResultsChartSem() { |
51 | public LearningResultsChartSem() { |
15 | } |
52 | } |
16 | 53 | ||
17 | public LearningResultsChartSem(1.5.0/docs/api/java/lang/String.html">String semesterCode) { |
54 | public LearningResultsChartSem(1.5.0/docs/api/java/lang/String.html">String semesterCode) { |
18 | this.semesterCode = semesterCode; |
55 | this.semesterCode = semesterCode; |
- | 56 | ||
19 | } |
57 | } |
20 | 58 | ||
21 | public 1.5.0/docs/api/java/lang/String.html">String getSemesterCode() { |
59 | public 1.5.0/docs/api/java/lang/String.html">String getSemesterCode() { |
22 | return semesterCode; |
60 | return semesterCode; |
23 | } |
61 | } |
24 | 62 | ||
25 | public void setSemesterCode(1.5.0/docs/api/java/lang/String.html">String semesterCode) { |
63 | public void setSemesterCode(1.5.0/docs/api/java/lang/String.html">String semesterCode) { |
26 | this.semesterCode = semesterCode; |
64 | this.semesterCode = semesterCode; |
27 | } |
65 | } |
28 | 66 | ||
- | 67 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results, CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
|
- | 68 | List<UnitsLearningResultYear> years = results.getYears(); |
|
- | 69 | ||
- | 70 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
|
- | 71 | ||
- | 72 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
|
- | 73 | for (UnitsLearningResultYear year : years) { |
|
- | 74 | for (UnitsLearningResultSemester semester : year.getSemesters()) { |
|
- | 75 | if (semester.getSemestre().equals(getSemesterCode())) { |
|
- | 76 | for (UnitsLearningResultUc uc : semester.getUcs()) { |
|
- | 77 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getSemElementosPercent()), "Sem elementos", uc.getName()); |
|
- | 78 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getReprovadosPercent()), "Reprovados", uc.getName()); |
|
- | 79 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getAprovadosPercent()), "Aprovados", uc.getName()); |
|
- | 80 | } |
|
- | 81 | break; |
|
- | 82 | } |
|
- | 83 | } |
|
- | 84 | } |
|
- | 85 | ||
- | 86 | ||
- | 87 | JFreeChart chart = ChartFactory.createStackedBarChart( |
|
- | 88 | null, |
|
- | 89 | null, |
|
- | 90 | null, |
|
- | 91 | data, |
|
- | 92 | PlotOrientation.HORIZONTAL, |
|
- | 93 | true, |
|
- | 94 | false, |
|
- | 95 | false); |
|
- | 96 | ||
- | 97 | chart.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
|
- | 98 | CategoryPlot plot = (CategoryPlot) chart.getPlot(); |
|
- | 99 | plot.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
|
- | 100 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.GRAY); |
|
- | 101 | plot.setRangeGridlinesVisible(true); |
|
- | 102 | //plot.setRangeGridlineStroke(new BasicStroke(1.0f)); |
|
- | 103 | ||
- | 104 | RectangleInsets chartRectangle = new RectangleInsets(0,0,30F,0); |
|
- | 105 | chart.setPadding(chartRectangle); |
|
- | 106 | ||
- | 107 | plot.getDomainAxis().setTickLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 25)); |
|
- | 108 | plot.getRangeAxis().setTickLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 25)); |
|
- | 109 | ||
- | 110 | StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); |
|
- | 111 | // Remover gradiente das barras |
|
- | 112 | renderer.setBarPainter(new StandardBarPainter()); |
|
- | 113 | renderer.setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(237,127,32)); |
|
- | 114 | renderer.setSeriesPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(255,198,0)); |
|
- | 115 | renderer.setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(122,173,38)); |
|
- | 116 | renderer.setMaximumBarWidth(0.2); |
|
- | 117 | ||
- | 118 | renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new 1.5.0/docs/api/java/text/DecimalFormat.html">DecimalFormat("#.##'%'"))); |
|
- | 119 | renderer.setBaseItemLabelsVisible(true); |
|
- | 120 | renderer.setBaseItemLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica",1.5.0/docs/api/java/awt/Font.html">Font.PLAIN,25)); |
|
- | 121 | ||
- | 122 | LegendTitle legend = chart.getLegend(); |
|
- | 123 | legend.setItemFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN,25)); |
|
- | 124 | legend.setFrame(BlockBorder.NONE); |
|
- | 125 | ||
- | 126 | ||
- | 127 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
|
- | 128 | 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; |
|
- | 129 | 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); |
|
- | 130 | 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)); |
|
- | 131 | ||
- | 132 | FileUploaded fileUploaded = new FileUploaded(); |
|
- | 133 | fileUploaded.setTmpName(tempName); |
|
- | 134 | fileUploaded.setTitle("Taxa global de aproveitamento"); |
|
- | 135 | fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear()); |
|
- | 136 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
|
- | 137 | fileUploaded.setFileSize(output.length()); |
|
- | 138 | fileUploaded.setExtension("png"); |
|
- | 139 | ||
- | 140 | return fileUploaded; |
|
- | 141 | } |
|
29 | 142 | ||
30 | } |
143 | } |