%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.data.DataObject" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="java.util.Date" %> <%@ page import="java.util.List" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.HashMap" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Document" %> <%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %> <%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement.Project" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="javax.validation.constraints.Pattern" %> <%@ page import="org.crosswire.webtools.*" %> <%! @Description(value = "Retrieve user statistics", name = "statistics/user") public static class MyParameters extends Parameters { protected ProjectManagement.Project project = null; protected int minDocID = -1; protected int maxDocID = -1; @Description(value = "Get statistics for user other than requesting user (ALL for all)", defaultValue = "[currentUser]", example = "screenName") public String userID; @Description(value = "Get statistics for the primary document group for a Project ID", example = "1") public Integer projectID; @Description(value = "Get statistics for the primary document group for a Project Name", example = "ECM Matthew") public String projectName; @Description(value = "Get statistics for a Document Group", example = "1") public Integer documentGroupID; @Description(value = "Limit each statistic to a maximum number of reported items", defaultValue="none, or userID=ALL: 100", example = "100") public Integer limit; @Description(value = "Show this usage help", example = "true", defaultValue = "false") public Boolean help = false; @Description(value = "Show extra detail for provided docID", example = "20001") public Integer detailDocID = null; @Description(value = "sort by docID rather than latest work", example = "true") public Boolean sortByDocID = false; @Pattern(regexp = "^(xml|html)?$", message = "Valid response formats: \"xml\", \"json\", \"csv\", \"html\"") @Description(value = "specify the result format: xml, json, csv, html", defaultValue = "xml", example = "html") public String format = "xml"; @Override protected void afterLoad() { if ((userID == null || userID.isEmpty()) && getUser() != null) userID = getUser().getUserName(); if ("ALL".equals(userID) && limit == null) limit = 100; } @Override protected void afterValidate() { super.format = this.format; } @Override protected void customValidation() { projectName = Transcription.assureUnicode(projectName); if (projectID != null || projectName != null) { project = projectID != null ? ProjectManagement.getProject(projectID) : ProjectManagement.getProject(projectName); if (project == null) { addError(-7, "Project not found."); return; } } if (project != null && documentGroupID == null) { documentGroupID = project.getDocumentGroupID(); } } @Override protected boolean permissionValidation(HttpServletRequest request, HttpServletResponse response) { return true; } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response); if (params.getErrors().size() == 0 && !params.help) { StringBuffer results = new StringBuffer(); if ("html".equals(params.format)) { %> Statistics for user: <%=params.userID %> <% } else { results.append(""); } DataObject query = new DataObject(); String sql = "select DOCUMENTID, USERID, MIN(CREATEDATE) FIRSTCHANGE, MAX(CREATEDATE) LATESTCHANGE, count(1) IMAGECOUNT from SURROGATEIMAGE WHERE 1=1"; if (!"ALL".equals(params.userID)) { sql += " AND USERID={USERID}"; query.setValue("USERID", params.userID); } String orderBy = params.sortByDocID ? "DOCUMENTID" : "LATESTCHANGE desc"; sql += " group by DOCUMENTID, USERID order by " + orderBy; if (params.limit != null) sql += " limit " + params.limit; StringBuffer substats = new StringBuffer(); List rows = query.getDataSet(sql); int total1 = 0; for (DataObject r : rows) { if ("html".equals(params.format)) { substats.append(""+r.getIntValue("DOCUMENTID")+""+r.getIntValue("IMAGECOUNT")+""+r.getStringValue("USERID")+""+r.getDateValue("LATESTCHANGE")+""); } else { substats.append(""); } total1 += r.getIntValue("IMAGECOUNT"); } if ("html".equals(params.format)) { results.append("Images"); results.append("docIDimageCountuserIDlatestChange"); results.append("" + substats.toString() + ""); } else { results.append(""); results.append(substats.toString()); results.append(""); } query = new DataObject(); sql = "select DOCUMENTID, USERID, MAX(CREATEDATE) LATESTCHANGE, count(DISTINCT(PAGEID)) INDEXEDPAGECOUNT from BIBLICALCONTENT WHERE 1=1"; if (!"ALL".equals(params.userID)) { sql += " AND USERID={USERID}"; query.setValue("USERID", params.userID); } sql += " group by DOCUMENTID, USERID order by " + orderBy; if (params.limit != null) sql += " limit " + params.limit; rows = query.getDataSet(sql); substats = new StringBuffer(); total1 = 0; for (DataObject r : rows) { if ("html".equals(params.format)) { substats.append(""+r.getIntValue("DOCUMENTID")+""+r.getIntValue("INDEXEDPAGECOUNT")+""+r.getStringValue("USERID")+""+r.getDateValue("LATESTCHANGE")+""); } else { substats.append(""); } total1 += r.getIntValue("INDEXEDPAGECOUNT"); } if ("html".equals(params.format)) { results.append("Indexing"); results.append("docIDindexPageCountuserIDlatestChange"); results.append("" + substats.toString() + ""); } else { results.append(""); results.append(substats.toString()); results.append(""); } query = new DataObject(); sql = "select DOCUMENTID, USERID, MAX(CREATEDATE) LATESTCHANGE, count(DISTINCT(PAGEID)) TRANSCRIPTIONPAGECOUNT, SUM(LINECOUNT) TRANSCRIPTIONLINECOUNT from TRANSCRIPTIONPAGE WHERE 1=1"; if (!"ALL".equals(params.userID)) { sql += " AND USERID={USERID}"; query.setValue("USERID", params.userID); } sql += " group by DOCUMENTID, USERID order by " + orderBy; if (params.limit != null) sql += " limit " + params.limit; substats = new StringBuffer(); rows = query.getDataSet(sql); total1 = 0; int total2 = 0; for (DataObject r : rows) { if ("html".equals(params.format)) { String downloadURL = "../../transcript/get?docID=" + r.getIntValue("DOCUMENTID") + "&userName="+r.getStringValue("USERID")+"&fullPage=true&pageID=ALL&format=teiraw"; substats.append(""+r.getIntValue("DOCUMENTID")+""+r.getIntValue("TRANSCRIPTIONPAGECOUNT")+""+r.getIntValue("TRANSCRIPTIONLINECOUNT")+""+r.getStringValue("USERID")+""+r.getDateValue("LATESTCHANGE")+"Download"); } else { substats.append(""); DataObject queryDetail = new DataObject(); sql = "select TP.DOCUMENTID, TP.USERID, TP.CREATEDATE LATESTCHANGE, TP.PAGEID TRANSCRIPTIONPAGEID, TP.LINECOUNT, P.INDEXSTRINGORIG from TRANSCRIPTIONPAGE TP left join PAGE P on P.DOCUMENTID=TP.DOCUMENTID and P.PAGEID=TP.PAGEID WHERE TP.DOCUMENTID={DOCUMENTID} "; queryDetail.setIntValue("DOCUMENTID", params.detailDocID); if (!"ALL".equals(params.userID)) { sql += " AND USERID={USERID}"; queryDetail.setValue("USERID", params.userID); } List rowsDetail = queryDetail.getDataSet(sql); for (DataObject d : rowsDetail) { substats.append(""); } substats.append(""); } else { substats.append("/>"); } } catch (Exception e) { e.printStackTrace(); } } total1 += r.getIntValue("TRANSCRIPTIONPAGECOUNT"); total2 += r.getIntValue("TRANSCRIPTIONLINECOUNT"); } if ("html".equals(params.format)) { results.append("Transcriptions"); results.append("docIDtranscribedPageCounttranscribedLineCountuserIDlatestChangeDownload Transcription"); results.append("" + substats.toString() + ""); } else { results.append(""); results.append(substats.toString()); results.append(""); } query = new DataObject(); sql = "select DOCUMENTID, USERID, MAX(CREATEDATE) LATESTCHANGE, count(1) FEATURECOUNT from FEATURE WHERE 1=1"; if (!"ALL".equals(params.userID)) { sql += " AND USERID={USERID}"; query.setValue("USERID", params.userID); } sql += " group by DOCUMENTID, USERID order by " + orderBy; if (params.limit != null) sql += " limit " + params.limit; substats = new StringBuffer(); rows = query.getDataSet(sql); total1 = 0; for (DataObject r : rows) { int docID = r.getIntValue("DOCUMENTID"); if ("html".equals(params.format)) { substats.append(""+docID+""+r.getIntValue("FEATURECOUNT")+""+r.getStringValue("USERID")+""+r.getDateValue("LATESTCHANGE")+""); } else { substats.append(""); DataObject queryDetail = new DataObject(); sql = "select TP.DOCUMENTID, TP.USERID, TP.CREATEDATE LATESTCHANGE, TP.PAGEID FEATUREPAGEID, TP.FEATURECODE from FEATURE TP WHERE TP.DOCUMENTID={DOCUMENTID}"; queryDetail.setIntValue("DOCUMENTID", params.detailDocID); if (!"ALL".equals(params.userID)) { sql += " AND USERID={USERID}"; queryDetail.setValue("USERID", params.userID); } List rowsDetail = queryDetail.getDataSet(sql); for (DataObject d : rowsDetail) { substats.append(""); } substats.append(""); } else { substats.append("/>"); } } catch (Exception e) { e.printStackTrace(); } } total1 += r.getIntValue("FEATURECOUNT"); } if ("html".equals(params.format)) { results.append("Features"); results.append("docIDfeatureCountuserIDlatestChange"); results.append("" + substats.toString() + ""); } else { results.append(""); results.append(substats.toString()); results.append(""); } if ("html".equals(params.format)) { response.setContentType("text/html"); out.print(results.toString()); } else { results.append(""); Serializer.output(response, out, params, XMLBlock.createXMLBlock(results.toString())); } return; } else { ((Parameters)params).format = "html"; } Serializer.reportErrors(request, response, out, params, true); %>