| 1778 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 2263 |
vikas |
3 |
import in.shop2020.datalogger.EventType;
|
| 1778 |
rajveer |
4 |
import in.shop2020.serving.utils.FileUtils;
|
|
|
5 |
import in.shop2020.serving.utils.Utils;
|
| 2511 |
vikas |
6 |
import in.shop2020.utils.DataLogger;
|
| 1778 |
rajveer |
7 |
|
|
|
8 |
import java.io.BufferedReader;
|
|
|
9 |
import java.io.File;
|
|
|
10 |
import java.io.FileInputStream;
|
|
|
11 |
import java.io.IOException;
|
|
|
12 |
import java.io.InputStreamReader;
|
| 1950 |
rajveer |
13 |
import java.text.DecimalFormat;
|
| 1778 |
rajveer |
14 |
import java.util.ArrayList;
|
|
|
15 |
import java.util.LinkedHashMap;
|
|
|
16 |
import java.util.List;
|
|
|
17 |
import java.util.Map;
|
|
|
18 |
|
| 2056 |
vikas |
19 |
import org.apache.commons.lang.StringUtils;
|
| 1778 |
rajveer |
20 |
import org.apache.log4j.Logger;
|
|
|
21 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
22 |
import org.apache.struts2.convention.annotation.Actions;
|
|
|
23 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
*
|
|
|
27 |
* @author rajveer
|
|
|
28 |
*
|
|
|
29 |
*/
|
|
|
30 |
|
|
|
31 |
@Result(name = "show", location = "compare-show.vm")
|
|
|
32 |
public class CompareController extends BaseController {
|
|
|
33 |
|
|
|
34 |
private static final long serialVersionUID = 1L;
|
|
|
35 |
|
| 2944 |
chandransh |
36 |
private static Logger logger = Logger.getLogger(Class.class);
|
| 2157 |
vikas |
37 |
|
| 1950 |
rajveer |
38 |
List<String> slides = new ArrayList<String>();
|
|
|
39 |
|
| 1778 |
rajveer |
40 |
private List<String> productList;
|
|
|
41 |
private List<String> productNames;
|
|
|
42 |
private Map<String, String> snippets;
|
| 1950 |
rajveer |
43 |
private List<String> unComparedSlides;
|
|
|
44 |
private List<String> commonSlides;
|
|
|
45 |
|
|
|
46 |
private Map<String, String> slideNameImportanceMap;
|
|
|
47 |
|
|
|
48 |
private Map<String, Map<String, Double>> productSlideScores;
|
|
|
49 |
|
|
|
50 |
private List<String> importances = new ArrayList<String>();
|
|
|
51 |
|
| 1778 |
rajveer |
52 |
public CompareController() {
|
|
|
53 |
super();
|
| 1950 |
rajveer |
54 |
importances.add("V. Imp");
|
|
|
55 |
importances.add("Imp");
|
|
|
56 |
importances.add("Not Imp");
|
| 1778 |
rajveer |
57 |
}
|
|
|
58 |
|
|
|
59 |
@Actions({
|
|
|
60 |
@Action("/compare-mobile-phones"),
|
|
|
61 |
@Action("/compare")
|
|
|
62 |
})
|
|
|
63 |
|
|
|
64 |
public String index() throws SecurityException, IOException {
|
|
|
65 |
productList = new ArrayList<String>();
|
| 1821 |
rajveer |
66 |
if(request.getParameter("p1") != null){
|
|
|
67 |
this.productList.add(request.getParameter("p1"));
|
| 1778 |
rajveer |
68 |
}
|
| 1821 |
rajveer |
69 |
if(request.getParameter("p2") != null){
|
|
|
70 |
this.productList.add(request.getParameter("p2"));
|
| 1778 |
rajveer |
71 |
}
|
| 1821 |
rajveer |
72 |
if(request.getParameter("p3") != null){
|
|
|
73 |
this.productList.add(request.getParameter("p3"));
|
| 1778 |
rajveer |
74 |
}
|
| 1821 |
rajveer |
75 |
if(request.getParameter("p4") != null){
|
|
|
76 |
this.productList.add(request.getParameter("p4"));
|
| 1778 |
rajveer |
77 |
}
|
| 1821 |
rajveer |
78 |
if(request.getParameter("p5") != null){
|
|
|
79 |
this.productList.add(request.getParameter("p5"));
|
| 1778 |
rajveer |
80 |
}
|
|
|
81 |
|
| 3185 |
vikas |
82 |
DataLogger.logData(EventType.PRODUCT_COMPARE, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
|
| 2157 |
vikas |
83 |
StringUtils.join(productList, ", "));
|
| 1778 |
rajveer |
84 |
return "show";
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
public List<String> getSlideNames() {
|
|
|
88 |
productNames = new ArrayList<String>();
|
| 1950 |
rajveer |
89 |
slideNameImportanceMap = new LinkedHashMap<String, String>();
|
|
|
90 |
productSlideScores = new LinkedHashMap<String, Map<String, Double>>();
|
|
|
91 |
|
| 1778 |
rajveer |
92 |
for (String productId : productList) {
|
|
|
93 |
File f = new File(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideNamesSnippet.html");
|
|
|
94 |
FileInputStream fis = null;
|
|
|
95 |
try {
|
|
|
96 |
fis = new FileInputStream(f);
|
|
|
97 |
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
98 |
String line;
|
|
|
99 |
boolean isProductName = true;;
|
| 1950 |
rajveer |
100 |
Map<String, Double> slideScores = new LinkedHashMap<String, Double>();
|
| 1778 |
rajveer |
101 |
while((line = br.readLine()) != null){
|
|
|
102 |
if(isProductName){
|
| 1950 |
rajveer |
103 |
productNames.add(line);
|
|
|
104 |
productSlideScores.put(line, slideScores);
|
| 1778 |
rajveer |
105 |
isProductName = false;
|
|
|
106 |
continue;
|
|
|
107 |
}
|
| 1950 |
rajveer |
108 |
|
|
|
109 |
String[] parts = line.split("!!!");
|
|
|
110 |
String slideName = parts[0];
|
|
|
111 |
String importance = parts[1];
|
|
|
112 |
double score = Double.parseDouble(parts[2]);
|
|
|
113 |
if(score > 0){
|
|
|
114 |
if(!slideNameImportanceMap.containsKey(slideName)){
|
|
|
115 |
if(!importance.equals("None")){
|
|
|
116 |
slideNameImportanceMap.put(slideName, importance);
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
if(!slideScores.containsKey(slideName)){
|
|
|
120 |
slideScores.put(slideName, score);
|
|
|
121 |
}
|
| 1778 |
rajveer |
122 |
}
|
| 1950 |
rajveer |
123 |
if(!slides.contains(slideName)){
|
|
|
124 |
slides.add(slideName);
|
|
|
125 |
}
|
|
|
126 |
|
| 1778 |
rajveer |
127 |
}
|
|
|
128 |
} catch (IOException e) {
|
| 2944 |
chandransh |
129 |
logger.error("Error while reading snippet", e);
|
| 1778 |
rajveer |
130 |
}
|
|
|
131 |
}
|
| 2944 |
chandransh |
132 |
logger.info(productNames);
|
| 1950 |
rajveer |
133 |
|
|
|
134 |
unComparedSlides = new ArrayList<String>();
|
|
|
135 |
for(String slideName: slides){
|
|
|
136 |
if(!slideNameImportanceMap.containsKey(slideName)){
|
|
|
137 |
unComparedSlides.add(slideName);
|
|
|
138 |
}
|
|
|
139 |
}
|
| 1778 |
rajveer |
140 |
return slides;
|
|
|
141 |
}
|
|
|
142 |
|
| 1950 |
rajveer |
143 |
public List<String> getUncomparedSlides(){
|
|
|
144 |
return this.unComparedSlides;
|
|
|
145 |
}
|
| 1778 |
rajveer |
146 |
|
| 1950 |
rajveer |
147 |
public List<String> getcommonSlides(){
|
|
|
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);
|
| 1977 |
rajveer |
155 |
double commulativeWeightedScore = 0.0;
|
|
|
156 |
double commulativeWeights = 0.0;
|
| 1950 |
rajveer |
157 |
|
|
|
158 |
for(String slideName: slideNameImportanceMap.keySet()){
|
|
|
159 |
double score = 0.0;
|
|
|
160 |
if(slideScores.get(slideName) != null){
|
|
|
161 |
score = slideScores.get(slideName);
|
|
|
162 |
}
|
|
|
163 |
String importance = slideNameImportanceMap.get(slideName);
|
|
|
164 |
if(importance.equals("V. Imp")){
|
| 1977 |
rajveer |
165 |
commulativeWeightedScore += score*55;
|
|
|
166 |
commulativeWeights += 55;
|
| 1950 |
rajveer |
167 |
}
|
|
|
168 |
if(importance.equals("Imp")){
|
| 1977 |
rajveer |
169 |
commulativeWeightedScore += score*30;
|
|
|
170 |
commulativeWeights += 30;
|
| 1950 |
rajveer |
171 |
}
|
|
|
172 |
if(importance.equals("Not Imp")){
|
| 1977 |
rajveer |
173 |
commulativeWeightedScore += score*15;
|
|
|
174 |
commulativeWeights += 15;
|
| 1950 |
rajveer |
175 |
}
|
|
|
176 |
}
|
| 1977 |
rajveer |
177 |
double weightedScore = commulativeWeightedScore/commulativeWeights;
|
| 1950 |
rajveer |
178 |
|
|
|
179 |
DecimalFormat oneDForm = new DecimalFormat("#.#");
|
|
|
180 |
weightedScore = Double.valueOf(oneDForm.format(weightedScore));
|
|
|
181 |
|
|
|
182 |
overallScores.add(weightedScore);
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
return overallScores;
|
|
|
187 |
}
|
|
|
188 |
|
| 1778 |
rajveer |
189 |
public Map<String, String> getSnippets(){
|
|
|
190 |
if (productList != null) {
|
| 1950 |
rajveer |
191 |
snippets = new LinkedHashMap<String, String>();
|
| 1778 |
rajveer |
192 |
for (String productId : productList) {
|
|
|
193 |
try {
|
|
|
194 |
snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "ComparisonSnippet.html"));
|
|
|
195 |
} catch (IOException e) {
|
| 2944 |
chandransh |
196 |
logger.error(e);
|
| 1778 |
rajveer |
197 |
}
|
|
|
198 |
}
|
|
|
199 |
}
|
| 1950 |
rajveer |
200 |
this.commonSlides = new ArrayList<String>();
|
|
|
201 |
|
| 1778 |
rajveer |
202 |
return snippets;
|
|
|
203 |
}
|
| 1950 |
rajveer |
204 |
|
|
|
205 |
public Map<String, String> getProductSummarySnippets(){
|
|
|
206 |
if (productList != null) {
|
|
|
207 |
snippets = new LinkedHashMap<String, String>();
|
|
|
208 |
for (String productId : productList) {
|
|
|
209 |
try {
|
|
|
210 |
snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "CompareProductSummarySnippet.html"));
|
|
|
211 |
} catch (IOException e) {
|
| 2944 |
chandransh |
212 |
logger.error(e);
|
| 1950 |
rajveer |
213 |
}
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
return snippets;
|
|
|
217 |
}
|
| 1778 |
rajveer |
218 |
public Map<String, String> getProductSnippets(){
|
|
|
219 |
if (productList != null) {
|
| 1950 |
rajveer |
220 |
snippets = new LinkedHashMap<String, String>();
|
| 1778 |
rajveer |
221 |
for (String productId : productList) {
|
|
|
222 |
try {
|
|
|
223 |
snippets.put(productId, FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "CompareProductSnippet.html"));
|
|
|
224 |
} catch (IOException e) {
|
| 2944 |
chandransh |
225 |
logger.error(e);
|
| 1778 |
rajveer |
226 |
}
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
}
|
|
|
230 |
return snippets;
|
|
|
231 |
}
|
|
|
232 |
|
| 1950 |
rajveer |
233 |
public List<String> getProductList(){
|
|
|
234 |
return this.productList;
|
|
|
235 |
}
|
|
|
236 |
|
| 1778 |
rajveer |
237 |
public List<String> getProductNames(){
|
|
|
238 |
return this.productNames;
|
|
|
239 |
}
|
| 1950 |
rajveer |
240 |
|
|
|
241 |
public Map<String, String> getSlideNameImportanceMap(){
|
|
|
242 |
return this.slideNameImportanceMap;
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
public Map<String, Map<String, Double>> getProductSlideScores(){
|
|
|
246 |
return this.productSlideScores;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
public List<String> getImportances(){
|
|
|
250 |
return this.importances;
|
|
|
251 |
}
|
| 1821 |
rajveer |
252 |
}
|