Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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);
74
 
75
    for (Entity result : pq.asIterable()) {
76
    	if(result.getProperty("eventType").equals("PRODUCT_COMPARE")){
77
    		totalComparisons++;
78
    		String source = (String)result.getProperty("source");
79
    		List<Long>itemIds = (List<Long>)result.getProperty("itemIds");
80
    		totalProductsCompared = totalProductsCompared + itemIds.size();
81
    		if(product_compare_map.containsKey(source)) {
82
    			Long source_count = product_compare_map.get(source);
83
    			source_count = source_count + 1;
84
    			product_compare_map.put(source, source_count);
85
			} else {
86
				product_compare_map.put(source, 1L);
87
			}
88
		}
89
    	else if(result.getProperty("eventType").equals("RESEARCH_ADD")){
90
			String source = (String)result.getProperty("source");
91
    		if(compare_add_map.containsKey(source)) {
92
    			Long source_count = compare_add_map.get(source);
93
    			source_count = source_count + 1;
94
    			compare_add_map.put(source, source_count);
95
			} else {
96
				compare_add_map.put(source, 1L);
97
			}
98
		}
99
    	else if(result.getProperty("eventType").equals("RESEARCH_DELETE")){
100
    		totalProductsDeleted++;
101
		}
102
    }
103
 
104
    double avgComparisons = 0.0;
105
    double avgProductsCompared = 0.0;
106
    if(totalComparisons!=0){
107
    	avgProductsCompared = (double)(totalProductsCompared/totalComparisons);
108
	}
109
	if(totaldays!=0){
110
		avgComparisons = (double)(totalComparisons/totaldays);
111
	}
112
%>
113
<h2> Comparison Stats </h2>
114
<table cellpadding="5" cellspacing="0" border="1">
115
	<thead>
116
		<tr>
117
			<th>Source</th>
118
			<th>Number of Comparisons</th>
119
		</tr>
120
	</thead>
121
	<tbody>
122
	<%
123
	for(Entry<String, Long> comparison: product_compare_map.entrySet()){
124
		String source = comparison.getKey();
125
		long numComparisons = comparison.getValue();
126
	%>
127
			<tr>
128
                <td><%=source%></td>
129
				<td><%=numComparisons%></td>
130
            </tr>    
131
	<%}%>		
132
	</tbody>
133
</table>
134
<h3> Number of Comparisons per Day : <%=avgComparisons%></h3>
135
<h3> Average Size of Comparisons : <%=avgProductsCompared%></h3>
136
<h2> Add to Compare Stats </h2>
137
<table cellpadding="5" cellspacing="0" border="1">
138
	<thead>
139
		<tr>
140
			<th>Source</th>
141
			<th>Number of Comparisons</th>
142
		</tr>
143
	</thead>
144
	<tbody>
145
	<%
146
	for(Entry<String, Long> comparison: compare_add_map.entrySet()){
147
		String source = comparison.getKey();
148
		long numComparisons = comparison.getValue();
149
	%>
150
			<tr>
151
                <td><%=source%></td>
152
				<td><%=numComparisons%></td>
153
            </tr>    
154
	<%}%>		
155
	</tbody>
156
</table>
157
<h2> Comparisons Deleted Stats </h2>
158
<h3> Number of Deleted Comparisons : <%=totalProductsDeleted%></h3>
159
</body>
160
</html>