Subversion Repositories SmartDukaan

Rev

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

Rev 1821 Rev 1950
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.serving.utils.FileUtils;
3
import in.shop2020.serving.utils.FileUtils;
4
import in.shop2020.serving.utils.Utils;
4
import in.shop2020.serving.utils.Utils;
5
import in.shop2020.thrift.clients.UserContextServiceClient;
-
 
6
import in.shop2020.model.v1.user.UserContextService.Client;
-
 
7
 
5
 
8
import java.io.BufferedReader;
6
import java.io.BufferedReader;
9
import java.io.File;
7
import java.io.File;
10
import java.io.FileInputStream;
8
import java.io.FileInputStream;
11
import java.io.IOException;
9
import java.io.IOException;
12
import java.io.InputStreamReader;
10
import java.io.InputStreamReader;
13
import java.net.URLEncoder;
11
import java.text.DecimalFormat;
14
import java.util.ArrayList;
12
import java.util.ArrayList;
15
import java.util.HashMap;
-
 
16
import java.util.LinkedHashMap;
13
import java.util.LinkedHashMap;
17
import java.util.List;
14
import java.util.List;
18
import java.util.Map;
15
import java.util.Map;
19
import java.util.StringTokenizer;
-
 
20
 
16
 
21
import org.apache.log4j.Logger;
17
import org.apache.log4j.Logger;
22
import org.apache.struts2.convention.annotation.Action;
18
import org.apache.struts2.convention.annotation.Action;
23
import org.apache.struts2.convention.annotation.Actions;
19
import org.apache.struts2.convention.annotation.Actions;
24
import org.apache.struts2.convention.annotation.Result;
20
import org.apache.struts2.convention.annotation.Result;
25
import org.apache.velocity.VelocityContext;
-
 
26
 
21
 
27
/**
22
/**
28
 * 
23
 * 
29
 * @author rajveer
24
 * @author rajveer
30
 * 
25
 * 
Line 35... Line 30...
35
 
30
 
36
    private static final long serialVersionUID = 1L;
31
    private static final long serialVersionUID = 1L;
37
 
32
 
38
    private static Logger log = Logger.getLogger(Class.class);
33
    private static Logger log = Logger.getLogger(Class.class);
39
 
34
 
-
 
35
    List<String> slides = new ArrayList<String>();
-
 
36
    
40
    private List<String> productList;
37
    private List<String> productList;
41
    private List<String> productNames;
38
    private List<String> productNames;
42
    private Map<String, String> snippets;
39
    private Map<String, String> snippets;
-
 
40
    private List<String> unComparedSlides;
-
 
41
    private List<String> commonSlides;
-
 
42
    
-
 
43
    private Map<String, String> slideNameImportanceMap;
-
 
44
    
-
 
45
    private Map<String, Map<String, Double>> productSlideScores;
43
 
46
    
-
 
47
    private List<String> importances = new ArrayList<String>();
-
 
48
    
44
    public CompareController() {
49
    public CompareController() {
45
        super();
50
        super();
-
 
51
        importances.add("V. Imp");
-
 
52
        importances.add("Imp");
-
 
53
        importances.add("Not Imp");
46
    }
54
    }
47
 
55
 
48
    @Actions({
56
    @Actions({
49
        @Action("/compare-mobile-phones"),
57
        @Action("/compare-mobile-phones"),
50
        @Action("/compare")
58
        @Action("/compare")
Line 66... Line 74...
66
        }
74
        }
67
        if(request.getParameter("p5") != null){
75
        if(request.getParameter("p5") != null){
68
            this.productList.add(request.getParameter("p5"));
76
            this.productList.add(request.getParameter("p5"));
69
        }
77
        }
70
        
78
        
71
        readSlideNames();
-
 
72
        
-
 
73
        return "show";
79
        return "show";
74
    }
80
    }
75
 
-
 
76
    private void readSlideNames(){
-
 
77
        
-
 
78
    }
-
 
79
    
81
    
80
    public List<String> getSlideNames() {
82
    public List<String> getSlideNames() {
81
        List<String> slides = new ArrayList<String>();
-
 
82
        productNames = new ArrayList<String>();
83
        productNames = new ArrayList<String>();
-
 
84
        slideNameImportanceMap = new LinkedHashMap<String, String>();
-
 
85
        productSlideScores = new LinkedHashMap<String, Map<String, Double>>();
-
 
86
        
83
        for (String productId : productList) {
87
        for (String productId : productList) {
84
            File f = new File(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideNamesSnippet.html");
88
            File f = new File(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideNamesSnippet.html");
85
            FileInputStream fis = null;
89
            FileInputStream fis = null;
86
            try {
90
            try {
87
                fis = new FileInputStream(f);
91
                fis = new FileInputStream(f);
88
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
92
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
89
                String line;
93
                String line;
90
                boolean isProductName = true;;
94
                boolean isProductName = true;;
-
 
95
                Map<String, Double> slideScores = new LinkedHashMap<String, Double>();
91
                while((line = br.readLine()) != null){
96
                while((line = br.readLine()) != null){
92
                    if(isProductName){
97
                    if(isProductName){
93
                        productNames.add(line); 
98
                        productNames.add(line);
-
 
99
                        productSlideScores.put(line, slideScores);
94
                        isProductName = false;
100
                        isProductName = false;
95
                        continue;
101
                        continue;
96
                    }
102
                    }
-
 
103
                    
-
 
104
                    String[] parts = line.split("!!!");
-
 
105
                    String slideName = parts[0];
-
 
106
                    String importance = parts[1];
-
 
107
                    double score = Double.parseDouble(parts[2]);
-
 
108
                    if(score > 0){
-
 
109
                        if(!slideNameImportanceMap.containsKey(slideName)){
-
 
110
                            if(!importance.equals("None")){
-
 
111
                                slideNameImportanceMap.put(slideName, importance);
-
 
112
                            }
-
 
113
                        }
-
 
114
                        if(!slideScores.containsKey(slideName)){
-
 
115
                            slideScores.put(slideName, score);
-
 
116
                        }
-
 
117
                    }
97
                    if(!slides.contains(line)){
118
                    if(!slides.contains(slideName)){
98
                        slides.add(line);
119
                        slides.add(slideName);
99
                    }
120
                    }
-
 
121
                    
100
                }
122
                }
101
            } catch (IOException e) {
123
            } catch (IOException e) {
102
                e.printStackTrace();
124
                e.printStackTrace();
103
            }
125
            }
104
        }
126
        }
105
        log.info(productNames);
127
        log.info(productNames);
-
 
128
        
-
 
129
        unComparedSlides = new ArrayList<String>();
-
 
130
        for(String slideName: slides){
-
 
131
            if(!slideNameImportanceMap.containsKey(slideName)){
-
 
132
                unComparedSlides.add(slideName);
-
 
133
            }
-
 
134
        }
106
        return slides;
135
        return slides;
107
    }
136
    }
108
    
137
    
-
 
138
    public List<String> getUncomparedSlides(){
-
 
139
        return this.unComparedSlides;
-
 
140
    }
-
 
141
    
-
 
142
    public List<String> getcommonSlides(){
-
 
143
        for(String slideName: slides){
-
 
144
            for(String productId: snippets.keySet()){
-
 
145
                
-
 
146
            }
-
 
147
        }
-
 
148
        return this.commonSlides;
-
 
149
    }
-
 
150
    
-
 
151
    public List<Double> getOverallScores(){
-
 
152
        List<Double> overallScores = new ArrayList<Double>();
-
 
153
        for(String productId : productSlideScores.keySet()){
-
 
154
            Map<String, Double> slideScores = productSlideScores.get(productId);
-
 
155
            double veryImportantSlidesScore = 0.0;
-
 
156
            double regularSlidesScore = 0.0;
-
 
157
            double notSoImportantSlidesScore = 0.0;
-
 
158
            int veryImportantSlidesCount = 0;
-
 
159
            int regularSlidesCount = 0;
-
 
160
            int notSoImportantSlidesCount = 0;
-
 
161
            
-
 
162
            for(String slideName: slideNameImportanceMap.keySet()){
-
 
163
                double score = 0.0;
-
 
164
                if(slideScores.get(slideName) != null){
-
 
165
                    score = slideScores.get(slideName);
-
 
166
                }
-
 
167
                String importance = slideNameImportanceMap.get(slideName);
-
 
168
                if(importance.equals("V. Imp")){
-
 
169
                    veryImportantSlidesScore += score;
-
 
170
                    veryImportantSlidesCount++;
-
 
171
                }
-
 
172
                if(importance.equals("Imp")){
-
 
173
                    regularSlidesScore += score;
-
 
174
                    regularSlidesCount++;
-
 
175
                }
-
 
176
                if(importance.equals("Not Imp")){
-
 
177
                    notSoImportantSlidesScore += score;
-
 
178
                    notSoImportantSlidesCount++;
-
 
179
                }
-
 
180
            }
-
 
181
            System.out.println(veryImportantSlidesScore + " \n" + veryImportantSlidesCount + " \n" + regularSlidesScore + " \n" + regularSlidesCount + " \n" + notSoImportantSlidesScore + " \n" + notSoImportantSlidesCount);
-
 
182
            double weightedScore = (55*veryImportantSlidesScore/veryImportantSlidesCount + 30*regularSlidesScore/regularSlidesCount + 15*notSoImportantSlidesScore/notSoImportantSlidesCount)/100;
-
 
183
            
-
 
184
            DecimalFormat oneDForm = new DecimalFormat("#.#");
-
 
185
            weightedScore = Double.valueOf(oneDForm.format(weightedScore));
-
 
186
            
-
 
187
            overallScores.add(weightedScore);
-
 
188
        }
-
 
189
        
-
 
190
         
-
 
191
        return overallScores;
-
 
192
    }
109
    
193
    
110
    public Map<String, String> getSnippets(){
194
    public Map<String, String> getSnippets(){
111
        if (productList != null) {
195
        if (productList != null) {
112
            snippets = new HashMap<String, String>();
196
            snippets = new LinkedHashMap<String, String>();
113
            for (String productId : productList) {
197
            for (String productId : productList) {
114
                try {
198
                try {
115
                    snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ComparisonSnippet.html"));
199
                    snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ComparisonSnippet.html"));
116
                } catch (IOException e) {
200
                } catch (IOException e) {
117
                    log.error(e);
201
                    log.error(e);
118
                }
202
                }
119
            }
203
            }
120
        }
204
        }
-
 
205
        this.commonSlides = new ArrayList<String>();
-
 
206
        
-
 
207
        return snippets;
-
 
208
    }
-
 
209
 
-
 
210
    public Map<String, String> getProductSummarySnippets(){
-
 
211
        if (productList != null) {
-
 
212
            snippets = new LinkedHashMap<String, String>();
-
 
213
            for (String productId : productList) {
-
 
214
                try {
-
 
215
                    snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "CompareProductSummarySnippet.html"));
-
 
216
                } catch (IOException e) {
-
 
217
                    log.error(e);
-
 
218
                }
-
 
219
            }
-
 
220
        }
121
        return snippets;
221
        return snippets;
122
    }
222
    }
123
    
-
 
124
    public Map<String, String> getProductSnippets(){
223
    public Map<String, String> getProductSnippets(){
125
        if (productList != null) {
224
        if (productList != null) {
126
            snippets = new HashMap<String, String>();
225
            snippets = new LinkedHashMap<String, String>();
127
            for (String productId : productList) {
226
            for (String productId : productList) {
128
                try {
227
                try {
129
                    snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "CompareProductSnippet.html"));
228
                    snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "CompareProductSnippet.html"));
130
                } catch (IOException e) {
229
                } catch (IOException e) {
131
                    log.error(e);
230
                    log.error(e);
Line 134... Line 233...
134
 
233
 
135
        }
234
        }
136
        return snippets;
235
        return snippets;
137
    }
236
    }
138
    
237
    
-
 
238
    public List<String> getProductList(){
-
 
239
        return this.productList;
-
 
240
    }
-
 
241
    
139
    public List<String> getProductNames(){
242
    public List<String> getProductNames(){
140
        return this.productNames;
243
        return this.productNames;
141
    }
244
    }
-
 
245
 
-
 
246
    public Map<String, String> getSlideNameImportanceMap(){
-
 
247
        return this.slideNameImportanceMap;
-
 
248
    }
-
 
249
    
-
 
250
    public Map<String, Map<String, Double>> getProductSlideScores(){
-
 
251
        return this.productSlideScores;
-
 
252
    }
-
 
253
    
-
 
254
    public List<String> getImportances(){
-
 
255
        return this.importances;
-
 
256
    }
142
}
257
}