Example #1
0
        public void ClearTest()
        {
            var target = new EventCounter(() => DateTimeOffset.Now, TimeSpan.FromHours(1));

            target.Count("a");
            target.Count("a");
            target.Clear("a");

            target.GetCount("a").Should().Be(0);
        }
Example #2
0
        public void SimpleCountTest()
        {
            var target = new EventCounter(() => DateTimeOffset.Now, TimeSpan.FromHours(1));

            target.Count("a");
            target.Count("a");
            target.Count("b");

            target.GetCount("a").Should().Be(2);
            target.GetCount("b").Should().Be(1);
            target.GetCount("c").Should().Be(0);
        }
Example #3
0
        public void SurveyTimeTest()
        {
            var time   = T(TimeSpan.Zero);
            var target = new EventCounter(() => time, TimeSpan.FromMinutes(1));

            target.Count("a");
            target.Count("a");
            target.Count("a");
            time = T(TimeSpan.FromMinutes(1));
            target.Count("a");
            time = T(TimeSpan.FromMinutes(2));
            target.Count("a");

            target.GetCount("a").Should().Be(2);
        }
Example #4
0
        public void CleanupTest()
        {
            var time   = T(TimeSpan.Zero);
            var target = new EventCounter(() => time, TimeSpan.FromMinutes(1));

            target.Count("a");
            target.Count("a");
            target.Count("a");
            time = T(TimeSpan.FromMinutes(5));

            target.GetSnapshot()
            .Should().Contain(i => i.Key == "a");
            target.Cleanup();
            target.GetSnapshot()
            .Should().NotContain(i => i.Key == "a");
        }
Example #5
0
        public async Task ConcurrencyTest()
        {
            for (int r = 0; r < 30; r++)
            {
                var target = new EventCounter(() => DateTimeOffset.Now, TimeSpan.FromHours(1));
                var random = new Random();

                var tasks = Enumerable.Range(1, 15)
                            .Select(_ => Task.Run(() =>
                {
                    for (var n = 0; n < 1000; n++)
                    {
                        target.Count(random.Next(30).ToString());
                    }
                })).ToArray();

                await Task.WhenAll(tasks);

                target.GetSnapshot()
                .Sum(i => i.Value)
                .Should().Be(15000);
            }
        }
Example #6
0
        public static void Main()
        {
            // User input
            var           directoryOfJsonFiles = "C:\\Users\\fredrik\\Documents\\playing_with_projections\\data";
            List <string> jsonFiles            = Directory.EnumerateFiles(directoryOfJsonFiles).Where(x => x.Contains(".json")).ToList();

            ConsoleTools.WriteColor($"Found {jsonFiles.Count()} files:", ConsoleColor.Green);
            foreach (string file in jsonFiles)
            {
                int index = jsonFiles.IndexOf(file);
                ConsoleTools.WriteColor($"{index}. {file}", ConsoleColor.Gray);
            }
            ConsoleTools.WriteColor($"{jsonFiles.Count()}. All files", ConsoleColor.Gray);
            Console.WriteLine("Please choose a file (by number)");
            string inp       = Console.ReadLine();
            int    selection = int.Parse(inp);

            string[] selectedFile;
            if (selection == jsonFiles.Count())
            {
                selectedFile = new string[] { directoryOfJsonFiles }
            }
            ;
            else
            {
                selectedFile = new string[] { jsonFiles[selection] }
            };


            ConsoleTools.WriteColor("\nAvailable projections are:", ConsoleColor.Green);
            int pIndex = 0;

            ConsoleTools.WriteColor($"{pIndex}. Count", ConsoleColor.Gray); pIndex++;
            ConsoleTools.WriteColor($"{pIndex}. HowManyPlayersHaveRegistered", ConsoleColor.Gray); pIndex++;
            ConsoleTools.WriteColor($"{pIndex}. HowManyPlayersHaveRegisteredEachMonth", ConsoleColor.Gray); pIndex++;
            ConsoleTools.WriteColor($"{pIndex}. TrendingGames", ConsoleColor.Gray); pIndex++;
            ConsoleTools.WriteColor($"{pIndex}. ActivePlayers", ConsoleColor.Gray); pIndex++;


            Console.WriteLine("Please choose a projection (by number)");
            int selectedProjection = int.Parse(Console.ReadLine());

            var events = GetEvents(selectedFile);

            // Actions
            if (selectedProjection == 0)
            {
                Console.WriteLine("Number of events: {0}", EventCounter.Count(events));
            }
            if (selectedProjection == 1)
            {
                Console.WriteLine("Players registered: {0}", EventCounter.HowManyPlayersHaveRegistered(events));
            }
            if (selectedProjection == 2)
            {
                Dictionary <string, int> dict = EventCounter.HowManyPlayersHaveRegisteredEachMonth(events);
                Console.WriteLine($"Month \t\t Number");
                foreach (KeyValuePair <string, int> kvp in dict)
                {
                    Console.WriteLine($"{kvp.Key, 0}  {kvp.Value, 20}");
                }
            }
            if (selectedProjection == 3)
            {
                IOrderedEnumerable <KeyValuePair <string, int> > dict = EventCounter.TrendingGames(events);
                Console.WriteLine($"Game ID \t\t Plays");
                foreach (KeyValuePair <string, int> kvp in dict)
                {
                    Console.WriteLine($"{kvp.Key,0}  {kvp.Value,20}");
                }
            }
            if (selectedProjection == 4)
            {
                List <string> activePlayerList = EventCounter.ActivePlayers(events);
                Console.WriteLine("Currently Active players");
                activePlayerList.ForEach(x => Console.WriteLine(x));
            }

            Console.ReadKey();
        }
Example #7
0
        public static void Main(string[] args)
        {
            var events = GetEvents(args);

            Console.WriteLine("Number of events: {0}", EventCounter.Count(events));
        }