private void AddMetrics ()
        {
            Add ("Client",       Application.ActiveClient);
            Add ("BuildHostCpu", Application.BuildHostCpu);
            Add ("BuildHostOS",  Application.BuildHostOperatingSystem);
            Add ("BuildTime",    Application.BuildTime);
            Add ("BuildVendor",  Application.BuildVendor);
            Add ("Version",      Application.Version);
            Add ("StartedAt",    ApplicationContext.StartedAt);

            // Query basic stats about what content the user has
            foreach (var src in ServiceManager.SourceManager.FindSources<PrimarySource> ()) {
                var type_name = src.TypeName;
                var reader = new HyenaDataReader (ServiceManager.DbConnection.Query (
                    @"SELECT COUNT(*),
                             COUNT(CASE ifnull(Rating, 0)          WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(BPM, 0)             WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(LastStreamError, 0) WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(Composer, 0)        WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(LicenseUri, 0)      WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(Grouping, 0)        WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE PlayCount                  WHEN 0 THEN 1 ELSE NULL END),
                             AVG(Score),
                             AVG(BitRate),
                             SUM(PlayCount),
                             SUM(SkipCount),
                             CAST (SUM(PlayCount * (Duration/1000)) AS INTEGER),
                             SUM(FileSize)
                    FROM CoreTracks WHERE PrimarySourceID = ?", src.DbId
                ));

                // DateAdded, Grouping
                var results = new string [] {
                    "TrackCount", "RatedTrackCount", "BpmTrackCount", "ErrorTrackCount", "ComposerTrackCount",
                    "LicenseUriTrackCount", "GroupingTrackCount", "UnplayedTrackCount", "AvgScore",
                    "AvgBitRate", "TotalPlayCount", "TotalSkipCount", "TotalPlaySeconds", "TotalFileSize"
                };

                for (int i = 0; i < results.Length; i++) {
                    Add (String.Format ("{0}/{1}", type_name, results[i]), reader.Get<long> (i));
                }
                reader.Dispose ();
            }

            // Wire up event-triggered metrics
            active_source_changed = Add ("ActiveSourceChanged");
            ServiceManager.SourceManager.ActiveSourceChanged += OnActiveSourceChanged;

            shutdown = Add ("ShutdownAt",  () => DateTime.Now);
            duration = Add ("RunDuration", () => DateTime.Now - ApplicationContext.StartedAt);
            Application.ShutdownRequested += OnShutdownRequested;

            sqlite_executed = Add ("LongSqliteCommand");
            HyenaSqliteCommand.CommandExecuted += OnSqliteCommandExecuted;
            HyenaSqliteCommand.RaiseCommandExecuted = true;
            HyenaSqliteCommand.RaiseCommandExecutedThresholdMs = 400;

            playback_source_changed = Add ("PlaybackSourceChanged");
            ServiceManager.PlaybackController.SourceChanged += OnPlaybackSourceChanged;

            shuffle_changed = Add ("ShuffleModeChanged");
            ServiceManager.PlaybackController.ShuffleModeChanged += OnShuffleModeChanged;

            repeat_changed = Add ("RepeatModeChanged");
            ServiceManager.PlaybackController.RepeatModeChanged += OnRepeatModeChanged;
        }
示例#2
0
        private void AddMetrics()
        {
            Add("Client", Application.ActiveClient);
            Add("BuildHostCpu", Application.BuildHostCpu);
            Add("BuildHostOS", Application.BuildHostOperatingSystem);
            Add("BuildTime", Application.BuildTime);
            Add("BuildVendor", Application.BuildVendor);
            Add("Version", Application.Version);
            Add("StartedAt", ApplicationContext.StartedAt);

            // Query basic stats about what content the user has
            foreach (var src in ServiceManager.SourceManager.FindSources <PrimarySource> ())
            {
                var type_name = src.TypeName;
                var reader    = new HyenaDataReader(ServiceManager.DbConnection.Query(
                                                        @"SELECT COUNT(*),
                             COUNT(CASE ifnull(Rating, 0)          WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(BPM, 0)             WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(LastStreamError, 0) WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(Composer, 0)        WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(LicenseUri, 0)      WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE ifnull(Grouping, 0)        WHEN 0 THEN NULL ELSE 1 END),
                             COUNT(CASE PlayCount                  WHEN 0 THEN 1 ELSE NULL END),
                             AVG(Score),
                             AVG(BitRate),
                             SUM(PlayCount),
                             SUM(SkipCount),
                             CAST (SUM(PlayCount * (Duration/1000)) AS INTEGER),
                             SUM(FileSize)
                    FROM CoreTracks WHERE PrimarySourceID = ?", src.DbId
                                                        ));

                // DateAdded, Grouping
                var results = new string [] {
                    "TrackCount", "RatedTrackCount", "BpmTrackCount", "ErrorTrackCount", "ComposerTrackCount",
                    "LicenseUriTrackCount", "GroupingTrackCount", "UnplayedTrackCount", "AvgScore",
                    "AvgBitRate", "TotalPlayCount", "TotalSkipCount", "TotalPlaySeconds", "TotalFileSize"
                };

                for (int i = 0; i < results.Length; i++)
                {
                    Add(String.Format("{0}/{1}", type_name, results[i]), reader.Get <long> (i));
                }
                reader.Dispose();
            }

            // Wire up event-triggered metrics
            active_source_changed = Add("ActiveSourceChanged");
            ServiceManager.SourceManager.ActiveSourceChanged += OnActiveSourceChanged;

            shutdown = Add("ShutdownAt", () => DateTime.Now);
            duration = Add("RunDuration", () => DateTime.Now - ApplicationContext.StartedAt);
            Application.ShutdownRequested += OnShutdownRequested;

            sqlite_executed = Add("LongSqliteCommand");
            HyenaSqliteCommand.CommandExecuted                += OnSqliteCommandExecuted;
            HyenaSqliteCommand.RaiseCommandExecuted            = true;
            HyenaSqliteCommand.RaiseCommandExecutedThresholdMs = 400;

            playback_source_changed = Add("PlaybackSourceChanged");
            ServiceManager.PlaybackController.SourceChanged += OnPlaybackSourceChanged;

            shuffle_changed = Add("ShuffleModeChanged");
            ServiceManager.PlaybackController.ShuffleModeChanged += OnShuffleModeChanged;

            repeat_changed = Add("RepeatModeChanged");
            ServiceManager.PlaybackController.RepeatModeChanged += OnRepeatModeChanged;
        }