Subversion Repositories SmartDukaan

Rev

Rev 5552 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5552 phani.kuma 1
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
3
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
4
<%@ page import="com.google.appengine.api.datastore.Query" %>
5
<%@ page import="com.google.appengine.api.datastore.Entity" %>
6
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
7
<%@	page import="com.google.appengine.api.datastore.Query.SortDirection"%>
8
<%@ page import="java.util.HashMap"%>
9
<%@ page import="java.util.Map"%>
10
<%@	page import="java.util.Map.Entry"%>
11
<%@	page import="java.text.ParseException"%>
12
<%@	page import="java.util.Calendar"%>
13
<%@	page import="java.util.TimeZone"%>
14
<%@	page import="java.util.Date"%>
15
<%@	page import="java.util.List"%>
16
<%@	page import="java.util.Calendar"%>
17
<%@	page import="java.text.SimpleDateFormat"%>
18
<%@	page import="java.util.Arrays"%>
19
 
20
<html>
21
<head>
22
<title>Comparison Statistics</title>
23
</head>
24
<body>
25
<%
26
Date toDate = new Date();
27
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
28
cal.add(Calendar.DAY_OF_MONTH, -1);
29
Date fromDate = cal.getTime();
30
SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");
31
String toDateStr  = request.getParameter("toDate");
32
String fromDateStr = request.getParameter("fromDate");
33
if (fromDateStr == null || fromDateStr.isEmpty()) {
34
    fromDateStr = iSdf.format(fromDate);
35
}
36
if (toDateStr == null || toDateStr.isEmpty()) {
37
    toDateStr = iSdf.format(toDate);
38
}
39
%>
40
 
41
<form id="searchfilter" name="searchfilter" method="post" action="/jsp/comparison-stats.jsp">
42
<label>From Date(YYYYMMDD) : </label> <input type="text" name="fromDate" id="fromDate" value="<%= fromDateStr %>"/>
43
<label>To Date(YYYYMMDD) : </label> <input type="text" name="toDate" id="toDate" value="<%= toDateStr %>"/>
44
<input type="Submit" id="Submit" name="Submit" value="Submit" />
45
</form>
46
 
47
<%
48
    try {
49
        if (fromDateStr != null) {
50
            fromDate = iSdf.parse(fromDateStr);
51
        }
52
        if (toDateStr != null) {
53
            toDate = iSdf.parse(toDateStr);
54
        }
55
    }
56
    catch (ParseException pe) {
57
%>
58
        <span>Invalid Date Format</span>
59
<%
60
    }
61
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
62
    Query query = new Query("DataLog");
63
    query.addFilter("eventType", Query.FilterOperator.IN, Arrays.asList("PRODUCT_COMPARE","RESEARCH_ADD","RESEARCH_DELETE"));
64
    query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
65
    query.addFilter("date", Query.FilterOperator.LESS_THAN_OR_EQUAL, toDate);
66
    PreparedQuery pq = datastore.prepare(query);
67
 
68
    Map<String, Long>product_compare_map = new HashMap<String, Long>();
69
    Map<String, Long>compare_add_map = new HashMap<String, Long>();
70
    long totalComparisons = 0;
71
    long totalProductsCompared = 0;
72
    long totalProductsDeleted = 0;
73
    long totaldays = toDate.compareTo(fromDate);
5617 amar.kumar 74
    int i = 0;
75
    String err = "";
5552 phani.kuma 76
    for (Entity result : pq.asIterable()) {
5617 amar.kumar 77
    	try{
78
	    	if(result.getProperty("eventType").equals("PRODUCT_COMPARE")){
79
	    		totalComparisons++;
80
	    		String source = (String)result.getProperty("source");
81
	    		List<Long>itemIds = (List<Long>)result.getProperty("itemIds");
82
	    		totalProductsCompared = totalProductsCompared + itemIds.size();
83
	    		if(product_compare_map.containsKey(source)) {
84
	    			Long source_count = product_compare_map.get(source);
85
	    			source_count = source_count + 1;
86
	    			product_compare_map.put(source, source_count);
87
				} else {
88
					product_compare_map.put(source, 1L);
89
				}
5552 phani.kuma 90
			}
5617 amar.kumar 91
	    	else if(result.getProperty("eventType").equals("RESEARCH_ADD")){
92
				String source = (String)result.getProperty("source");
93
	    		if(compare_add_map.containsKey(source)) {
94
	    			Long source_count = compare_add_map.get(source);
95
	    			source_count = source_count + 1;
96
	    			compare_add_map.put(source, source_count);
97
				} else {
98
					compare_add_map.put(source, 1L);
99
				}
5552 phani.kuma 100
			}
5617 amar.kumar 101
	    	else if(result.getProperty("eventType").equals("RESEARCH_DELETE")){
102
	    		totalProductsDeleted++;
103
			}
104
    	} catch (Exception e) {
105
    		i++;
106
    		err = err.concat(e.getStackTrace().toString());
107
    		System.out.print(e);
108
    	}
5552 phani.kuma 109
    }
110
 
111
    double avgComparisons = 0.0;
112
    double avgProductsCompared = 0.0;
113
    if(totalComparisons!=0){
114
    	avgProductsCompared = (double)(totalProductsCompared/totalComparisons);
115
	}
116
	if(totaldays!=0){
117
		avgComparisons = (double)(totalComparisons/totaldays);
118
	}
119
%>
5617 amar.kumar 120
<h7 style = "display:none"><%=i%></h7>
121
<h7 style = "display:none"><%=err%></h7>
5552 phani.kuma 122
<h2> Comparison Stats </h2>
123
<table cellpadding="5" cellspacing="0" border="1">
124
	<thead>
125
		<tr>
126
			<th>Source</th>
127
			<th>Number of Comparisons</th>
128
		</tr>
129
	</thead>
130
	<tbody>
131
	<%
132
	for(Entry<String, Long> comparison: product_compare_map.entrySet()){
133
		String source = comparison.getKey();
134
		long numComparisons = comparison.getValue();
135
	%>
136
			<tr>
137
                <td><%=source%></td>
138
				<td><%=numComparisons%></td>
139
            </tr>    
140
	<%}%>		
141
	</tbody>
142
</table>
143
<h3> Number of Comparisons per Day : <%=avgComparisons%></h3>
144
<h3> Average Size of Comparisons : <%=avgProductsCompared%></h3>
145
<h2> Add to Compare Stats </h2>
146
<table cellpadding="5" cellspacing="0" border="1">
147
	<thead>
148
		<tr>
149
			<th>Source</th>
150
			<th>Number of Comparisons</th>
151
		</tr>
152
	</thead>
153
	<tbody>
154
	<%
155
	for(Entry<String, Long> comparison: compare_add_map.entrySet()){
156
		String source = comparison.getKey();
157
		long numComparisons = comparison.getValue();
158
	%>
159
			<tr>
160
                <td><%=source%></td>
161
				<td><%=numComparisons%></td>
162
            </tr>    
163
	<%}%>		
164
	</tbody>
165
</table>
166
<h2> Comparisons Deleted Stats </h2>
167
<h3> Number of Deleted Comparisons : <%=totalProductsDeleted%></h3>
168
</body>
169
</html>