[banshee] [Hyena.Metrics] Add JSON MetricsCollection method
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee] [Hyena.Metrics] Add JSON MetricsCollection method
- Date: Fri, 12 Feb 2010 18:05:00 +0000 (UTC)
commit c95e6b9b9b42c743d753bd45897fd1efb1426752
Author: Gabriel Burt <gabriel burt gmail com>
Date: Fri Feb 12 10:04:01 2010 -0800
[Hyena.Metrics] Add JSON MetricsCollection method
.../Banshee.Metrics/BansheeMetrics.cs | 3 +-
.../Hyena/Hyena.Metrics/MetricsCollection.cs | 21 ++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs b/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
index d78b446..13defe3 100644
--- a/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
+++ b/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
@@ -101,7 +101,8 @@ namespace Banshee.Metrics
// TODO schedule sending the data to the server in some timeout?
// TODO remove this, just for testing
- Log.InformationFormat ("Anonymous usage data collected:\n{0}", metrics.ToString ());
+ Log.InformationFormat ("Anonymous usage data collected:\n{0}", metrics.ToJsonString ());
+ //System.IO.File.WriteAllText ("usage-data.json", metrics.ToJsonString ());
}
private void AddMetrics ()
diff --git a/src/Libraries/Hyena/Hyena.Metrics/MetricsCollection.cs b/src/Libraries/Hyena/Hyena.Metrics/MetricsCollection.cs
index f2eb02e..d558490 100644
--- a/src/Libraries/Hyena/Hyena.Metrics/MetricsCollection.cs
+++ b/src/Libraries/Hyena/Hyena.Metrics/MetricsCollection.cs
@@ -30,6 +30,8 @@ using System.Collections.Generic;
using System.Text;
using System.Reflection;
+using Hyena.Json;
+
namespace Hyena.Metrics
{
public sealed class MetricsCollection : List<Metric>, IDisposable
@@ -82,6 +84,25 @@ namespace Hyena.Metrics
return sb.ToString ();
}
+ public string ToJsonString ()
+ {
+ var report = new Dictionary<string, object> ();
+
+ report["ID"] = AnonymousUserId;
+ report["Metrics"] = this.GroupBy<Metric, string> (m => m.Category)
+ .Select (c => {
+ var d = new Dictionary<string, object> ();
+ foreach (var metric in c) {
+ d[metric.Name] = Store.GetFor (metric).Select (s =>
+ new object [] { s.Stamp, s.Value }
+ );
+ }
+ return d;
+ });
+
+ return report.ToJsonString ();
+ }
+
public void AddDefaults ()
{
Add ("Env", "OS Platform", () => PlatformDetection.SystemName);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]