Example #1
0
        private static void CalculateStats(Artist artist)
        {
            var stats = _musicService.CalculateStats(artist).Result;

            Write("");
            Write($"OK, here are the lyric stats for {artist.Name}:");
            Write("");
            Write($"In {stats.Albums.Count()} album{stats.Albums.Count().Pluralise()} we found {stats.Songs} song{stats.Songs.Pluralise()}.");
            Write("");
            Write($"Of these, we could get the lyrics for {stats.SongsWithLyrics} song{stats.SongsWithLyrics.Pluralise()}, with a total of {stats.TotalDistinctNonStopWords} unique words being used (after removing stop words).");
            Write("");
            Success($"So that's an average of {Math.Round(stats.AverageNumberOfWords, 2)} words per song.");
            Write("");
            Write("But wait, there's more:");
            Write("");
            Write($"The biggest number of words in a song (after removing stop words) was {stats.MaximumNumberOfNonStopWords}");
            Write("");
            Write($"And the smallest number of words in a song (after removing stop words) was {stats.MinimumNumberOfNonStopWords}");
            Write("");
            Write("Here are the 10 longest words we found:");
            foreach (var longWord in stats.LongestWords.OrderByDescending(x => x.Length).Take(10))
            {
                Write($"  {longWord}");
            }
            Write("");
            Write("And here are the 10 most popular words:");
            foreach (var kvp in stats.MostPopularNonStopWords.OrderByDescending(x => x.Value).Take(10))
            {
                Write($"  {kvp.Key} ({kvp.Value} times)");
            }
            Write("");
            Write("That was fun!");
        }