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