| Line 15... |
Line 15... |
| 15 |
import java.util.List;
|
15 |
import java.util.List;
|
| 16 |
import java.util.Map;
|
16 |
import java.util.Map;
|
| 17 |
import java.util.Map.Entry;
|
17 |
import java.util.Map.Entry;
|
| 18 |
import java.util.Set;
|
18 |
import java.util.Set;
|
| 19 |
import java.util.TimeZone;
|
19 |
import java.util.TimeZone;
|
| - |
|
20 |
import java.util.logging.Logger;
|
| 20 |
|
21 |
|
| 21 |
import javax.servlet.http.HttpServlet;
|
22 |
import javax.servlet.http.HttpServlet;
|
| 22 |
import javax.servlet.http.HttpServletRequest;
|
23 |
import javax.servlet.http.HttpServletRequest;
|
| 23 |
import javax.servlet.http.HttpServletResponse;
|
24 |
import javax.servlet.http.HttpServletResponse;
|
| 24 |
|
25 |
|
| 25 |
import com.google.appengine.api.datastore.DatastoreService;
|
26 |
import com.google.appengine.api.datastore.DatastoreService;
|
| 26 |
import com.google.appengine.api.datastore.DatastoreServiceFactory;
|
27 |
import com.google.appengine.api.datastore.DatastoreServiceFactory;
|
| 27 |
import com.google.appengine.api.datastore.Entity;
|
28 |
import com.google.appengine.api.datastore.Entity;
|
| - |
|
29 |
import com.google.appengine.api.datastore.FetchOptions;
|
| 28 |
import com.google.appengine.api.datastore.PreparedQuery;
|
30 |
import com.google.appengine.api.datastore.PreparedQuery;
|
| 29 |
import com.google.appengine.api.datastore.Query;
|
31 |
import com.google.appengine.api.datastore.Query;
|
| 30 |
|
32 |
|
| 31 |
public class DailyProductWithSourceAggregatorServlet extends HttpServlet {
|
33 |
public class DailyProductWithSourceAggregatorServlet extends HttpServlet {
|
| 32 |
private static final long serialVersionUID = -8236918415987438049L;
|
34 |
private static final long serialVersionUID = -8236918415987438049L;
|
| - |
|
35 |
private static Logger logger = Logger.getLogger(DailyProductWithSourceAggregatorServlet.class.getName());
|
| - |
|
36 |
|
| 33 |
private static final String KIND = "DataLog";
|
37 |
private static final String KIND = "DataLog";
|
| 34 |
private static final String SESSION_ID_FILED = "sessionId";
|
38 |
private static final String SESSION_ID_FIELD = "sessionId";
|
| 35 |
private static final String ITEMID_FILED = "itemId";
|
39 |
private static final String ITEMID_FIELD = "itemId";
|
| 36 |
private static final String ITEMIDS_FILED = "itemIds";
|
40 |
private static final String ITEMIDS_FIELD = "itemIds";
|
| 37 |
private static final String PRODUCTNAME_FILED = "productName";
|
41 |
private static final String PRODUCTNAME_FIELD = "productName";
|
| 38 |
private static final String EVENTTYPE_FILED = "eventType";
|
42 |
private static final String EVENTTYPE_FIELD = "eventType";
|
| 39 |
private static final String DATE_FILED = "date";
|
43 |
private static final String DATE_FIELD = "date";
|
| 40 |
private static final String FIRST_SOURCE_FILED = "firstSource";
|
44 |
private static final String FIRST_SOURCE_FIELD = "firstSource";
|
| 41 |
private static final String SESSION_SOURCE_FILED = "source";
|
45 |
private static final String SESSION_SOURCE_FIELD = "source";
|
| 42 |
|
46 |
|
| 43 |
|
47 |
|
| 44 |
private static final String PRODUCT_VIEW_EVENT = "PRODUCT_VIEW";
|
48 |
private static final String PRODUCT_VIEW_EVENT = "PRODUCT_VIEW";
|
| 45 |
private static final String ADD_TO_CART_EVENT = "ADD_TO_CART";
|
49 |
private static final String ADD_TO_CART_EVENT = "ADD_TO_CART";
|
| 46 |
private static final String DELETE_FROM_CART_EVENT = "DELETE_FROM_CART";
|
50 |
private static final String DELETE_FROM_CART_EVENT = "DELETE_FROM_CART";
|
| Line 75... |
Line 79... |
| 75 |
private static final String UNIQUE_PROCEED_TO_PAY_COUNT_KEY = "UniqueProceedToPayCount";
|
79 |
private static final String UNIQUE_PROCEED_TO_PAY_COUNT_KEY = "UniqueProceedToPayCount";
|
| 76 |
|
80 |
|
| 77 |
private static final String FIRST_SOURCE_KEY = "FirstSource";
|
81 |
private static final String FIRST_SOURCE_KEY = "FirstSource";
|
| 78 |
private static final String SESSION_SOURCE_KEY = "SessionSource";
|
82 |
private static final String SESSION_SOURCE_KEY = "SessionSource";
|
| 79 |
|
83 |
|
| 80 |
private Map<Long, Item> itemsMap = new HashMap<Long, Item>();
|
84 |
private Map<Long, Item> itemsMap;
|
| 81 |
private Map<Long, Item> itemsCatalogIdMap = new HashMap<Long, Item>();
|
85 |
private Map<Long, Item> itemsCatalogIdMap;
|
| 82 |
private Map<String, Item> itemsNameMap = new HashMap<String, Item>();
|
86 |
private Map<String, Item> itemsNameMap;
|
| 83 |
private Map<String, Map<String, Long>> itemsResultMap = new HashMap<String, Map<String, Long>>();
|
87 |
private Map<String, Map<String, Long>> itemsResultMap;
|
| 84 |
|
88 |
|
| 85 |
private Map<String, Map<String, String>> sessionIdSourceMap = new HashMap<String, Map<String,String>>();
|
89 |
private Map<String, Map<String, String>> sessionIdSourceMap;
|
| 86 |
|
90 |
|
| 87 |
private Date fromDate;
|
91 |
private Date fromDate;
|
| 88 |
private Date toDate;
|
92 |
private Date toDate;
|
| 89 |
private DatastoreService datastore;
|
93 |
private DatastoreService datastore;
|
| 90 |
|
94 |
|
| 91 |
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
95 |
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
| - |
|
96 |
logger.warning("Running DailyProductWithSourceAggregator");
|
| - |
|
97 |
sessionIdSourceMap = new HashMap<String, Map<String,String>>();
|
| - |
|
98 |
itemsMap = new HashMap<Long, Item>();
|
| - |
|
99 |
itemsCatalogIdMap = new HashMap<Long, Item>();
|
| - |
|
100 |
itemsNameMap = new HashMap<String, Item>();
|
| - |
|
101 |
itemsResultMap = new HashMap<String, Map<String, Long>>();
|
| - |
|
102 |
|
| 92 |
datastore = DatastoreServiceFactory.getDatastoreService();
|
103 |
datastore = DatastoreServiceFactory.getDatastoreService();
|
| 93 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
104 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
| 94 |
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
|
105 |
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
|
| 95 |
String dateStr = req.getParameter("date");
|
106 |
String dateStr = req.getParameter("date");
|
| 96 |
if (dateStr != null && !dateStr.isEmpty()) {
|
107 |
if (dateStr != null && !dateStr.isEmpty()) {
|
| Line 115... |
Line 126... |
| 115 |
itemsMap.put(item.getId(), item);
|
126 |
itemsMap.put(item.getId(), item);
|
| 116 |
itemsCatalogIdMap.put(item.getCatalogId(), item);
|
127 |
itemsCatalogIdMap.put(item.getCatalogId(), item);
|
| 117 |
itemsNameMap.put(item.getName().trim(), item);
|
128 |
itemsNameMap.put(item.getName().trim(), item);
|
| 118 |
}
|
129 |
}
|
| 119 |
|
130 |
|
| - |
|
131 |
logger.warning("DailyProductWithSourceAggregator : Updating View Count Map");
|
| 120 |
UpdateViewCount(PRODUCT_VIEW_EVENT, VIEW_COUNT_KEY, UNIQUE_VIEW_COUNT_KEY);
|
132 |
UpdateViewCount(PRODUCT_VIEW_EVENT, VIEW_COUNT_KEY, UNIQUE_VIEW_COUNT_KEY);
|
| - |
|
133 |
logger.warning("DailyProductWithSourceAggregator : itemsResultMap size : " + itemsResultMap.size());
|
| - |
|
134 |
logger.warning("DailyProductWithSourceAggregator : sessionIdSourceMap size : " + sessionIdSourceMap.size());
|
| 121 |
|
135 |
|
| - |
|
136 |
logger.warning("DailyProductWithSourceAggregator : Updating Add To Cart Count Map");
|
| 122 |
UpdateItemIdEventCount(ADD_TO_CART_EVENT, ADD_TO_CART_COUNT_KEY, UNIQUE_ADD_TO_CART_COUNT_KEY, false);
|
137 |
UpdateItemIdEventCount(ADD_TO_CART_EVENT, ADD_TO_CART_COUNT_KEY, UNIQUE_ADD_TO_CART_COUNT_KEY, false);
|
| - |
|
138 |
logger.warning("DailyProductWithSourceAggregator : Updating Delete From Cart Count Map");
|
| 123 |
UpdateItemIdEventCount(DELETE_FROM_CART_EVENT, DELETE_FROM_CART_COUNT_KEY, UNIQUE_DELETE_FROM_CART_COUNT_KEY, false);
|
139 |
UpdateItemIdEventCount(DELETE_FROM_CART_EVENT, DELETE_FROM_CART_COUNT_KEY, UNIQUE_DELETE_FROM_CART_COUNT_KEY, false);
|
| - |
|
140 |
logger.warning("DailyProductWithSourceAggregator : Updating Add To Research Count Map");
|
| 124 |
UpdateItemIdEventCount(RESEARCH_ADD_EVENT, ADD_TO_RESEARCH_COUNT_KEY, UNIQUE_ADD_TO_RESEARCH_COUNT_KEY, true);
|
141 |
UpdateItemIdEventCount(RESEARCH_ADD_EVENT, ADD_TO_RESEARCH_COUNT_KEY, UNIQUE_ADD_TO_RESEARCH_COUNT_KEY, true);
|
| - |
|
142 |
logger.warning("DailyProductWithSourceAggregator : Updating Delete From Research Count Map");
|
| 125 |
UpdateItemIdEventCount(RESEARCH_DELETE_EVENT, DELETE_FROM_RESEARCH_COUNT_KEY, UNIQUE_DELETE_FROM_RESEARCH_COUNT_KEY, true);
|
143 |
UpdateItemIdEventCount(RESEARCH_DELETE_EVENT, DELETE_FROM_RESEARCH_COUNT_KEY, UNIQUE_DELETE_FROM_RESEARCH_COUNT_KEY, true);
|
| 126 |
|
144 |
|
| - |
|
145 |
logger.warning("DailyProductWithSourceAggregator : Updating ShippingAccessCount Count Map");
|
| 127 |
UpdateItemIdEventCount(SHIPPING_ACCESS_EVENT, SHIPPING_ACCESS_COUNT_KEY, UNIQUE_SHIPPING_ACCESS_COUNT_KEY, false);
|
146 |
UpdateItemIdEventCount(SHIPPING_ACCESS_EVENT, SHIPPING_ACCESS_COUNT_KEY, UNIQUE_SHIPPING_ACCESS_COUNT_KEY, false);
|
| - |
|
147 |
logger.warning("DailyProductWithSourceAggregator : Updating Payment Success Count Map");
|
| 128 |
UpdateItemIdEventCount(PAYMENT_SUCCESS_EVENT, PAYMENT_SUCCESS_COUNT_KEY, UNIQUE_PAYMENT_SUCCESS_COUNT_KEY, false);
|
148 |
UpdateItemIdEventCount(PAYMENT_SUCCESS_EVENT, PAYMENT_SUCCESS_COUNT_KEY, UNIQUE_PAYMENT_SUCCESS_COUNT_KEY, false);
|
| - |
|
149 |
logger.warning("DailyProductWithSourceAggregator : Updating Order Creation Count Map");
|
| 129 |
UpdateItemIdEventCount(ORDER_CREATION_EVENT, ORDER_CREATION_COUNT_KEY, UNIQUE_ORDER_CREATION_COUNT_KEY, false);
|
150 |
UpdateItemIdEventCount(ORDER_CREATION_EVENT, ORDER_CREATION_COUNT_KEY, UNIQUE_ORDER_CREATION_COUNT_KEY, false);
|
| - |
|
151 |
logger.warning("DailyProductWithSourceAggregator : Updating Payment Failure Count Map");
|
| 130 |
UpdateItemIdEventCount(PAYMENT_FAILURE_EVENT, PAYMENT_FAILURE_COUNT_KEY, UNIQUE_PAYMENT_FAILURE_COUNT_KEY, false);
|
152 |
UpdateItemIdEventCount(PAYMENT_FAILURE_EVENT, PAYMENT_FAILURE_COUNT_KEY, UNIQUE_PAYMENT_FAILURE_COUNT_KEY, false);
|
| - |
|
153 |
logger.warning("DailyProductWithSourceAggregator : Updating Proceed To Pay Count Map");
|
| 131 |
UpdateItemIdEventCount(PROCEED_TO_PAY_EVENT, PROCEED_TO_PAY_COUNT_KEY, UNIQUE_PROCEED_TO_PAY_COUNT_KEY, false);
|
154 |
UpdateItemIdEventCount(PROCEED_TO_PAY_EVENT, PROCEED_TO_PAY_COUNT_KEY, UNIQUE_PROCEED_TO_PAY_COUNT_KEY, false);
|
| 132 |
|
155 |
|
| 133 |
List<ItemActivityWithSource> itemActivities = new ArrayList<ItemActivityWithSource>();
|
156 |
List<ItemActivityWithSource> itemActivities = new ArrayList<ItemActivityWithSource>();
|
| 134 |
ItemActivityWithSourceRepository itemActivityRepository = new ItemActivityWithSourceRepository();
|
157 |
ItemActivityWithSourceRepository itemActivityRepository = new ItemActivityWithSourceRepository();
|
| 135 |
for (Entry<String, Map<String, Long>> entry : itemsResultMap.entrySet()) {
|
158 |
for (Entry<String, Map<String, Long>> entry : itemsResultMap.entrySet()) {
|
| Line 173... |
Line 196... |
| 173 |
itemActivity.setUniqueOrderCreation(itemMap.get(UNIQUE_ORDER_CREATION_COUNT_KEY));
|
196 |
itemActivity.setUniqueOrderCreation(itemMap.get(UNIQUE_ORDER_CREATION_COUNT_KEY));
|
| 174 |
itemActivity.setUniquePaymentFailure(itemMap.get(UNIQUE_PAYMENT_FAILURE_COUNT_KEY));
|
197 |
itemActivity.setUniquePaymentFailure(itemMap.get(UNIQUE_PAYMENT_FAILURE_COUNT_KEY));
|
| 175 |
itemActivity.setUniqueProceedToPay(itemMap.get(UNIQUE_PROCEED_TO_PAY_COUNT_KEY));
|
198 |
itemActivity.setUniqueProceedToPay(itemMap.get(UNIQUE_PROCEED_TO_PAY_COUNT_KEY));
|
| 176 |
|
199 |
|
| 177 |
itemActivities.add(itemActivity);
|
200 |
itemActivities.add(itemActivity);
|
| - |
|
201 |
|
| - |
|
202 |
if (itemActivities.size()>500) {
|
| - |
|
203 |
logger.warning("DailyProductWithSourceAggregator : persisting itemactivities : " + itemActivities.size());
|
| - |
|
204 |
itemActivityRepository.createAll(itemActivities);
|
| - |
|
205 |
itemActivities.clear();
|
| - |
|
206 |
}
|
| 178 |
}
|
207 |
}
|
| - |
|
208 |
logger.warning("DailyProductWithSourceAggregator : persisting itemactivities : " + itemActivities.size());
|
| - |
|
209 |
logger.warning("DailyProductWithSourceAggregator : itemactivities : " + itemActivities);
|
| 179 |
itemActivityRepository.createAll(itemActivities);
|
210 |
itemActivityRepository.createAll(itemActivities);
|
| 180 |
}
|
211 |
}
|
| 181 |
|
212 |
|
| 182 |
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
213 |
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
| 183 |
doPost(req, resp);
|
214 |
doPost(req, resp);
|
| 184 |
}
|
215 |
}
|
| 185 |
|
216 |
|
| 186 |
private void UpdateViewCount(String event, String viewCountKey, String uniqueViewCountKey) {
|
217 |
private void UpdateViewCount(String event, String viewCountKey, String uniqueViewCountKey) {
|
| 187 |
Query query = new Query(KIND);
|
218 |
Query query = new Query(KIND);
|
| 188 |
query.addFilter(EVENTTYPE_FILED, Query.FilterOperator.EQUAL, event);
|
219 |
query.addFilter(EVENTTYPE_FIELD, Query.FilterOperator.EQUAL, event);
|
| 189 |
query.addFilter(DATE_FILED, Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
220 |
query.addFilter(DATE_FIELD, Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
| 190 |
query.addFilter(DATE_FILED, Query.FilterOperator.LESS_THAN, toDate);
|
221 |
query.addFilter(DATE_FIELD, Query.FilterOperator.LESS_THAN, toDate);
|
| 191 |
PreparedQuery pq = datastore.prepare(query);
|
222 |
PreparedQuery pq = datastore.prepare(query);
|
| 192 |
Set<String> uniqueSet = new HashSet<String>();
|
223 |
Set<String> uniqueSet = new HashSet<String>();
|
| - |
|
224 |
List<Entity> entityResults = new ArrayList<Entity>();
|
| - |
|
225 |
|
| - |
|
226 |
logger.warning("DailyProductWithSourceAggregator : Getting View Events in list");
|
| - |
|
227 |
for (Entity e : pq.asList(FetchOptions.Builder.withChunkSize(500))) {
|
| - |
|
228 |
entityResults.add(e);
|
| - |
|
229 |
}
|
| - |
|
230 |
logger.warning("DailyProductWithSourceAggregator : Done Getting View Events in list");
|
| 193 |
for (Entity result : pq.asIterable()) {
|
231 |
for (Entity result : entityResults) {
|
| 194 |
String sessionId = (String)result.getProperty(SESSION_ID_FILED);
|
232 |
String sessionId = (String)result.getProperty(SESSION_ID_FIELD);
|
| 195 |
String firstSource = getSource(sessionId, FIRST_SOURCE_KEY);
|
233 |
String firstSource = getSource(sessionId, FIRST_SOURCE_KEY);
|
| 196 |
String sessionSource = getSource(sessionId, SESSION_SOURCE_KEY);
|
234 |
String sessionSource = getSource(sessionId, SESSION_SOURCE_KEY);
|
| 197 |
String paidFirstSource = "0";
|
235 |
String paidFirstSource = "0";
|
| 198 |
String paidSessionSource = "0";
|
236 |
String paidSessionSource = "0";
|
| 199 |
if (firstSource.startsWith("PAID :")) {
|
237 |
if (firstSource.startsWith("PAID :")) {
|
| 200 |
paidFirstSource = "1";
|
238 |
paidFirstSource = "1";
|
| 201 |
}
|
239 |
}
|
| 202 |
if (sessionSource.startsWith("PAID :")) {
|
240 |
if (sessionSource.startsWith("PAID :")) {
|
| 203 |
paidSessionSource = "1";
|
241 |
paidSessionSource = "1";
|
| 204 |
}
|
242 |
}
|
| 205 |
firstSource = firstSource.replaceAll(".*http[s]?://", "").replaceAll("/.*", "");
|
243 |
firstSource = firstSource.replaceAll(".*http[s]?://", "").replaceAll("/.*", "").replaceAll("www.", "");
|
| 206 |
sessionSource = sessionSource.replaceAll(".*http[s]?://", "").replaceAll("/.*", "");
|
244 |
sessionSource = sessionSource.replaceAll(".*http[s]?://", "").replaceAll("/.*", "").replaceAll("www.", "");
|
| 207 |
Long catalogItemId = (Long)result.getProperty(ITEMID_FILED);
|
245 |
Long catalogItemId = (Long)result.getProperty(ITEMID_FIELD);
|
| 208 |
if(catalogItemId == null) {
|
246 |
if(catalogItemId == null) {
|
| 209 |
String name = (String)result.getProperty(PRODUCTNAME_FILED);
|
247 |
String name = (String)result.getProperty(PRODUCTNAME_FIELD);
|
| 210 |
if (itemsNameMap.containsKey(name.trim())) {
|
248 |
if (itemsNameMap.containsKey(name.trim())) {
|
| 211 |
catalogItemId = itemsNameMap.get(name.trim()).getCatalogId();
|
249 |
catalogItemId = itemsNameMap.get(name.trim()).getCatalogId();
|
| 212 |
}
|
250 |
}
|
| 213 |
}
|
251 |
}
|
| 214 |
String key = paidFirstSource + "_" + firstSource + "_"
|
252 |
String key = paidFirstSource + "_" + firstSource + "_"
|
| Line 243... |
Line 281... |
| 243 |
}
|
281 |
}
|
| 244 |
}
|
282 |
}
|
| 245 |
}
|
283 |
}
|
| 246 |
|
284 |
|
| 247 |
private String getSource(String sessionId, String sourceKey) {
|
285 |
private String getSource(String sessionId, String sourceKey) {
|
| 248 |
if (sessionIdSourceMap.isEmpty()) {
|
286 |
if (sessionIdSourceMap.containsKey(sessionId)) {
|
| - |
|
287 |
logger.warning("DailyProductWithSourceAggregator : sessionIdSourceMap hit : "
|
| - |
|
288 |
+ sessionId);
|
| - |
|
289 |
return sessionIdSourceMap.get(sessionId).get(sourceKey);
|
| - |
|
290 |
}
|
| - |
|
291 |
if (sessionId != null && !sessionId.isEmpty()) {
|
| 249 |
Query sessionQuery = new Query(KIND);
|
292 |
Query sessionQuery = new Query(KIND);
|
| 250 |
sessionQuery.addFilter(EVENTTYPE_FILED, Query.FilterOperator.EQUAL,
|
293 |
sessionQuery.addFilter(EVENTTYPE_FIELD, Query.FilterOperator.EQUAL,
|
| 251 |
NEW_SESSION_EVENT);
|
294 |
NEW_SESSION_EVENT);
|
| 252 |
sessionQuery.addFilter(DATE_FILED, Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
295 |
sessionQuery.addFilter(SESSION_ID_FIELD,
|
| 253 |
sessionQuery.addFilter(DATE_FILED, Query.FilterOperator.LESS_THAN, toDate);
|
296 |
Query.FilterOperator.EQUAL, sessionId);
|
| 254 |
|
297 |
|
| 255 |
PreparedQuery sessionPq = datastore.prepare(sessionQuery);
|
298 |
PreparedQuery sessionPq = datastore.prepare(sessionQuery);
|
| 256 |
for (Entity sessionResult : sessionPq.asIterable()) {
|
299 |
for (Entity sessionResult : sessionPq.asIterable()) {
|
| 257 |
String firstSource = "";
|
300 |
String firstSource = "";
|
| 258 |
String sessionSource = "";
|
301 |
String sessionSource = "";
|
| 259 |
if (sessionResult != null) {
|
302 |
if (sessionResult != null) {
|
| 260 |
if (sessionResult.hasProperty(FIRST_SOURCE_FILED)) {
|
303 |
if (sessionResult.hasProperty(FIRST_SOURCE_FIELD)) {
|
| 261 |
firstSource = sessionResult.getProperty(FIRST_SOURCE_FILED).toString();
|
304 |
firstSource = sessionResult.getProperty(
|
| - |
|
305 |
FIRST_SOURCE_FIELD).toString();
|
| 262 |
}
|
306 |
}
|
| 263 |
if (sessionResult.hasProperty(SESSION_SOURCE_FILED)) {
|
307 |
if (sessionResult.hasProperty(SESSION_SOURCE_FIELD)) {
|
| 264 |
sessionSource = sessionResult.getProperty(SESSION_SOURCE_FILED).toString();
|
308 |
sessionSource = sessionResult.getProperty(
|
| - |
|
309 |
SESSION_SOURCE_FIELD).toString();
|
| 265 |
}
|
310 |
}
|
| 266 |
}
|
311 |
}
|
| 267 |
Map<String, String> sessionSourcesMap = new HashMap<String, String>();
|
312 |
Map<String, String> sessionSourcesMap = new HashMap<String, String>();
|
| 268 |
sessionSourcesMap.put(FIRST_SOURCE_KEY, firstSource);
|
313 |
sessionSourcesMap.put(FIRST_SOURCE_KEY, firstSource);
|
| 269 |
sessionSourcesMap.put(SESSION_SOURCE_KEY, sessionSource);
|
314 |
sessionSourcesMap.put(SESSION_SOURCE_KEY, sessionSource);
|
| Line 271... |
Line 316... |
| 271 |
}
|
316 |
}
|
| 272 |
}
|
317 |
}
|
| 273 |
if (sessionIdSourceMap.containsKey(sessionId)) {
|
318 |
if (sessionIdSourceMap.containsKey(sessionId)) {
|
| 274 |
return sessionIdSourceMap.get(sessionId).get(sourceKey);
|
319 |
return sessionIdSourceMap.get(sessionId).get(sourceKey);
|
| 275 |
}
|
320 |
}
|
| 276 |
Query sessionQuery = new Query(KIND);
|
- |
|
| 277 |
sessionQuery.addFilter(EVENTTYPE_FILED, Query.FilterOperator.EQUAL,
|
- |
|
| 278 |
NEW_SESSION_EVENT);
|
- |
|
| 279 |
sessionQuery.addFilter(SESSION_ID_FILED, Query.FilterOperator.EQUAL, sessionId);
|
- |
|
| 280 |
|
- |
|
| 281 |
PreparedQuery sessionPq = datastore.prepare(sessionQuery);
|
- |
|
| 282 |
for (Entity sessionResult : sessionPq.asIterable()) {
|
- |
|
| 283 |
String firstSource = "";
|
- |
|
| 284 |
String sessionSource = "";
|
- |
|
| 285 |
if (sessionResult != null) {
|
- |
|
| 286 |
if (sessionResult.hasProperty(FIRST_SOURCE_FILED)) {
|
- |
|
| 287 |
firstSource = sessionResult.getProperty(FIRST_SOURCE_FILED).toString();
|
- |
|
| 288 |
}
|
- |
|
| 289 |
if (sessionResult.hasProperty(SESSION_SOURCE_FILED)) {
|
- |
|
| 290 |
sessionSource = sessionResult.getProperty(SESSION_SOURCE_FILED).toString();
|
- |
|
| 291 |
}
|
- |
|
| 292 |
}
|
- |
|
| 293 |
Map<String, String> sessionSourcesMap = new HashMap<String, String>();
|
- |
|
| 294 |
sessionSourcesMap.put(FIRST_SOURCE_KEY, firstSource);
|
- |
|
| 295 |
sessionSourcesMap.put(SESSION_SOURCE_KEY, sessionSource);
|
- |
|
| 296 |
sessionIdSourceMap.put(sessionId, sessionSourcesMap);
|
- |
|
| 297 |
}
|
- |
|
| 298 |
if (sessionIdSourceMap.containsKey(sessionId)) {
|
- |
|
| 299 |
return sessionIdSourceMap.get(sessionId).get(sourceKey);
|
- |
|
| 300 |
}
|
- |
|
| 301 |
return "";
|
321 |
return "";
|
| 302 |
}
|
322 |
}
|
| 303 |
|
323 |
|
| 304 |
private void UpdateItemIdEventCount(String event, String countKey, String uniqueCountKey, boolean isCatalogIdEvent) {
|
324 |
private void UpdateItemIdEventCount(String event, String countKey, String uniqueCountKey, boolean isCatalogIdEvent) {
|
| 305 |
Query query = new Query(KIND);
|
325 |
Query query = new Query(KIND);
|
| 306 |
query.addFilter(EVENTTYPE_FILED, Query.FilterOperator.EQUAL, event);
|
326 |
query.addFilter(EVENTTYPE_FIELD, Query.FilterOperator.EQUAL, event);
|
| 307 |
query.addFilter(DATE_FILED, Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
327 |
query.addFilter(DATE_FIELD, Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
|
| 308 |
query.addFilter(DATE_FILED, Query.FilterOperator.LESS_THAN, toDate);
|
328 |
query.addFilter(DATE_FIELD, Query.FilterOperator.LESS_THAN, toDate);
|
| 309 |
PreparedQuery pq = datastore.prepare(query);
|
329 |
PreparedQuery pq = datastore.prepare(query);
|
| 310 |
Set<String> uniqueSet = new HashSet<String>();
|
330 |
Set<String> uniqueSet = new HashSet<String>();
|
| - |
|
331 |
List<Entity> results = new ArrayList<Entity>();
|
| - |
|
332 |
for (Entity e : pq.asList(FetchOptions.Builder.withChunkSize(500))) {
|
| - |
|
333 |
results.add(e);
|
| - |
|
334 |
}
|
| 311 |
for (Entity result : pq.asIterable()) {
|
335 |
for (Entity result : results) {
|
| 312 |
String sessionId = (String)result.getProperty(SESSION_ID_FILED);
|
336 |
String sessionId = (String)result.getProperty(SESSION_ID_FIELD);
|
| 313 |
String firstSource = getSource(sessionId, FIRST_SOURCE_KEY);
|
337 |
String firstSource = getSource(sessionId, FIRST_SOURCE_KEY);
|
| 314 |
String sessionSource = getSource(sessionId, SESSION_SOURCE_KEY);
|
338 |
String sessionSource = getSource(sessionId, SESSION_SOURCE_KEY);
|
| 315 |
String paidFirstSource = "0";
|
339 |
String paidFirstSource = "0";
|
| 316 |
String paidSessionSource = "0";
|
340 |
String paidSessionSource = "0";
|
| 317 |
if (firstSource.startsWith("PAID :")) {
|
341 |
if (firstSource.startsWith("PAID :")) {
|
| 318 |
paidFirstSource = "1";
|
342 |
paidFirstSource = "1";
|
| 319 |
}
|
343 |
}
|
| 320 |
if (sessionSource.startsWith("PAID :")) {
|
344 |
if (sessionSource.startsWith("PAID :")) {
|
| 321 |
paidSessionSource = "1";
|
345 |
paidSessionSource = "1";
|
| 322 |
}
|
346 |
}
|
| 323 |
firstSource = firstSource.replaceAll(".*http[s]?://", "").replaceAll("/.*", "");
|
347 |
firstSource = firstSource.replaceAll(".*http[s]?://", "").replaceAll("/.*", "").replaceAll("www.", "");
|
| 324 |
sessionSource = sessionSource.replaceAll(".*http[s]?://", "").replaceAll("/.*", "");
|
348 |
sessionSource = sessionSource.replaceAll(".*http[s]?://", "").replaceAll("/.*", "").replaceAll("www.", "");
|
| 325 |
List<Long> itemIds = null;
|
349 |
List<Long> itemIds = null;
|
| 326 |
if (!result.hasProperty(ITEMIDS_FILED)) {
|
350 |
if (!result.hasProperty(ITEMIDS_FIELD)) {
|
| 327 |
continue;
|
351 |
continue;
|
| 328 |
}
|
352 |
}
|
| 329 |
try {
|
353 |
try {
|
| 330 |
itemIds = (List<Long>)result.getProperty(ITEMIDS_FILED);
|
354 |
itemIds = (List<Long>)result.getProperty(ITEMIDS_FIELD);
|
| 331 |
} catch (ClassCastException e) {
|
355 |
} catch (ClassCastException e) {
|
| 332 |
try {
|
356 |
try {
|
| 333 |
itemIds = new ArrayList<Long>();
|
357 |
itemIds = new ArrayList<Long>();
|
| 334 |
itemIds.add((Long)result.getProperty(ITEMIDS_FILED));
|
358 |
itemIds.add((Long)result.getProperty(ITEMIDS_FIELD));
|
| 335 |
}
|
359 |
}
|
| 336 |
catch(Exception ex) {
|
360 |
catch(Exception ex) {
|
| 337 |
log(e.getMessage());
|
361 |
log(e.getMessage());
|
| 338 |
}
|
362 |
}
|
| 339 |
}
|
363 |
}
|