[hyena] Add JSON MetricsCollection method



commit e57f97c38fb0037378ddfdef43d0aedfe028c260
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri Feb 12 10:04:01 2010 -0800

    Add JSON MetricsCollection method

 src/Hyena/Hyena.Metrics/MetricsCollection.cs |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/src/Hyena/Hyena.Metrics/MetricsCollection.cs b/src/Hyena/Hyena.Metrics/MetricsCollection.cs
index f2eb02e..d558490 100644
--- a/src/Hyena/Hyena.Metrics/MetricsCollection.cs
+++ b/src/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]