| 3100 |
vikas |
1 |
<%@page import="com.google.appengine.api.datastore.FetchOptions"%>
|
|
|
2 |
<%@page import="java.util.ArrayList"%>
|
|
|
3 |
<%@page import="in.shop2020.model.Item"%>
|
|
|
4 |
<%@page import="in.shop2020.server.ItemRepository"%>
|
| 3013 |
vikas |
5 |
<%@page import="java.util.Map"%>
|
|
|
6 |
<%@page import="java.util.HashMap"%>
|
|
|
7 |
<%@page import="java.util.Calendar"%>
|
|
|
8 |
<%@page import="java.util.Date"%>
|
|
|
9 |
<%@page import="java.util.TimeZone"%>
|
|
|
10 |
<%@page import="java.text.SimpleDateFormat"%>
|
|
|
11 |
<%@page import="com.google.appengine.api.datastore.Query.SortDirection"%>
|
|
|
12 |
<%@page import="java.util.Map.Entry"%>
|
|
|
13 |
<%@ page import="java.util.List" %>
|
|
|
14 |
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
|
|
|
15 |
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
|
|
|
16 |
<%@ page import="com.google.appengine.api.datastore.Query" %>
|
|
|
17 |
<%@ page import="com.google.appengine.api.datastore.Entity" %>
|
|
|
18 |
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
|
|
|
19 |
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
|
|
20 |
|
|
|
21 |
<html>
|
|
|
22 |
<head>
|
|
|
23 |
<link rel="stylesheet" href="/DataTables/media/css/demo_table.css" type="text/css" />
|
|
|
24 |
<link rel="stylesheet" href="/DataTables/extras/TableTools/media/css/TableTools.css" type="text/css" />
|
|
|
25 |
</head>
|
|
|
26 |
<body>
|
|
|
27 |
<%
|
|
|
28 |
SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
29 |
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
|
|
|
30 |
String dateStr = request.getParameter("date");
|
| 3100 |
vikas |
31 |
ItemRepository itemRepository = new ItemRepository();
|
|
|
32 |
List<Item> items = itemRepository.getAll();
|
|
|
33 |
Map<Long, Item> itemsMap = new HashMap<Long, Item>();
|
|
|
34 |
Map<Long, Item> itemsCatalogIdMap = new HashMap<Long, Item>();
|
|
|
35 |
Map<String, Item> itemsNameMap = new HashMap<String, Item>();
|
|
|
36 |
Map<Long, Map<String, Long>> itemsResultMap = new HashMap<Long, Map<String, Long>>();
|
|
|
37 |
for (Item item : items) {
|
|
|
38 |
itemsMap.put(item.getId(), item);
|
|
|
39 |
itemsCatalogIdMap.put(item.getCatalogId(), item);
|
|
|
40 |
itemsNameMap.put(item.getName().trim(), item);
|
|
|
41 |
}
|
| 3013 |
vikas |
42 |
if (dateStr != null && !dateStr.isEmpty()) {
|
|
|
43 |
cal.setTime(iSdf.parse(dateStr));
|
|
|
44 |
}
|
|
|
45 |
else {
|
|
|
46 |
dateStr = iSdf.format(cal.getTime());
|
|
|
47 |
}
|
|
|
48 |
cal.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
49 |
Date toDate = iSdf.parse(iSdf.format(cal.getTime()));
|
|
|
50 |
cal.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
51 |
Date fromDate = iSdf.parse(iSdf.format(cal.getTime()));
|
|
|
52 |
|
|
|
53 |
String fromDateStr = request.getParameter("fromDate");
|
|
|
54 |
if (fromDateStr == null || fromDateStr.isEmpty()) {
|
|
|
55 |
fromDateStr = iSdf.format(fromDate);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
59 |
sdf.setTimeZone(TimeZone.getTimeZone("IST"));
|
|
|
60 |
DatastoreService datastore = DatastoreServiceFactory
|
|
|
61 |
.getDatastoreService();
|
|
|
62 |
Query query = new Query("DataLog");
|
|
|
63 |
query.addFilter("eventType", Query.FilterOperator.EQUAL, "PRODUCT_VIEW");
|
|
|
64 |
query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
|
|
65 |
query.addFilter("date", Query.FilterOperator.LESS_THAN, toDate);
|
|
|
66 |
PreparedQuery pq = datastore.prepare(query);
|
|
|
67 |
for (Entity result : pq.asIterable()) {
|
| 3100 |
vikas |
68 |
Long catalogItemId = (Long)result.getProperty("itemId");
|
|
|
69 |
if(catalogItemId == null) {
|
|
|
70 |
String name = (String)result.getProperty("productName");
|
|
|
71 |
if (itemsNameMap.containsKey(name.trim())) {
|
|
|
72 |
catalogItemId = itemsNameMap.get(name.trim()).getCatalogId();
|
|
|
73 |
}
|
| 3013 |
vikas |
74 |
}
|
| 3100 |
vikas |
75 |
if (itemsResultMap.containsKey(catalogItemId)) {
|
|
|
76 |
Map<String, Long> itemMap = itemsResultMap.get(catalogItemId);
|
|
|
77 |
if (itemMap.containsKey("ViewCount")) {
|
|
|
78 |
Long count = itemMap.get("ViewCount");
|
|
|
79 |
itemMap.put("ViewCount", ++count);
|
|
|
80 |
}
|
|
|
81 |
else {
|
|
|
82 |
itemMap.put("ViewCount", 1l);
|
|
|
83 |
}
|
|
|
84 |
}
|
| 3013 |
vikas |
85 |
else {
|
| 3100 |
vikas |
86 |
Map<String, Long> itemMap = new HashMap<String, Long>();
|
|
|
87 |
itemMap.put("ViewCount", 1l);
|
|
|
88 |
itemsResultMap.put(catalogItemId, itemMap);
|
| 3013 |
vikas |
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
query = new Query("DataLog");
|
|
|
93 |
query.addFilter("eventType", Query.FilterOperator.EQUAL, "ADD_TO_CART");
|
|
|
94 |
query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
|
|
95 |
query.addFilter("date", Query.FilterOperator.LESS_THAN, toDate);
|
|
|
96 |
pq = datastore.prepare(query);
|
|
|
97 |
for (Entity result : pq.asIterable()) {
|
|
|
98 |
for (Long itemId : (List<Long>)result.getProperty("itemIds")) {
|
| 3100 |
vikas |
99 |
Long catalogItemId = itemsMap.get(itemId).getCatalogId();
|
|
|
100 |
if (itemsResultMap.containsKey(catalogItemId)) {
|
|
|
101 |
Map<String, Long> itemMap = itemsResultMap.get(catalogItemId);
|
|
|
102 |
if (itemMap.containsKey("AddToCartCount")) {
|
|
|
103 |
Long count = itemMap.get("AddToCartCount");
|
|
|
104 |
itemMap.put("AddToCartCount", ++count);
|
|
|
105 |
}
|
|
|
106 |
else {
|
|
|
107 |
itemMap.put("AddToCartCount", 1l);
|
|
|
108 |
}
|
| 3013 |
vikas |
109 |
}
|
|
|
110 |
else {
|
| 3100 |
vikas |
111 |
Map<String, Long> itemMap = new HashMap<String, Long>();
|
|
|
112 |
itemMap.put("AddToCartCount", 1l);
|
|
|
113 |
itemsResultMap.put(catalogItemId, itemMap);
|
| 3013 |
vikas |
114 |
}
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
query = new Query("DataLog");
|
|
|
119 |
query.addFilter("eventType", Query.FilterOperator.EQUAL, "DELETE_FROM_CART");
|
|
|
120 |
query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
|
|
121 |
query.addFilter("date", Query.FilterOperator.LESS_THAN, toDate);
|
|
|
122 |
pq = datastore.prepare(query);
|
|
|
123 |
for (Entity result : pq.asIterable()) {
|
|
|
124 |
for (Long itemId : (List<Long>)result.getProperty("itemIds")) {
|
| 3100 |
vikas |
125 |
Long catalogItemId = itemsMap.get(itemId).getCatalogId();
|
|
|
126 |
if (itemsResultMap.containsKey(catalogItemId)) {
|
|
|
127 |
Map<String, Long> itemMap = itemsResultMap.get(catalogItemId);
|
|
|
128 |
if (itemMap.containsKey("DeleteFromCartCount")) {
|
|
|
129 |
Long count = itemMap.get("DeleteFromCartCount");
|
|
|
130 |
itemMap.put("DeleteFromCartCount", ++count);
|
|
|
131 |
}
|
|
|
132 |
else {
|
|
|
133 |
itemMap.put("DeleteFromCartCount", 1l);
|
|
|
134 |
}
|
| 3013 |
vikas |
135 |
}
|
|
|
136 |
else {
|
| 3100 |
vikas |
137 |
Map<String, Long> itemMap = new HashMap<String, Long>();
|
|
|
138 |
itemMap.put("DeleteFromCartCount", 1l);
|
|
|
139 |
itemsResultMap.put(catalogItemId, itemMap);
|
| 3013 |
vikas |
140 |
}
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
query = new Query("DataLog");
|
|
|
145 |
query.addFilter("eventType", Query.FilterOperator.EQUAL, "RESEARCH_ADD");
|
|
|
146 |
query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
|
|
147 |
query.addFilter("date", Query.FilterOperator.LESS_THAN, toDate);
|
|
|
148 |
pq = datastore.prepare(query);
|
|
|
149 |
for (Entity result : pq.asIterable()) {
|
| 3100 |
vikas |
150 |
for (Long catalogItemId : (List<Long>)result.getProperty("itemIds")) {
|
|
|
151 |
if (itemsResultMap.containsKey(catalogItemId)) {
|
|
|
152 |
Map<String, Long> itemMap = itemsResultMap.get(catalogItemId);
|
|
|
153 |
if (itemMap.containsKey("AddToResearchCount")) {
|
|
|
154 |
Long count = itemMap.get("AddToResearchCount");
|
|
|
155 |
itemMap.put("AddToResearchCount", ++count);
|
|
|
156 |
}
|
|
|
157 |
else {
|
|
|
158 |
itemMap.put("AddToResearchCount", 1l);
|
|
|
159 |
}
|
| 3013 |
vikas |
160 |
}
|
|
|
161 |
else {
|
| 3100 |
vikas |
162 |
Map<String, Long> itemMap = new HashMap<String, Long>();
|
|
|
163 |
itemMap.put("AddToResearchCount", 1l);
|
|
|
164 |
itemsResultMap.put(catalogItemId, itemMap);
|
| 3013 |
vikas |
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
query = new Query("DataLog");
|
|
|
170 |
query.addFilter("eventType", Query.FilterOperator.EQUAL, "RESEARCH_DELETE");
|
|
|
171 |
query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
|
|
172 |
query.addFilter("date", Query.FilterOperator.LESS_THAN, toDate);
|
|
|
173 |
pq = datastore.prepare(query);
|
|
|
174 |
for (Entity result : pq.asIterable()) {
|
| 3100 |
vikas |
175 |
for (Long catalogItemId : (List<Long>)result.getProperty("itemIds")) {
|
|
|
176 |
if (itemsResultMap.containsKey(catalogItemId)) {
|
|
|
177 |
Map<String, Long> itemMap = itemsResultMap.get(catalogItemId);
|
|
|
178 |
if (itemMap.containsKey("ResearchDeleteCount")) {
|
|
|
179 |
Long count = itemMap.get("ResearchDeleteCount");
|
|
|
180 |
itemMap.put("ResearchDeleteCount", ++count);
|
|
|
181 |
}
|
|
|
182 |
else {
|
|
|
183 |
itemMap.put("ResearchDeleteCount", 1l);
|
|
|
184 |
}
|
| 3013 |
vikas |
185 |
}
|
|
|
186 |
else {
|
| 3100 |
vikas |
187 |
Map<String, Long> itemMap = new HashMap<String, Long>();
|
|
|
188 |
itemMap.put("ResearchDeleteCount", 1l);
|
|
|
189 |
itemsResultMap.put(catalogItemId, itemMap);
|
| 3013 |
vikas |
190 |
}
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
%>
|
|
|
194 |
<form id="frmProductActivity" name="frmProductActivity" method="post" action="/jsp/product-activity.jsp">
|
|
|
195 |
<label>Date(YYYYMMDD) : </label> <input type="text" name="date" id="date" value="<%= dateStr %>"/>
|
|
|
196 |
<input type="submit" name="submit" id="submit" value="Submit"/><br/>
|
|
|
197 |
</form>
|
|
|
198 |
<table cellpadding="0" cellspacing="0" border="0" class="display"
|
| 3100 |
vikas |
199 |
id="prodFunnel">
|
| 3013 |
vikas |
200 |
<thead>
|
|
|
201 |
<tr>
|
|
|
202 |
<th>Product</th>
|
| 3100 |
vikas |
203 |
<th>View</th>
|
|
|
204 |
<th>AddToCart</th>
|
|
|
205 |
<th>DeleteFromCart</th>
|
|
|
206 |
<th>AddToResearch</th>
|
|
|
207 |
<th>DeleteFromResearch</th>
|
| 3013 |
vikas |
208 |
</tr>
|
|
|
209 |
</thead>
|
|
|
210 |
<tbody>
|
|
|
211 |
|
|
|
212 |
<%
|
| 3116 |
vikas |
213 |
for (Entry<Long, Map<String, Long>> entry : itemsResultMap.entrySet()) {
|
| 3100 |
vikas |
214 |
Long catalogItemId = (Long)entry.getKey();
|
|
|
215 |
Map<String, Long> itemMap = (Map<String, Long>)entry.getValue();
|
| 3013 |
vikas |
216 |
%>
|
|
|
217 |
<tr>
|
| 3100 |
vikas |
218 |
<td><%=itemsCatalogIdMap.get(catalogItemId)==null? catalogItemId : itemsCatalogIdMap.get(catalogItemId).getName()%></td>
|
|
|
219 |
<td><%=itemMap.get("ViewCount")==null? 0 : itemMap.get("ViewCount")%></td>
|
|
|
220 |
<td><%=itemMap.get("AddToCartCount")==null? 0 : itemMap.get("AddToCartCount")%></td>
|
|
|
221 |
<td><%=itemMap.get("DeleteFromCartCount")==null? 0 : itemMap.get("DeleteFromCartCount")%></td>
|
|
|
222 |
<td><%=itemMap.get("AddToResearchCount")==null? 0 : itemMap.get("AddToResearchCount")%></td>
|
|
|
223 |
<td><%=itemMap.get("DeleteFromCartCount")==null? 0 : itemMap.get("DeleteFromCartCount")%></td>
|
| 3013 |
vikas |
224 |
</tr>
|
|
|
225 |
<%
|
|
|
226 |
}
|
|
|
227 |
%>
|
|
|
228 |
</tbody>
|
|
|
229 |
</table>
|
|
|
230 |
|
|
|
231 |
<script type="text/javascript" language="javascript" src="/DataTables/media/js/jquery.js"></script>
|
|
|
232 |
<script type="text/javascript" language="javascript" src="/DataTables/media/js/jquery.dataTables.min.js"></script>
|
|
|
233 |
<script type="text/javascript" charset="utf-8" src="/DataTables/extras/TableTools/media/js/ZeroClipboard.js"></script>
|
|
|
234 |
<script type="text/javascript" charset="utf-8" src="/DataTables/extras/TableTools/media/js/TableTools.js"></script>
|
|
|
235 |
<script type="text/javascript" charset="utf-8">
|
|
|
236 |
$(document).ready(function() {
|
| 3100 |
vikas |
237 |
$('#prodFunnel').dataTable({
|
|
|
238 |
"iDisplayLength": 15,
|
| 3013 |
vikas |
239 |
"bProcessing": true,
|
|
|
240 |
"aaSorting": [[1,'desc']],
|
| 3100 |
vikas |
241 |
"sDom": 'T<"clear">lfrtip',
|
|
|
242 |
"oTableTools": {
|
|
|
243 |
"sSwfPath": "/DataTables/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf"
|
|
|
244 |
},
|
|
|
245 |
"aLengthMenu": [[10, 15, 25, 50, 100, -1], [10, 15, 25, 50, 100, "All"]]
|
| 3013 |
vikas |
246 |
});
|
|
|
247 |
} );
|
|
|
248 |
</script>
|
|
|
249 |
</body>
|
|
|
250 |
</html>
|