Subversion Repositories bacoAlunos

Rev

Rev 1862 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1862 Rev 1873
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;
-
 
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;
3
import pt.estgp.estgweb.utils.documentBuilder.AutoImageWraperComponent;
12
import pt.estgp.estgweb.utils.documentBuilder.ImageComponent;
-
 
13
import pt.estgp.estgweb.web.controllers.utils.FileUploaded;
-
 
14
 
-
 
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;
4
 
20
 
5
/**
21
/**
6
 * Created by jorgemachado on 31/10/17.
22
 * Created by jorgemachado on 31/10/17.
7
 */
23
 */
8
public class GlobalLearningResultsChartImg extends AutoImageWraperComponent
24
public class GlobalLearningResultsChartImg extends ImageComponent
9
{
25
{
-
 
26
    /**
-
 
27
     *
-
 
28
     * @param results
-
 
29
     * @return the tmp path for generated chart
-
 
30
     * @throws IOException
-
 
31
     */
-
 
32
    public FileUploaded generateChart2tmp(UnitsLearningResultsTable results,CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException
-
 
33
    {
-
 
34
        float aprovados = results.getAprovados();
-
 
35
        float reprovados = results.getReprovados();
-
 
36
        float semElementos = results.getSemElementos();
-
 
37
        double aprovadosPercent = ((int)(results.getAprovadosPercent()*100.0))/100.0;
-
 
38
        double reprovadosPercent = ((int)(results.getReprovadosPercent()*100.0))/100.0;
-
 
39
        double semElementosPercent = ((int)(results.getSemElementosPercent()*100.0))/100.0;
-
 
40
 
-
 
41
        1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png";
-
 
42
 
-
 
43
        DefaultPieDataset data = new DefaultPieDataset();
-
 
44
        if(reprovados > 0)
-
 
45
            data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados));
-
 
46
        if(aprovados > 0)
-
 
47
            data.setValue("Aprovados " + aprovadosPercent  + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados));
-
 
48
        if(semElementos > 0)
-
 
49
            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);
-
 
51
        chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255));
-
 
52
        PiePlot plot = (RingPlot) chart.getPlot();
-
 
53
        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));
-
 
55
        //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier());
-
 
56
 
-
 
57
        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));
-
 
59
        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));
-
 
61
        plot.setOutlineVisible(false);
-
 
62
 
-
 
63
 
-
 
64
 
-
 
65
        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));
-
 
67
 
-
 
68
 
-
 
69
        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;
-
 
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);
-
 
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));
-
 
73
 
-
 
74
        FileUploaded fileUploaded = new FileUploaded();
-
 
75
        fileUploaded.setTmpName(tempName);
-
 
76
        fileUploaded.setTitle("Taxa global de aproveitamento");
-
 
77
        fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear());
-
 
78
        fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output));
-
 
79
        fileUploaded.setFileSize(output.length());
-
 
80
        fileUploaded.setExtension("png");
-
 
81
        return fileUploaded;
-
 
82
    }
-
 
83
 
-
 
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 {
-
 
85
        float aprovados = 10;
-
 
86
        float reprovados = 2;
-
 
87
        float semElementos = 4;
-
 
88
        double aprovadosPercent = ((int)10/16*100.0)/100.0;
-
 
89
        double reprovadosPercent = ((int)2/16*100.0)/100.0;
-
 
90
        double semElementosPercent = ((int)4/16*100.0)/100.0;
-
 
91
 
-
 
92
        1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png";
-
 
93
 
-
 
94
        DefaultPieDataset data = new DefaultPieDataset();
-
 
95
        if(reprovados > 0)
-
 
96
            data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados));
-
 
97
        if(aprovados > 0)
-
 
98
            data.setValue("Aprovados " + aprovadosPercent  + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados));
-
 
99
        if(semElementos > 0)
-
 
100
            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);
-
 
102
        chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255));
-
 
103
        PiePlot plot = (RingPlot) chart.getPlot();
-
 
104
        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));
-
 
106
        //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier());
-
 
107
 
-
 
108
        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));
-
 
110
        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));
-
 
112
        plot.setOutlineVisible(false);
-
 
113
 
-
 
114
 
-
 
115
 
-
 
116
        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));
-
 
118
 
-
 
119
 
-
 
120
        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;
-
 
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);
-
 
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));
-
 
124
 
-
 
125
 
-
 
126
    }
-
 
127
 
10
 
128
 
11
}
129
}
12
 
130