<%@ page contentType="text/html;charset=GBK" %>
<%
/**
 *	$RCSfile: stats.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:19 $
 */
%>

<%@ page import="java.text.*,
                 java.util.*,
                 com.jivesoftware.util.*,
                 com.jivesoftware.forum.*,
                 com.jivesoftware.forum.util.*"
	errorPage="error.jsp"
%>

<%@ include file="global.jsp" %>

<%! // Global vars, methods, etc

    //
    static float nDays(ResultFilter filter) {
        Date start = filter.getModifiedDateRangeMin();
        Date end = filter.getModifiedDateRangeMax();
        return (float)((float)(end.getTime() - start.getTime())/((float)24.0*3600.0*1000.0));
    }
%>

<%  // Get parameters
    int start = ParamUtils.getIntParameter(request,"start",0);
    int range = ParamUtils.getIntParameter(request,"range",10);
    int forumsPerPage = 5;

    UserManager userManager = forumFactory.getUserManager();

    // Get a calendar object using  Jive's locale and time zone:
    Calendar cal = Calendar.getInstance(JiveGlobals.getTimeZone(), JiveGlobals.getLocale());

    // Reset the calendar to today's 12 AM:
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    // result filter for today (midnight -> present time)
    ResultFilter filterToday = new ResultFilter();
    filterToday.setStartIndex(start);
    filterToday.setNumResults(range);
    filterToday.setModifiedDateRangeMin(cal.getTime());
    filterToday.setModifiedDateRangeMax(new Date(CacheTimer.currentTime));

    // result filter for yesterday
    ResultFilter filterYesterday = new ResultFilter();
    filterYesterday.setStartIndex(start);
    filterYesterday.setNumResults(range);
    filterYesterday.setModifiedDateRangeMax(cal.getTime());
    // back the date up a day
    cal.roll(Calendar.DAY_OF_YEAR, -1);
    filterYesterday.setModifiedDateRangeMin(cal.getTime());
    float nDaysYesterday = nDays(filterYesterday);

    // result filter for last week (not including today)
    ResultFilter filterWeek = new ResultFilter();
    filterWeek.setStartIndex(start);
    filterWeek.setNumResults(range);
    filterWeek.setModifiedDateRangeMax(cal.getTime());
    // back the date up 6 days
    cal.roll(Calendar.DAY_OF_YEAR, -6);
    filterWeek.setModifiedDateRangeMin(cal.getTime());
    float nDaysWeek = nDays(filterWeek);

    // result filter for last month (not including today)
    ResultFilter filterMonth = new ResultFilter();
    filterMonth.setStartIndex(start);
    filterMonth.setNumResults(range);
    // change the date to be back to one day ago
    cal.roll(Calendar.DAY_OF_YEAR, 6);
    filterMonth.setModifiedDateRangeMax(cal.getTime());
    // back up the date one month
    cal.roll(Calendar.MONTH, -1);
    filterMonth.setModifiedDateRangeMin(cal.getTime());
    float nDaysMonth = nDays(filterMonth);
%>

<%@ include file="header.jsp" %>

<p>

<%  // Title of this page and breadcrumbs
    String title = "基本统计";
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {title, "stats.jsp"}
    };
%>
<%@ include file="title.jsp" %>

<font size="-1">
以下为你的活动论坛的简单的统计。
</font>

<p>

<font size="-1">
<%  int userCount = userManager.getUserCount();
    int fCount = forumFactory.getForumCount();
%>
共有 <b><%= userCount %></b> 个用户
阅读 <b><%= fCount %></b> 个论坛。
</font>
<p>

<font size="-1"><b>新主题 &amp; 消息</b></font><p>

<font size="-1">
以下是每段时间的新消息的测量。
</font>
<p>

<table bgcolor="<%= tblBorderColor %>" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><td>
<table bgcolor="<%= tblBorderColor %>" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#eeeeee">
    <td align="center" rowspan="2"><font size="-2" face="verdana"><b>论坛</b></font></td>
    <td align="center" colspan="2"><font size="-2" face="verdana"><b>今天</b></font></td>
    <td align="center" colspan="2"><font size="-2" face="verdana"><b>昨天</b></font></td>
    <td align="center" colspan="2"><font size="-2" face="verdana"><b>上周</b></font></td>
    <td align="center" colspan="2"><font size="-2" face="verdana"><b>上月</b></font></td>
</tr>
<tr bgcolor="#eeeeee">
    <td align="center"><font size="-2" face="verdana">主题</font></td>
    <td align="center"><font size="-2" face="verdana">消息</font></td>
    <td align="center"><font size="-2" face="verdana">主题</font></td>
    <td align="center"><font size="-2" face="verdana">消息</font></td>
    <td align="center"><font size="-2" face="verdana">主题</font></td>
    <td align="center"><font size="-2" face="verdana">消息</font></td>
    <td align="center"><font size="-2" face="verdana">主题</font></td>
    <td align="center"><font size="-2" face="verdana">消息</font></td>
</tr>

<%
    DecimalFormat numberFormatter = new DecimalFormat("#0.0");

    Iterator itForum = forumFactory.forums();

    int idx=0;
    while (idx++ < start && itForum.hasNext()) {
        itForum.next();
    }
    // show "range" number of forums
    idx=0;

    int forumCount = 0;
    long count;
    float days;

    while (idx++ < range && itForum.hasNext()) {
        Forum forum = (Forum)itForum.next();
        ++forumCount;
        int todayMessageCount = forum.getMessageCount(filterToday);
        int yesterdayMessageCount = forum.getMessageCount(filterYesterday);
        int weekMessageCount = forum.getMessageCount(filterWeek);
        int monthMessageCount = forum.getMessageCount(filterMonth);

        int todayThreadCount = forum.getThreadCount(filterToday);
        int yesterdayThreadCount = forum.getThreadCount(filterYesterday);
        int weekThreadCount = forum.getThreadCount(filterWeek);
        int monthThreadCount = forum.getThreadCount(filterMonth);
%>
<tr bgcolor="#ffffff">
    <td bgcolor="#ebf1f9"><font size="-1"><b><%= forum.getName() %></b></font></td>
    <td align="center"><font size="-1"><%= todayThreadCount %></font></td>
    <td align="center"><font size="-1"><%= todayMessageCount %></font></td>
    <td align="center" bgcolor="#ebf1f9"><font size="-1"><%= yesterdayThreadCount %></td>
    <td align="center" bgcolor="#ebf1f9"><font size="-1"><%= yesterdayMessageCount %></td>
    <td align="center"><font size="-1"><%= weekThreadCount %><br></font><font size="-2" color="#666666">日均<%= numberFormatter.format((float)weekThreadCount/nDaysWeek) %>条</font></td>
    <td align="center"><font size="-1"><%= weekMessageCount %><br></font><font size="-2" color="#666666">日均<%= numberFormatter.format((float)weekMessageCount/nDaysWeek) %>条</font></td>
    <td align="center" bgcolor="#ebf1f9"><font size="-1"><%= monthThreadCount %><br></font><font size="-2" color="#666666">日均<%= numberFormatter.format((float)monthThreadCount/nDaysMonth) %>条</font></td>
    <td align="center" bgcolor="#ebf1f9"><font size="-1"><%= monthMessageCount %><br></font><font size="-2" color="#666666">日均<%= numberFormatter.format((float)monthMessageCount/nDaysMonth) %>条</font></td>
</tr>
<%  } %>
</table>
</td></tr>
</table>

<p>

<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<%  if (start > 0) { %>
	<td width="1%" nowrap><font size="-1"><a href="stats.jsp?start=<%= start-range %>">上<%= range %>个论坛的统计</a></font></td>
<%  } else { %>
	<td width="1%" nowrap><font size="-1">&nbsp;</font></td>
<%  } %>

<%  if (start > 0) { %>
	<td width="98%" align="center"><font size="-1"><a href="stats.jsp?start=0">第一页</a></font></td>
<%  } else { %>
	<td width="98%" nowrap><font size="-1">&nbsp;</font></td>
<%  } %>

<%  if (start+range < forumFactory.getForumCount()) { %>
	<td width="1%" nowrap><font size="-1"><a href="stats.jsp?start=<%= start+range %>"> 下<%= range %>个论坛统计 </a></font></td>
<%  } else { %>
	<td width="1%" nowrap><font size="-1">&nbsp;</font></td>
<%  } %>
</tr>
</table>

<%@ include file="footer.jsp" %>