aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/UserStatistics/Sessions_Report.cs
diff options
context:
space:
mode:
authorTeravus Ovares2009-01-07 23:20:23 +0000
committerTeravus Ovares2009-01-07 23:20:23 +0000
commit95984e05876136cee464b3ecdc66d3cf36aac353 (patch)
tree53625792d2f8b5fcd629079bc0b460efcc2ff560 /OpenSim/Region/UserStatistics/Sessions_Report.cs
parent* refactor: Make some direct IClientAPI calls go through the dialog module in... (diff)
downloadopensim-SC-95984e05876136cee464b3ecdc66d3cf36aac353.zip
opensim-SC-95984e05876136cee464b3ecdc66d3cf36aac353.tar.gz
opensim-SC-95984e05876136cee464b3ecdc66d3cf36aac353.tar.bz2
opensim-SC-95984e05876136cee464b3ecdc66d3cf36aac353.tar.xz
* Added session report.
** Full or two criteria. UserID, or VersionString * Added link to session report from client report.
Diffstat (limited to 'OpenSim/Region/UserStatistics/Sessions_Report.cs')
-rw-r--r--OpenSim/Region/UserStatistics/Sessions_Report.cs260
1 files changed, 260 insertions, 0 deletions
diff --git a/OpenSim/Region/UserStatistics/Sessions_Report.cs b/OpenSim/Region/UserStatistics/Sessions_Report.cs
new file mode 100644
index 0000000..2eeb90d
--- /dev/null
+++ b/OpenSim/Region/UserStatistics/Sessions_Report.cs
@@ -0,0 +1,260 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Text;
32using Mono.Data.SqliteClient;
33using OpenMetaverse;
34using OpenSim.Framework;
35
36namespace OpenSim.Region.UserStatistics
37{
38 public class Sessions_Report : IStatsController
39 {
40 #region IStatsController Members
41
42 public string ReportName
43 {
44 get { return "Sessions"; }
45 }
46
47 public Hashtable ProcessModel(Hashtable pParams)
48 {
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"];
55
56 string puserUUID = string.Empty;
57 string clientVersionString = string.Empty;
58 int queryparams = 0;
59
60 if (requestvars.ContainsKey("UserID"))
61 {
62 UUID testUUID = UUID.Zero;
63 if (UUID.TryParse(requestvars["UserID"].ToString(), out testUUID))
64 {
65 puserUUID = requestvars["UserID"].ToString();
66
67 }
68 }
69
70 if (requestvars.ContainsKey("VersionString"))
71 {
72 UUID testUUID = UUID.Zero;
73
74 clientVersionString = requestvars["VersionString"].ToString();
75
76
77 }
78
79 lock (dbConn)
80 {
81 string sql =
82 "SELECT distinct a.name_f, a.name_l, a.Agent_ID, b.Session_ID, b.client_version, b.last_updated FROM stats_session_data a LEFT OUTER JOIN stats_session_data b ON a.Agent_ID = b.Agent_ID";
83
84 if (puserUUID.Length > 0)
85 {
86 if (queryparams == 0)
87 sql += " WHERE";
88 else
89 sql += " AND";
90
91 sql += " b.agent_id=:agent_id";
92 queryparams++;
93 }
94
95 if (clientVersionString.Length > 0)
96 {
97 if (queryparams == 0)
98 sql += " WHERE";
99 else
100 sql += " AND";
101
102 sql += " b.client_version=:client_version";
103 queryparams++;
104 }
105
106 sql += " ORDER BY a.name_f, a.name_l, b.last_updated;";
107
108 SqliteCommand cmd = new SqliteCommand(sql, dbConn);
109
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));
114
115 SqliteDataReader sdr = cmd.ExecuteReader();
116
117 if (sdr.HasRows)
118 {
119 UUID userUUID = UUID.Zero;
120
121 SessionList activeSessionList = new SessionList();
122 activeSessionList.user_id=UUID.Random();
123 while(sdr.Read())
124 {
125 UUID readUUID = UUID.Parse(sdr["agent_id"].ToString());
126 if (readUUID != userUUID)
127 {
128 activeSessionList = new SessionList();
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);
134 }
135
136 ShortSessionData ssd = new ShortSessionData();
137
138 ssd.last_update = Utils.UnixTimeToDateTime((uint)Convert.ToInt32(sdr["last_updated"]));
139 ssd.session_id = UUID.Parse(sdr["session_id"].ToString());
140 ssd.client_version = sdr["client_version"].ToString();
141 activeSessionList.sessions.Add(ssd);
142
143 userUUID = activeSessionList.user_id;
144 }
145 }
146 sdr.Close();
147 sdr.Dispose();
148
149 }
150 modeldata["SessionData"] = lstSessions;
151 return modeldata;
152 }
153
154 public string RenderView(Hashtable pModelResult)
155 {
156 List<SessionList> lstSession = (List<SessionList>) pModelResult["SessionData"];
157 Dictionary<string, IStatsController> reports = (Dictionary<string, IStatsController>)pModelResult["Reports"];
158
159 const string STYLESHEET =
160 @"
161<STYLE>
162body
163{
164 font-size:15px; font-family:Helvetica, Verdana; color:Black;
165}
166TABLE.defaultr { }
167TR.defaultr { padding: 5px; }
168TD.header { font-weight:bold; padding:5px; }
169TD.content {}
170TD.contentright { text-align: right; }
171TD.contentcenter { text-align: center; }
172TD.align_top { vertical-align: top; }
173</STYLE>
174";
175
176 StringBuilder output = new StringBuilder();
177 HTMLUtil.HtmlHeaders_O(ref output);
178 output.Append(STYLESHEET);
179 HTMLUtil.HtmlHeaders_C(ref output);
180
181 HTMLUtil.AddReportLinks(ref output, reports, "");
182
183 HTMLUtil.TABLE_O(ref output, "defaultr");
184 HTMLUtil.TR_O(ref output, "defaultr");
185 HTMLUtil.TD_O(ref output, "header");
186 output.Append("FirstName");
187 HTMLUtil.TD_C(ref output);
188 HTMLUtil.TD_O(ref output, "header");
189 output.Append("LastName");
190 HTMLUtil.TD_C(ref output);
191 HTMLUtil.TD_O(ref output, "header");
192 output.Append("SessionEnd");
193 HTMLUtil.TD_C(ref output);
194 HTMLUtil.TD_O(ref output, "header");
195 output.Append("Client");
196 HTMLUtil.TD_C(ref output);
197 HTMLUtil.TR_C(ref output);
198 if (lstSession.Count == 0)
199 {
200 HTMLUtil.TR_O(ref output, "");
201 HTMLUtil.TD_O(ref output, "align_top", 1, 4);
202 output.Append("No results for that query");
203 HTMLUtil.TD_C(ref output);
204 HTMLUtil.TR_C(ref output);
205 }
206 foreach (SessionList ssnlst in lstSession)
207 {
208 int cnt = 0;
209 foreach (ShortSessionData sesdata in ssnlst.sessions)
210 {
211 HTMLUtil.TR_O(ref output, "");
212 if (cnt++ == 0)
213 {
214 HTMLUtil.TD_O(ref output, "align_top", ssnlst.sessions.Count, 1);
215 output.Append(ssnlst.firstname);
216 HTMLUtil.TD_C(ref output);
217 HTMLUtil.TD_O(ref output, "align_top", ssnlst.sessions.Count, 1);
218 output.Append(ssnlst.lastname);
219 HTMLUtil.TD_C(ref output);
220 }
221 HTMLUtil.TD_O(ref output, "content");
222 output.Append(sesdata.last_update.ToShortDateString());
223 output.Append(" - ");
224 output.Append(sesdata.last_update.ToShortTimeString());
225 HTMLUtil.TD_C(ref output);
226 HTMLUtil.TD_O(ref output, "content");
227 output.Append(sesdata.client_version);
228 HTMLUtil.TD_C(ref output);
229 HTMLUtil.TR_C(ref output);
230
231 }
232 HTMLUtil.TR_O(ref output, "");
233 HTMLUtil.TD_O(ref output, "align_top", 1, 4);
234 HTMLUtil.HR(ref output, "");
235 HTMLUtil.TD_C(ref output);
236 HTMLUtil.TR_C(ref output);
237 }
238 HTMLUtil.TABLE_C(ref output);
239 output.Append("</BODY>\n</HTML>");
240 return output.ToString();
241 }
242
243 public class SessionList
244 {
245 public string firstname;
246 public string lastname;
247 public UUID user_id;
248 public List<ShortSessionData> sessions;
249 }
250
251 public struct ShortSessionData
252 {
253 public UUID session_id;
254 public string client_version;
255 public DateTime last_update;
256 }
257
258 #endregion
259 }
260}