Subversion Repositories SmartDukaan

Rev

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

Rev 3116 Rev 3141
Line -... Line 1...
-
 
1
<%@page import="in.shop2020.server.ItemActivityRepository"%>
-
 
2
<%@page import="in.shop2020.model.ItemActivity"%>
1
<%@page import="com.google.appengine.api.datastore.FetchOptions"%>
3
<%@page import="com.google.appengine.api.datastore.FetchOptions"%>
2
<%@page import="java.util.ArrayList"%>
4
<%@page import="java.util.ArrayList"%>
3
<%@page import="in.shop2020.model.Item"%>
5
<%@page import="in.shop2020.model.Item"%>
4
<%@page import="in.shop2020.server.ItemRepository"%>
6
<%@page import="in.shop2020.server.ItemRepository"%>
5
<%@page import="java.util.Map"%>
7
<%@page import="java.util.Map"%>
Line 24... Line 26...
24
      <link rel="stylesheet" href="/DataTables/extras/TableTools/media/css/TableTools.css" type="text/css" /> 
26
      <link rel="stylesheet" href="/DataTables/extras/TableTools/media/css/TableTools.css" type="text/css" /> 
25
  </head>
27
  </head>
26
  <body>
28
  <body>
27
<%
29
<%
28
    SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");
30
    SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");
-
 
31
    iSdf.setTimeZone(TimeZone.getTimeZone("IST"));
29
	Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
32
	Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
30
	String dateStr = request.getParameter("date");
33
	String dateStr = request.getParameter("date");
-
 
34
	Date date;
-
 
35
	if (dateStr != null && !dateStr.isEmpty()) {
-
 
36
	    date = iSdf.parse(dateStr);
-
 
37
	}
-
 
38
	else {
-
 
39
	    date = iSdf.parse(iSdf.format(cal.getTime()));
-
 
40
	    dateStr = iSdf.format(date);
-
 
41
	}
-
 
42
	
31
	ItemRepository itemRepository = new ItemRepository();
43
	ItemRepository itemRepository = new ItemRepository();
32
	List<Item> items = itemRepository.getAll();
44
	List<Item> items = itemRepository.getAll();
33
	Map<Long, Item> itemsMap = new HashMap<Long, Item>();
-
 
34
	Map<Long, Item> itemsCatalogIdMap = new HashMap<Long, Item>();
45
	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) {
46
	for (Item item : items) {
38
	    itemsMap.put(item.getId(), item);
-
 
39
	    itemsCatalogIdMap.put(item.getCatalogId(), item);
47
	    itemsCatalogIdMap.put(item.getCatalogId(), item);
40
	    itemsNameMap.put(item.getName().trim(), item);
-
 
41
	}
-
 
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
	}
48
	}
57
	
49
	
58
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
 
59
    sdf.setTimeZone(TimeZone.getTimeZone("IST"));
-
 
60
    DatastoreService datastore = DatastoreServiceFactory
50
	ItemActivityRepository itemActivityRepository = new ItemActivityRepository();
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()) {
-
 
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
            }
-
 
74
        }
-
 
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
        }
-
 
85
        else {
-
 
86
            Map<String, Long> itemMap = new HashMap<String, Long>();
-
 
87
            itemMap.put("ViewCount", 1l);
-
 
88
            itemsResultMap.put(catalogItemId, itemMap);
-
 
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")) {
-
 
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
                }
-
 
109
            }
-
 
110
            else {
-
 
111
                Map<String, Long> itemMap = new HashMap<String, Long>();
-
 
112
                itemMap.put("AddToCartCount", 1l);
-
 
113
                itemsResultMap.put(catalogItemId, itemMap);
-
 
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")) {
-
 
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
                }
-
 
135
            }
-
 
136
            else {
-
 
137
                Map<String, Long> itemMap = new HashMap<String, Long>();
-
 
138
                itemMap.put("DeleteFromCartCount", 1l);
-
 
139
                itemsResultMap.put(catalogItemId, itemMap);
-
 
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()) {
-
 
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
                }
-
 
160
            }
-
 
161
            else {
-
 
162
                Map<String, Long> itemMap = new HashMap<String, Long>();
-
 
163
                itemMap.put("AddToResearchCount", 1l);
-
 
164
                itemsResultMap.put(catalogItemId, itemMap);
-
 
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()) {
-
 
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");
51
	List<ItemActivity> itemActivities = itemActivityRepository.getByDate(date);
180
                    itemMap.put("ResearchDeleteCount", ++count);
-
 
181
                }
-
 
182
                else {
-
 
183
                    itemMap.put("ResearchDeleteCount", 1l);
-
 
184
                }
-
 
185
            }
-
 
186
            else {
-
 
187
                Map<String, Long> itemMap = new HashMap<String, Long>();
-
 
188
                itemMap.put("ResearchDeleteCount", 1l);
-
 
189
                itemsResultMap.put(catalogItemId, itemMap);
-
 
190
            }
-
 
191
        }
-
 
192
    }
-
 
193
%>
52
%>
194
    <form id="frmProductActivity" name="frmProductActivity" method="post" action="/jsp/product-activity.jsp">
53
    <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 %>"/>
54
      <label>Date(YYYYMMDD) : </label> <input type="text" name="date" id="date" value="<%= dateStr %>"/>
196
      <input type="submit" name="submit" id="submit" value="Submit"/><br/>
55
      <input type="submit" name="submit" id="submit" value="Submit"/><br/>
197
    </form>
56
    </form>
Line 199... Line 58...
199
		id="prodFunnel">
58
		id="prodFunnel">
200
		<thead>
59
		<thead>
201
			<tr>
60
			<tr>
202
				<th>Product</th>
61
				<th>Product</th>
203
				<th>View</th>
62
				<th>View</th>
-
 
63
				<th>Unique</th>
204
				<th>AddToCart</th>
64
				<th>AddCart</th>
-
 
65
				<th>Unique</th>
-
 
66
                <th>DelCart</th>
205
				<th>DeleteFromCart</th>
67
				<th>Unique</th>
-
 
68
                <th>AddResearch</th>
206
				<th>AddToResearch</th>
69
				<th>Unique</th>
207
				<th>DeleteFromResearch</th>
70
                <th>DelResearch</th>
-
 
71
				<th>Unique</th>
208
			</tr>
72
			</tr>
209
		</thead>
73
		</thead>
210
		<tbody>
74
		<tbody>
211
 
75
 
212
<%
76
<%
213
    for (Entry<Long, Map<String, Long>> entry : itemsResultMap.entrySet()) {
77
    for (ItemActivity itemActivity : itemActivities) {
214
        Long catalogItemId = (Long)entry.getKey();
-
 
215
        Map<String, Long> itemMap = (Map<String, Long>)entry.getValue();
-
 
216
%>
78
%>
217
			<tr>
79
			<tr>
218
				<td><%=itemsCatalogIdMap.get(catalogItemId)==null? catalogItemId : itemsCatalogIdMap.get(catalogItemId).getName()%></td>
80
				<td><%=itemsCatalogIdMap.get(itemActivity.getCatalogId())==null? itemActivity.getCatalogId() : itemsCatalogIdMap.get(itemActivity.getCatalogId()).getName()%></td>
219
				<td><%=itemMap.get("ViewCount")==null? 0 : itemMap.get("ViewCount")%></td>
81
				<td><%=itemActivity.getView()==null? 0 : itemActivity.getView()%></td>
-
 
82
				<td><%=itemActivity.getUniqueView()==null? 0 : itemActivity.getUniqueView()%></td>
220
				<td><%=itemMap.get("AddToCartCount")==null? 0 : itemMap.get("AddToCartCount")%></td>
83
				<td><%=itemActivity.getAddToCart()==null? 0 : itemActivity.getAddToCart()%></td>
-
 
84
                <td><%=itemActivity.getUniqueAddToCart()==null? 0 : itemActivity.getUniqueAddToCart()%></td>
221
                <td><%=itemMap.get("DeleteFromCartCount")==null? 0 : itemMap.get("DeleteFromCartCount")%></td>
85
                <td><%=itemActivity.getDeleteFromCart()==null? 0 : itemActivity.getDeleteFromCart()%></td>
-
 
86
                <td><%=itemActivity.getUniqueDeleteFromCart()==null? 0 : itemActivity.getUniqueDeleteFromCart()%></td>
222
                <td><%=itemMap.get("AddToResearchCount")==null? 0 : itemMap.get("AddToResearchCount")%></td>
87
                <td><%=itemActivity.getAddToResearch()==null? 0 : itemActivity.getAddToResearch()%></td>
-
 
88
                <td><%=itemActivity.getUniqueAddToResearch()==null? 0 : itemActivity.getUniqueAddToResearch()%></td>
223
                <td><%=itemMap.get("DeleteFromCartCount")==null? 0 : itemMap.get("DeleteFromCartCount")%></td>
89
                <td><%=itemActivity.getDeleteFromResearch()==null? 0 : itemActivity.getDeleteFromResearch()%></td>
-
 
90
                <td><%=itemActivity.getUniqueDeleteFromResearch()==null? 0 : itemActivity.getUniqueDeleteFromResearch()%></td>
224
			</tr>
91
			</tr>
225
<%
92
<%
226
    }
93
    }
227
%>
94
%>
228
		</tbody>
95
		</tbody>