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