source: ether_eccad/trunk/ECCAD_INTERFACE/WEB-INF/src/org/medias/eccad/metier/statistique/ServiceStatistique.java @ 68

Last change on this file since 68 was 68, checked in by cbipsl, 14 years ago

commit v1 eccad

  • Property svn:executable set to *
File size: 5.5 KB
Line 
1package org.medias.eccad.metier.statistique;
2
3import java.util.LinkedList;
4import java.util.List;
5import java.util.Map;
6
7
8import org.medias.eccad.helpers.LoggerPerso;
9import org.medias.eccad.helpers.SpringBeanFactory;
10import org.medias.eccad.helpers.XmlHelper;
11import org.medias.eccad.metier.generationRaster.GenerateurLegendRaster;
12import org.medias.eccad.metier.generationRaster.GenerateurLegendeImg;
13import org.medias.eccad.metier.generationRaster.GenerateurWorldFile;
14import org.medias.eccad.metier.generationRaster.InformationLegend;
15import org.medias.eccad.metier.generationRaster.colorMap.ColorMapping;
16import org.medias.eccad.metier.generationRaster.colorMap.ColorMappingLineaire;
17import org.medias.eccad.metier.traducteur.TraducteurStat;
18import org.medias.eccad.modele.ColorTab;
19import org.medias.eccad.modele.ResultatStat;
20import org.medias.eccad.modele.StatReponse;
21import org.medias.eccad.modele.Valeur;
22import org.medias.eccad.modele.Zone;
23import org.medias.eccad.persistance.dao.ColorTabDAO;
24import org.medias.eccad.persistance.exception.PersistanceException;
25import org.springframework.beans.factory.xml.XmlBeanFactory;
26
27public class ServiceStatistique {
28        private XmlBeanFactory xmlbean;
29        private StatReponse reponse;
30        private TraducteurStat traducteur;
31       
32        public ServiceStatistique() {
33                xmlbean = SpringBeanFactory.getXmlFactory();
34                traducteur = new TraducteurStat();
35        }
36       
37        public StatReponse getCarteStat(Map<String, String> criteres, long id_param, long id_produit, long id_colormap, String fonction, String id_unique) {
38                String xml = traducteur.encodeCritere(criteres, id_param, id_produit, id_colormap, fonction);
39               
40                // TODO: ici modifier pour prendre en compte la librairie de jean-luc
41                //RasterDAO rasterdao = new RasterDAO();
42                GrapheCGI rasterdao = new GrapheCGI();
43                ////system.out.println(xml);
44                reponse = decodeReponse(rasterdao.getStatistique(xml));
45                if (reponse.getError() != null && !reponse.getError().equals(""))
46                        return null;
47               
48                GenerateurWorldFile gen_worldfile = (GenerateurWorldFile) xmlbean.getBean("worldfile");
49                gen_worldfile.setPasX(reponse.getCarte().getPasX());
50                gen_worldfile.setPasY(reponse.getCarte().getPasY());
51                gen_worldfile.setPixelY(reponse.getZone().getNorthbc() - (reponse.getCarte().getPasY()/2));
52                gen_worldfile.setPixelX(reponse.getZone().getWestbc() + (reponse.getCarte().getPasY()/2));
53               
54               
55                String nom = reponse.getUrlImage();
56               
57                nom = nom.substring(0, nom.length()-4);
58                gen_worldfile.writeWorldFile(nom);
59               
60                ////system.out.println(stat.getUrlImage());
61                //return reponse.getUrlImage();
62                return reponse;
63        }
64       
65        public String getLegend(String fichier, long id_colormap, long id_grille) {
66                LoggerPerso.log(ServiceStatistique.class, LoggerPerso.DEBUG, "retour getLegend " + reponse.getMaximal() +" " + reponse.getMinimal());
67                ColorMapping colormap = getColorMap(id_colormap);
68                InformationLegend info_legend = new InformationLegend();
69                GenerateurLegendRaster gen_legend = new GenerateurLegendeImg();
70               
71                gen_legend.genereLegendVertical(colormap, info_legend.getLegendDynamic(colormap.getColorTable(), reponse.getMaximal(), reponse.getMinimal()), info_legend.getInfoSup(id_grille));
72                gen_legend.enregistreLegend(fichier+".legend.png");
73               
74                return fichier+".legend.png";
75        }
76       
77        public ResultatStat getStatistique(Map<String, String> criteres, long id_param, long id_produit, String fonction) {
78                //RasterDAO rasterdao = new RasterDAO();
79                GrapheCGI rasterdao = new GrapheCGI();
80                String xml = traducteur.encodeCritere(criteres, id_param, id_produit, new Long(-1), fonction);
81                //system.out.println(xml);
82                LoggerPerso.log(ServiceStatistique.class, LoggerPerso.DEBUG, "");
83                reponse = decodeReponse(rasterdao.getStatistique(xml));
84                if (reponse == null)
85                        return new ResultatStat("0", "0", "0", "0", "0");
86                Map<String, String> map = reponse.getStatistique();
87                return new ResultatStat(map.get("min"), map.get("max"), map.get("moyenne"), map.get("ecartType"), map.get("somme"));
88        }
89       
90        public String getGraphe(String identifiant, Map<String, String> criteres, long id_param, long id_produit, String fonction) {
91                //RasterDAO rasterdao = new RasterDAO();
92                GrapheCGI rasterdao = new GrapheCGI();
93                String xml = traducteur.encodeCritere(criteres, id_param, id_produit, new Long(-1), fonction);
94                LoggerPerso.log(ServiceStatistique.class, LoggerPerso.DEBUG, "xml ::\n" + xml);
95                String str_reponse = rasterdao.getStatistique(xml);
96                LoggerPerso.log(ServiceStatistique.class, LoggerPerso.DEBUG, "reception OK");
97                reponse = decodeReponse(str_reponse);
98                LoggerPerso.log(ServiceStatistique.class, LoggerPerso.DEBUG, "decodage OK");
99                List<Valeur> graphe;
100                if (reponse == null)
101                        graphe = new LinkedList<Valeur>();
102                else
103                        graphe = reponse.getGraphe();
104               
105                return new ServiceGraphe().genereGraphe(identifiant, graphe);
106        }
107       
108       
109       
110        public StatReponse decodeReponse(String reponse_xml) {
111                reponse = traducteur.getReponse(reponse_xml);
112               
113                if (reponse.getError() != null && !reponse.getError().equals(""))
114                        return null;
115                return reponse;
116        }
117       
118        /**
119         * Interroge la base de données pour obtenir la table de couleur de la grille
120         *
121         * @param colormapid l'identifiant de la colormap
122         * @return la table de couleur par défaut
123         */
124        private ColorMapping getColorMap(long colormapid) {
125                ColorTabDAO colorDAO = (ColorTabDAO) xmlbean.getBean("colorTabDAO");
126               
127                ColorTab colortab = null;
128               
129                try {
130                        colortab = colorDAO.getColorMapByID(colormapid);
131                } catch (PersistanceException e) {
132                        e.printStackTrace();
133                }
134               
135                ColorMapping colormap = new ColorMappingLineaire();
136                colormap.setColorTable(colortab);
137                return colormap;
138        }
139}
Note: See TracBrowser for help on using the repository browser.