1
0

Clients_report.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Text;
  31. using Mono.Data.SqliteClient;
  32. using OpenMetaverse;
  33. using OpenSim.Region.Framework.Scenes;
  34. namespace OpenSim.Region.UserStatistics
  35. {
  36. public class Clients_report : IStatsController
  37. {
  38. #region IStatsController Members
  39. public string ReportName
  40. {
  41. get { return "Client"; }
  42. }
  43. public Hashtable ProcessModel(Hashtable pParams)
  44. {
  45. SqliteConnection dbConn = (SqliteConnection)pParams["DatabaseConnection"];
  46. List<ClientVersionData> clidata = new List<ClientVersionData>();
  47. List<ClientVersionData> cliRegData = new List<ClientVersionData>();
  48. Hashtable regionTotals = new Hashtable();
  49. Hashtable modeldata = new Hashtable();
  50. modeldata.Add("Scenes", pParams["Scenes"]);
  51. modeldata.Add("Reports", pParams["Reports"]);
  52. int totalclients = 0;
  53. int totalregions = 0;
  54. lock (dbConn)
  55. {
  56. string sql = "select count(distinct region_id) as regcnt from stats_session_data";
  57. SqliteCommand cmd = new SqliteCommand(sql, dbConn);
  58. SqliteDataReader sdr = cmd.ExecuteReader();
  59. if (sdr.HasRows)
  60. {
  61. sdr.Read();
  62. totalregions = Convert.ToInt32(sdr["regcnt"]);
  63. }
  64. sdr.Close();
  65. sdr.Dispose();
  66. sql =
  67. "select client_version, count(*) as cnt, avg(avg_sim_fps) as simfps from stats_session_data group by client_version order by count(*) desc LIMIT 10;";
  68. cmd = new SqliteCommand(sql, dbConn);
  69. sdr = cmd.ExecuteReader();
  70. if (sdr.HasRows)
  71. {
  72. while (sdr.Read())
  73. {
  74. ClientVersionData udata = new ClientVersionData();
  75. udata.version = sdr["client_version"].ToString();
  76. udata.count = Convert.ToInt32(sdr["cnt"]);
  77. udata.fps = Convert.ToSingle(sdr["simfps"]);
  78. clidata.Add(udata);
  79. totalclients += udata.count;
  80. }
  81. }
  82. sdr.Close();
  83. sdr.Dispose();
  84. if (totalregions > 1)
  85. {
  86. sql =
  87. "select region_id, client_version, count(*) as cnt, avg(avg_sim_fps) as simfps from stats_session_data group by region_id, client_version order by region_id, count(*) desc;";
  88. cmd = new SqliteCommand(sql, dbConn);
  89. sdr = cmd.ExecuteReader();
  90. if (sdr.HasRows)
  91. {
  92. while (sdr.Read())
  93. {
  94. ClientVersionData udata = new ClientVersionData();
  95. udata.version = sdr["client_version"].ToString();
  96. udata.count = Convert.ToInt32(sdr["cnt"]);
  97. udata.fps = Convert.ToSingle(sdr["simfps"]);
  98. udata.region_id = UUID.Parse(sdr["region_id"].ToString());
  99. cliRegData.Add(udata);
  100. }
  101. }
  102. sdr.Close();
  103. sdr.Dispose();
  104. }
  105. }
  106. foreach (ClientVersionData cvd in cliRegData)
  107. {
  108. if (regionTotals.ContainsKey(cvd.region_id))
  109. {
  110. int regiontotal = (int)regionTotals[cvd.region_id];
  111. regiontotal += cvd.count;
  112. regionTotals[cvd.region_id] = regiontotal;
  113. }
  114. else
  115. {
  116. regionTotals.Add(cvd.region_id, cvd.count);
  117. }
  118. }
  119. modeldata["ClientData"] = clidata;
  120. modeldata["ClientRegionData"] = cliRegData;
  121. modeldata["RegionTotals"] = regionTotals;
  122. modeldata["Total"] = totalclients;
  123. return modeldata;
  124. }
  125. public string RenderView(Hashtable pModelResult)
  126. {
  127. List<ClientVersionData> clidata = (List<ClientVersionData>) pModelResult["ClientData"];
  128. int totalclients = (int)pModelResult["Total"];
  129. Hashtable regionTotals = (Hashtable) pModelResult["RegionTotals"];
  130. List<ClientVersionData> cliRegData = (List<ClientVersionData>) pModelResult["ClientRegionData"];
  131. List<Scene> m_scenes = (List<Scene>)pModelResult["Scenes"];
  132. Dictionary<string, IStatsController> reports = (Dictionary<string, IStatsController>)pModelResult["Reports"];
  133. const string STYLESHEET =
  134. @"
  135. <STYLE>
  136. body
  137. {
  138. font-size:15px; font-family:Helvetica, Verdana; color:Black;
  139. }
  140. TABLE.defaultr { }
  141. TR.defaultr { padding: 5px; }
  142. TD.header { font-weight:bold; padding:5px; }
  143. TD.content {}
  144. TD.contentright { text-align: right; }
  145. TD.contentcenter { text-align: center; }
  146. TD.align_top { vertical-align: top; }
  147. </STYLE>
  148. ";
  149. StringBuilder output = new StringBuilder();
  150. HTMLUtil.HtmlHeaders_O(ref output);
  151. output.Append(STYLESHEET);
  152. HTMLUtil.HtmlHeaders_C(ref output);
  153. HTMLUtil.AddReportLinks(ref output, reports, "");
  154. HTMLUtil.TABLE_O(ref output, "defaultr");
  155. HTMLUtil.TR_O(ref output, "");
  156. HTMLUtil.TD_O(ref output, "header");
  157. output.Append("ClientVersion");
  158. HTMLUtil.TD_C(ref output);
  159. HTMLUtil.TD_O(ref output, "header");
  160. output.Append("Count/%");
  161. HTMLUtil.TD_C(ref output);
  162. HTMLUtil.TD_O(ref output, "header");
  163. output.Append("SimFPS");
  164. HTMLUtil.TD_C(ref output);
  165. HTMLUtil.TR_C(ref output);
  166. foreach (ClientVersionData cvd in clidata)
  167. {
  168. HTMLUtil.TR_O(ref output, "");
  169. HTMLUtil.TD_O(ref output, "content");
  170. string linkhref = "sessions.report?VersionString=" + cvd.version;
  171. HTMLUtil.A(ref output, cvd.version, linkhref, "");
  172. HTMLUtil.TD_C(ref output);
  173. HTMLUtil.TD_O(ref output, "content");
  174. output.Append(cvd.count);
  175. output.Append("/");
  176. if (totalclients > 0)
  177. output.Append((((float)cvd.count / (float)totalclients)*100).ToString());
  178. else
  179. output.Append(0);
  180. output.Append("%");
  181. HTMLUtil.TD_C(ref output);
  182. HTMLUtil.TD_O(ref output, "content");
  183. output.Append(cvd.fps);
  184. HTMLUtil.TD_C(ref output);
  185. HTMLUtil.TR_C(ref output);
  186. }
  187. HTMLUtil.TABLE_C(ref output);
  188. if (cliRegData.Count > 0)
  189. {
  190. HTMLUtil.TABLE_O(ref output, "defaultr");
  191. HTMLUtil.TR_O(ref output, "");
  192. HTMLUtil.TD_O(ref output, "header");
  193. output.Append("Region");
  194. HTMLUtil.TD_C(ref output);
  195. HTMLUtil.TD_O(ref output, "header");
  196. output.Append("ClientVersion");
  197. HTMLUtil.TD_C(ref output);
  198. HTMLUtil.TD_O(ref output, "header");
  199. output.Append("Count/%");
  200. HTMLUtil.TD_C(ref output);
  201. HTMLUtil.TD_O(ref output, "header");
  202. output.Append("SimFPS");
  203. HTMLUtil.TD_C(ref output);
  204. HTMLUtil.TR_C(ref output);
  205. foreach (ClientVersionData cvd in cliRegData)
  206. {
  207. HTMLUtil.TR_O(ref output, "");
  208. HTMLUtil.TD_O(ref output, "content");
  209. output.Append(regionNamefromUUID(m_scenes, cvd.region_id));
  210. HTMLUtil.TD_C(ref output);
  211. HTMLUtil.TD_O(ref output, "content");
  212. output.Append(cvd.version);
  213. HTMLUtil.TD_C(ref output);
  214. HTMLUtil.TD_O(ref output, "content");
  215. output.Append(cvd.count);
  216. output.Append("/");
  217. if ((int)regionTotals[cvd.region_id] > 0)
  218. output.Append((((float)cvd.count / (float)((int)regionTotals[cvd.region_id])) * 100).ToString());
  219. else
  220. output.Append(0);
  221. output.Append("%");
  222. HTMLUtil.TD_C(ref output);
  223. HTMLUtil.TD_O(ref output, "content");
  224. output.Append(cvd.fps);
  225. HTMLUtil.TD_C(ref output);
  226. HTMLUtil.TR_C(ref output);
  227. }
  228. HTMLUtil.TABLE_C(ref output);
  229. }
  230. output.Append("</BODY>");
  231. output.Append("</HTML>");
  232. return output.ToString();
  233. }
  234. public string regionNamefromUUID(List<Scene> scenes, UUID region_id)
  235. {
  236. string returnstring = string.Empty;
  237. foreach (Scene sn in scenes)
  238. {
  239. if (region_id == sn.RegionInfo.originRegionID)
  240. {
  241. returnstring = sn.RegionInfo.RegionName;
  242. break;
  243. }
  244. }
  245. if (returnstring.Length == 0)
  246. {
  247. returnstring = region_id.ToString();
  248. }
  249. return returnstring;
  250. }
  251. #endregion
  252. }
  253. public struct ClientVersionData
  254. {
  255. public UUID region_id;
  256. public string version;
  257. public int count;
  258. public float fps;
  259. }
  260. }