Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4912 amar.kumar 1
<%@ page import="java.util.Arrays"%>
2
<%@ page import="java.util.Calendar"%>
3
<%@ page import="java.text.ParseException"%>
4
<%@ page import="java.util.TimeZone"%>
5
<%@ page import="java.text.SimpleDateFormat"%>
6
<%@ page import="java.util.Date"%>
7
<%@ page import="com.google.appengine.api.datastore.Query.SortDirection"%>
8
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
9
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
10
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
11
<%@ page import="com.google.appengine.api.datastore.Query" %>
12
<%@ page import="com.google.appengine.api.datastore.Entity" %>
13
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
14
 
15
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
16
<html>
17
<head>
18
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
19
<title>Captcha Stats</title>
20
</head>
21
 
22
<% Date toDate = new Date();
23
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("IST"));
24
cal.add(Calendar.DAY_OF_MONTH, -1);
25
Date fromDate = cal.getTime();
26
SimpleDateFormat iSdf = new SimpleDateFormat("yyyyMMdd");
27
String toDateStr  = request.getParameter("toDate");
28
String fromDateStr = request.getParameter("fromDate");
29
if (fromDateStr == null || fromDateStr.isEmpty()) {
30
    fromDateStr = iSdf.format(fromDate);
31
}
32
if (toDateStr == null || toDateStr.isEmpty()) {
33
    toDateStr = iSdf.format(toDate);
34
}
35
%>
36
<body>
37
<form id="searchfilter" name="searchfilter" method="post" action="/jsp/captcha-stats.jsp">
38
<label>From Date(YYYYMMDD) : </label> <input type="text" name="fromDate" id="fromDate" value="<%= fromDateStr %>"/>
39
<label>To Date(YYYYMMDD) : </label> <input type="text" name="toDate" id="toDate" value="<%= toDateStr %>"/>
40
<input type="Submit" id="Submit" name="Submit" value="Submit" />
41
</form>
42
 
43
<%
44
    try {
45
        if (fromDateStr != null) {
46
            fromDate = iSdf.parse(fromDateStr);
47
        }
48
        if (toDateStr != null) {
49
            toDate = iSdf.parse(toDateStr);
50
        }
51
    }
52
    catch (ParseException pe) {
53
%>
54
        <span>Invalid Date Format</span>
55
<%
56
    }
57
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
58
    sdf.setTimeZone(TimeZone.getTimeZone("IST"));
59
 
60
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
61
    Query query = new Query("DataLog");
62
    query.addFilter("eventType", Query.FilterOperator.IN,Arrays.asList("CAPTCHA_SUCCESS","CAPTCHA_FAILED"));
63
    query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, fromDate);
64
    query.addFilter("date", Query.FilterOperator.LESS_THAN_OR_EQUAL, toDate);
65
    PreparedQuery pq = datastore.prepare(query);
66
 
67
 
68
	Integer captchaSuccessCount = 0;
69
	Integer captchaFailureCount = 0;
70
	for (Entity result : pq.asIterable()) {
71
		if(result.getProperty("eventType").equals("CAPTCHA_SUCCESS")){
72
			captchaSuccessCount++;
73
 
74
		}else{
75
			captchaFailureCount++;
76
		}
77
	}
78
 
79
	double captchaFailureRate = 0.0;
80
	if((captchaSuccessCount+captchaFailureCount)!=0){
81
		captchaFailureRate = ((double)((captchaFailureCount*100*100)/(captchaSuccessCount+captchaFailureCount)))/100.0;
82
	}
83
%>
84
 
85
<h3> Captcha Success Count : <%=captchaSuccessCount%></h3>
86
<h3> Captcha Failure Count : <%=captchaFailureCount%></h3>
87
<h3> Captcha Failure Rate : <%=captchaFailureRate%>%</h3> 	
88
 
89
</body>
90
</html>