29 using System.Collections;
30 using System.Collections.Generic;
32 using Mono.Data.SqliteClient;
34 using OpenSim.Framework;
36 namespace OpenSim.
Region.UserStatistics
40 #region IStatsController Members
42 public string ReportName
44 get {
return "Sessions"; }
49 Hashtable modeldata =
new Hashtable();
50 modeldata.Add(
"Scenes", pParams[
"Scenes"]);
51 modeldata.Add(
"Reports", pParams[
"Reports"]);
52 SqliteConnection dbConn = (SqliteConnection)pParams[
"DatabaseConnection"];
53 List<SessionList> lstSessions =
new List<SessionList>();
54 Hashtable requestvars = (Hashtable) pParams[
"RequestVars"];
57 string puserUUID = string.Empty;
58 string clientVersionString = string.Empty;
61 if (requestvars != null)
63 if (requestvars.ContainsKey(
"UserID"))
65 UUID testUUID = UUID.Zero;
66 if (UUID.TryParse(requestvars[
"UserID"].ToString(), out testUUID))
68 puserUUID = requestvars[
"UserID"].ToString();
73 if (requestvars.ContainsKey(
"VersionString"))
75 clientVersionString = requestvars[
"VersionString"].ToString();
82 "SELECT distinct a.name_f, a.name_l, a.Agent_ID, b.Session_ID, b.client_version, b.last_updated, b.start_time FROM stats_session_data a LEFT OUTER JOIN stats_session_data b ON a.Agent_ID = b.Agent_ID";
84 if (puserUUID.Length > 0)
91 sql +=
" b.agent_id=:agent_id";
95 if (clientVersionString.Length > 0)
102 sql +=
" b.client_version=:client_version";
106 sql +=
" ORDER BY a.name_f, a.name_l, b.last_updated;";
108 SqliteCommand cmd =
new SqliteCommand(sql, dbConn);
110 if (puserUUID.Length > 0)
111 cmd.Parameters.Add(
new SqliteParameter(
":agent_id", puserUUID));
112 if (clientVersionString.Length > 0)
113 cmd.Parameters.Add(
new SqliteParameter(
":client_version", clientVersionString));
115 SqliteDataReader sdr = cmd.ExecuteReader();
119 UUID userUUID = UUID.Zero;
122 activeSessionList.user_id=UUID.Random();
125 UUID readUUID = UUID.Parse(sdr[
"agent_id"].ToString());
126 if (readUUID != userUUID)
129 activeSessionList.user_id = readUUID;
130 activeSessionList.firstname = sdr[
"name_f"].ToString();
131 activeSessionList.lastname = sdr[
"name_l"].ToString();
132 activeSessionList.sessions =
new List<ShortSessionData>();
133 lstSessions.Add(activeSessionList);
138 ssd.last_update = Utils.UnixTimeToDateTime((uint)Convert.ToInt32(sdr[
"last_updated"]));
139 ssd.start_time = Utils.UnixTimeToDateTime((uint)Convert.ToInt32(sdr[
"start_time"]));
140 ssd.session_id = UUID.Parse(sdr[
"session_id"].ToString());
141 ssd.client_version = sdr[
"client_version"].ToString();
142 activeSessionList.sessions.Add(ssd);
144 userUUID = activeSessionList.user_id;
151 modeldata[
"SessionData"] = lstSessions;
157 List<SessionList> lstSession = (List<SessionList>) pModelResult[
"SessionData"];
158 Dictionary<string, IStatsController> reports = (Dictionary<string, IStatsController>)pModelResult[
"Reports"];
160 const string STYLESHEET =
165 font-size:15px; font-family:Helvetica, Verdana; color:Black;
168 TR.defaultr { padding: 5px; }
169 TD.header { font-weight:bold; padding:5px; }
171 TD.contentright { text-align: right; }
172 TD.contentcenter { text-align: center; }
173 TD.align_top { vertical-align: top; }
177 StringBuilder output =
new StringBuilder();
178 HTMLUtil.HtmlHeaders_O(ref output);
179 output.Append(STYLESHEET);
180 HTMLUtil.HtmlHeaders_C(ref output);
182 HTMLUtil.AddReportLinks(ref output, reports,
"");
184 HTMLUtil.TABLE_O(ref output,
"defaultr");
185 HTMLUtil.TR_O(ref output,
"defaultr");
186 HTMLUtil.TD_O(ref output,
"header");
187 output.Append(
"FirstName");
188 HTMLUtil.TD_C(ref output);
189 HTMLUtil.TD_O(ref output,
"header");
190 output.Append(
"LastName");
191 HTMLUtil.TD_C(ref output);
192 HTMLUtil.TD_O(ref output,
"header");
193 output.Append(
"SessionEnd");
194 HTMLUtil.TD_C(ref output);
195 HTMLUtil.TD_O(ref output,
"header");
196 output.Append(
"SessionLength");
197 HTMLUtil.TD_C(ref output);
198 HTMLUtil.TD_O(ref output,
"header");
199 output.Append(
"Client");
200 HTMLUtil.TD_C(ref output);
201 HTMLUtil.TR_C(ref output);
202 if (lstSession.Count == 0)
204 HTMLUtil.TR_O(ref output,
"");
205 HTMLUtil.TD_O(ref output,
"align_top", 1, 5);
206 output.Append(
"No results for that query");
207 HTMLUtil.TD_C(ref output);
208 HTMLUtil.TR_C(ref output);
215 HTMLUtil.TR_O(ref output,
"");
218 HTMLUtil.TD_O(ref output,
"align_top", ssnlst.sessions.Count, 1);
219 output.Append(ssnlst.firstname);
220 HTMLUtil.TD_C(ref output);
221 HTMLUtil.TD_O(ref output,
"align_top", ssnlst.sessions.Count, 1);
222 output.Append(ssnlst.lastname);
223 HTMLUtil.TD_C(ref output);
225 HTMLUtil.TD_O(ref output,
"content");
226 output.Append(sesdata.last_update.ToShortDateString());
227 output.Append(
" - ");
228 output.Append(sesdata.last_update.ToShortTimeString());
229 HTMLUtil.TD_C(ref output);
230 HTMLUtil.TD_O(ref output,
"content");
231 TimeSpan dtlength = sesdata.last_update.Subtract(sesdata.start_time);
232 if (dtlength.Days > 0)
234 output.Append(dtlength.Days);
235 output.Append(
" Days ");
237 if (dtlength.Hours > 0)
239 output.Append(dtlength.Hours);
240 output.Append(
" Hours ");
242 if (dtlength.Minutes > 0)
244 output.Append(dtlength.Minutes);
245 output.Append(
" Minutes");
247 HTMLUtil.TD_C(ref output);
248 HTMLUtil.TD_O(ref output,
"content");
249 output.Append(sesdata.client_version);
250 HTMLUtil.TD_C(ref output);
251 HTMLUtil.TR_C(ref output);
254 HTMLUtil.TR_O(ref output,
"");
255 HTMLUtil.TD_O(ref output,
"align_top", 1, 5);
256 HTMLUtil.HR(ref output,
"");
257 HTMLUtil.TD_C(ref output);
258 HTMLUtil.TR_C(ref output);
260 HTMLUtil.TABLE_C(ref output);
261 output.Append(
"</BODY>\n</HTML>");
262 return output.ToString();
string RenderView(Hashtable pModelResult)
List< ShortSessionData > sessions
Hashtable ProcessModel(Hashtable pParams)
string RenderJson(Hashtable pModelResult)