public void RequestsCorrectUrl()
            {
                var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/commit_activity", UriKind.Relative);

                var client = Substitute.For<IApiConnection>();
                var statisticsClient = new StatisticsClient(client);

                statisticsClient.GetCommitActivity("username", "repositoryName");

                client.Received().GetQueuedOperation<IEnumerable<WeeklyCommitActivity>>(expectedEndPoint, Args.CancellationToken);
            }
            public async Task RetrievesContributorsForCorrectUrl()
            {
                var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/contributors", UriKind.Relative);
                var client = Substitute.For<IApiConnection>();
                IReadOnlyList<Contributor> contributors = new ReadOnlyCollection<Contributor>(new[] { new Contributor() });
                client.GetQueuedOperation<Contributor>(expectedEndPoint, Args.CancellationToken)
                    .Returns(Task.FromResult(contributors));
                var statisticsClient = new StatisticsClient(client);

                var result = await statisticsClient.GetContributors("username", "repositoryName");

                Assert.Equal(1, result.Count);
            }
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var expectedEndPoint = new Uri("repositories/1/stats/contributors", UriKind.Relative);
                IReadOnlyList<Contributor> contributors = new ReadOnlyCollection<Contributor>(new[] { new Contributor() });

                var connection = Substitute.For<IApiConnection>();
                connection.GetQueuedOperation<Contributor>(expectedEndPoint, Args.CancellationToken)
                    .Returns(Task.FromResult(contributors));

                var client = new StatisticsClient(connection);

                var result = await client.GetContributors(1);

                Assert.Equal(1, result.Count);
            }
            public async Task RequestsCorrectUrl()
            {
                var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/commit_activity", UriKind.Relative);

                var data = new WeeklyCommitActivity(new[] { 1, 2 }, 100, 42);
                IReadOnlyList<WeeklyCommitActivity> response = new ReadOnlyCollection<WeeklyCommitActivity>(new[] { data });
                var client = Substitute.For<IApiConnection>();
                client.GetQueuedOperation<WeeklyCommitActivity>(expectedEndPoint, Args.CancellationToken)
                    .Returns(Task.FromResult(response));
                var statisticsClient = new StatisticsClient(client);

                var result = await statisticsClient.GetCommitActivity("username", "repositoryName");

                Assert.Equal(2, result.Activity[0].Days.Count);
                Assert.Equal(1, result.Activity[0].Days[0]);
                Assert.Equal(2, result.Activity[0].Days[1]);
                Assert.Equal(100, result.Activity[0].Total);
                Assert.Equal(42, result.Activity[0].Week);
            }
Example #5
0
            public async Task RequestsCorrectUrl()
            {
                var expectedEndPoint = new Uri("repos/username/repositoryName/stats/commit_activity", UriKind.Relative);

                var data = new WeeklyCommitActivity(new[] { 1, 2 }, 100, 42);
                IReadOnlyList <WeeklyCommitActivity> response = new ReadOnlyCollection <WeeklyCommitActivity>(new[] { data });
                var client = Substitute.For <IApiConnection>();

                client.GetQueuedOperation <WeeklyCommitActivity>(expectedEndPoint, Args.CancellationToken)
                .Returns(Task.FromResult(response));
                var statisticsClient = new StatisticsClient(client);

                var result = await statisticsClient.GetCommitActivity("username", "repositoryName");

                Assert.Equal(2, result.Activity[0].Days.Count);
                Assert.Equal(1, result.Activity[0].Days[0]);
                Assert.Equal(2, result.Activity[0].Days[1]);
                Assert.Equal(100, result.Activity[0].Total);
                Assert.Equal(42, result.Activity[0].Week);
            }
Example #6
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                CurrentUser = await _userManager.GetUserAsync(User);
            }
            else
            {
                HttpClient  httpclient = _clientFactory.CreateClient();
                UsersClient client     = new UsersClient(httpclient);
                try
                {
                    CurrentUser = await client.GetAsync(id);
                }
                catch
                {
                    CurrentUser = null;
                }

                try
                {
                    StatisticsClient sscli = new StatisticsClient(httpclient);
                    Statistics = await sscli.GetUserAsync(id);
                }
                catch
                {
                    Statistics = null;
                }
            }

            if (CurrentUser == null)
            {
                return(NotFound($"Unable to load user with ID '{id ?? _userManager.GetUserId(User)}'."));
            }

            return(Page());
        }
            public void RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
            {
                var expectedEndPoint = new Uri("repositories/1/stats/participation", UriKind.Relative);
                var cancellationToken = new CancellationToken();

                var client = Substitute.For<IApiConnection>();
                var statisticsClient = new StatisticsClient(client);

                statisticsClient.GetParticipation(1, cancellationToken);
                
                client.Received().GetQueuedOperation<Participation>(expectedEndPoint, cancellationToken);
            }
Example #8
0
 public void OneTimeSetUp()
 {
     InitDokladApi();
     _statisticsClient = DokladApi.StatisticsClient;
 }
 public async Task ThrowsIfGivenNullOwner()
 {
     var statisticsClient = new StatisticsClient(Substitute.For <IApiConnection>());
     await Assert.ThrowsAsync <ArgumentNullException>(() => statisticsClient.GetContributors(null, "repositoryName"));
 }
Example #10
0
 internal static void SaveScore(string name, int score)
 {
     var statistics = new StatisticsClient();
     statistics.SaveHighscoreAsync(name, score);
 }
Example #11
0
        private void StatsClick(object sender, RoutedEventArgs e)
        {
            Sound.Play(Sounds.Click);
            var statistics = new StatisticsClient();
            statistics.GetStatisticsCompleted += GetStatisticsCompleted;
            statistics.GetStatisticsAsync();

            _dialog = new Dialog {DialogContents = {Content = new StackPanel()}, Header = {Text = Strings.Statistics}};
            _dialog.Loading(LayoutRoot);
        }
Example #12
0
        private void GetAllTimeHighCompleted(object sender, GetHighscoresCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                var grid = (Grid) _dialog.DialogContents.Content;
                var panel = new StackPanel();
                panel.SetValue(Grid.RowProperty, 0);
                panel.SetValue(Grid.ColumnProperty, 0);
                grid.Children.Add(panel);

                var header = new TextBlock
                                 {
                                     Style = Styles.StrongText,
                                     Margin = new Thickness(0, 0, 0, 5),
                                     Text = Strings.HighScoreAllTime
                                 };
                panel.Children.Add(header);

                int place = 1;
                foreach (DataItem score in e.Result)
                {
                    AddHighScore(panel, place, score.Name, score.Value);
                    place++;
                }
            }
            var statistics = new StatisticsClient();
            statistics.GetHighscoresCompleted += GetMonthHighCompleted;
            statistics.GetHighscoresAsync(Game.HighScore, new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1),
                                          null);
        }
        public void Run(Context ctx, string[] args)
        {
            var client = new StatisticsClient(ctx);

            Console.WriteLine(client.GetTotalHours().ToString("0.0"));
        }
            public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
            {
                var expectedEndPoint = new Uri("repositories/1/stats/punch_card", UriKind.Relative);
                var cancellationToken = new CancellationToken();

                var connection = Substitute.For<IApiConnection>();
                IReadOnlyList<int[]> data = new ReadOnlyCollection<int[]>(new[] { new[] { 2, 8, 42 } });

                connection.GetQueuedOperation<int[]>(expectedEndPoint, cancellationToken)
                    .Returns(Task.FromResult(data));
                var client = new StatisticsClient(connection);

                var result = await client.GetPunchCard(1, cancellationToken);

                Assert.Equal(1, result.PunchPoints.Count);
                Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
                Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
                Assert.Equal(42, result.PunchPoints[0].CommitCount);
            }
Example #15
0
        public static async Task <int> CallStatisticsService()
        {
            var service = new StatisticsClient();

            var header = new MessageHeader()
            {
                MessageID           = "101",
                TransactionID       = "101",
                SenderID            = "101",
                SenderApplication   = "Debug",
                ReceiverID          = "101",
                ReceiverApplication = "Effica",
                CharacterSet        = "UTF-16"
            };

            var common = new LisCommon()
            {
                ContractKey   = ContractKey,
                UserId        = UserId,
                CallingSystem = CallingSystem,
                CallingUserId = UserId
            };

            // Initialize Request
            var req = new CommonRequestData()
            {
                Area = new Code()
                {
                    CodeSetName = "Effica/Lifecare", CodeValue = "Kkesk"
                },                                                                          // Department ID
                ContactAuthor = new ContactAuthor()
                {
                    ContactAuthorCodeId = CaCodeId.EfficaUserId, ContactAuthorCode = UserId
                }
                // FunctionType = new Code() { CodeSetName = "Effica/Lifecare", CodeValue = "08" } // Optional
            };

            var commonStats = new CommonStatisticsData()
            {
                /*
                 * EventType = new EventType()
                 * {
                 *  Event="ADD", // ADD/MOD/DEL
                 *  PatientId = new PatientId() { Identifier = "010101-0101" },
                 *  StartDateTime = DateTime.Now,
                 *  UserId = UserId
                 * }
                 */
            };

            var StatsData = new StatisticsData()
            {
                PatientId = new PatientId()
                {
                    Identifier = "010101-0101"
                },
                UserId = UserId,
                Area   = new Code()
                {
                    CodeSetName = "Effica/Lifecare", CodeValue = "Kkesk"
                },
                RequestArea = new Code()
                {
                    CodeSetName = "Effica/Lifecare", CodeValue = "Kkesk"
                },
                Function = new Code()
                {
                    CodeSetName = "Effica/Lifecare", CodeValue = "kotih"
                },
                ContactType = new Code()
                {
                    CodeSetName = "Effica/Lifecare", CodeValue = "1"
                },                                                                             // 1 = doctor appointment, 2 = home visit
                VisitType = new Code()
                {
                    CodeSetName = "Effica/Lifecare", CodeValue = "2"
                },                                                                           // Visit type data as numeral value, E.g 1 = first time visit 2= revisit
                ContentNotes = new ContentNote[] { new ContentNote()
                                                   {
                                                       Content = "INFL1", Amount = 1
                                                   } },                                               // Content note for Influenza flue shot
                ProcedureClasses = new Code[] { new Code()
                                                {
                                                    CodeSetName = "", CodeValue = "SPAT1009"
                                                } },                                                       // SPAT codes, see coding in "koodistopalvelu", http://koodistopalvelu.kanta.fi/codeserver/pages/classification-view-page.xhtml?classificationKey=310&versionKey=387
                StartDateTime = DateTime.Now.AddDays(-1.0),
                EndDateTime   = DateTime.Now,
                VisitUrgency  = new Code()
                {
                    CodeSetName = "Effica/Lifecare", CodeValue = "E"
                },                                                                              // E - No, K - Yes
                IsFirstVisit = new Code()
                {
                    CodeSetName = "Effica/Lifecare", CodeValue = "E"
                },                                                                               // E - No, K - Yes
                FollowUpCares = new Code[] { new Code()
                                             {
                                                 CodeSetName = "", CodeValue = "SPAT1334"
                                             } },                                                       // SPAT codes (SPAT1334 no follow-up actions)
                VisitReasons = new Code[] { new Code()
                                            {
                                                CodeSetName = "Effica/Lifecare", CodeValue = "A25"
                                            } }                                                                 // ICPC2 code
            };

            var GenericStats = new GenericStatData()
            {
            };                                           // Not in use

            // Structure for return data
            var rsp = new StatisticsOperation();

            try
            {
                service.AddStatistics(ref header, common, req, commonStats, StatsData, GenericStats, out rsp);
            }
            catch (Exception e)
            {
                Debug.Write(e.Message);
            }

            return(0);
        }
Example #16
0
 public GrainsManageStatisticsPool(StatisticsClient client, int poolSize) : base(client, poolSize)
 {
 }
            public async Task RetrievesPunchCard()
            {
                var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/punch_card", UriKind.Relative);

                var client = Substitute.For<IApiConnection>();
                IReadOnlyList<int[]> data = new ReadOnlyCollection<int[]>(new[] { new[] { 2, 8, 42 } });
                client.GetQueuedOperation<int[]>(expectedEndPoint, Args.CancellationToken)
                    .Returns(Task.FromResult(data));
                var statisticsClient = new StatisticsClient(client);

                var result = await statisticsClient.GetPunchCard("username", "repositoryName");

                Assert.Equal(1, result.PunchPoints.Count);
                Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
                Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
                Assert.Equal(42, result.PunchPoints[0].CommitCount);
            }
            public async Task EnsureNonNullArguments()
            {
                var client = new StatisticsClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetContributors(null, "name"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetContributors("owner", null));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetContributors("", "name"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetContributors("owner", ""));
            }
 public async Task ThrowsIfGivenNullRepositoryName()
 {
     var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
     await AssertEx.Throws<ArgumentNullException>(() => statisticsClient.GetCommitActivity("owner", null));
 }
Example #20
0
        private void GameWin(object sender, EventArgs e)
        {
            GameWon(_game.Round);
            _game.LastMove = null;
            Sound.Play(Sounds.GameWon);

            var statistics = new StatisticsClient();
            statistics.IsHighscoreCompleted += IsHighscoreCompleted;
            statistics.IsHighscoreAsync(_game.Score, Game.HighScore, DateTime.Today.Day);

            var textBlock = new TextBlock
                                {
                                    Style = Styles.BodyText,
                                    Text = String.Format(Strings.GameWinText, _game.Round, _game.Score.ToString("N0"),
                                                         _game.Moves.ToString("N0")) + "\n\n" + Strings.GameWinChecking
                                };

            _dialog = new Dialog
                          {
                              DialogContents = {Content = new StackPanel()},
                              Header = {Text = Strings.GameWinTitle}
                          };
            _dialog.Closed += SubmitHighScore;
            ((StackPanel) _dialog.DialogContents.Content).Children.Add(textBlock);
            _dialog.Show(LayoutRoot);
        }
 public async Task ThrowsIfGivenNullOwner()
 {
     var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
     await AssertEx.Throws<ArgumentNullException>(() => statisticsClient.GetCodeFrequency(null, "repositoryName"));
 }
Example #22
0
        private void HighScoreClick(object sender, RoutedEventArgs e)
        {
            Sound.Play(Sounds.Click);
            var grid = new Grid();
            grid.RowDefinitions.Add(new RowDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(300, GridUnitType.Pixel)});
            grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(250, GridUnitType.Pixel)});

            _dialog = new Dialog {DialogContents = {Content = grid}, Header = {Text = Strings.HighScore}};
            _dialog.Loading(LayoutRoot);

            var statistics = new StatisticsClient();
            statistics.GetHighscoresCompleted += GetAllTimeHighCompleted;
            statistics.GetHighscoresAsync(Game.HighScore, null, null);
        }
Example #23
0
        public static async Task <ProblemModel> GetAsync(ProblemMetadata metadata, HttpClient client, bool loadDescription, bool loadData)
        {
            ProblemModel res = new ProblemModel
            {
                Metadata = metadata,
            };

            ProblemsClient pcli = new ProblemsClient(client);

            {
                try
                {
                    StatisticsClient stcli = new StatisticsClient(client);
                    res.Statistics = await stcli.GetProblemAsync(metadata.Id);
                }
                catch
                {
                    res.Statistics = null;
                }
            }

            if (loadDescription)
            {
                try
                {
                    res.Description = await pcli.GetDescriptionAsync(metadata.Id);
                }
                catch { }
            }

            if (loadData)
            {
                try
                {
                    res.Samples = await pcli.GetSamplesAsync(metadata.Id);
                }
                catch
                {
                    res.Samples = Array.Empty <TestCaseMetadata>();
                }

                try
                {
                    res.Tests = await pcli.GetTestsAsync(metadata.Id);
                }
                catch
                {
                    res.Tests = Array.Empty <TestCaseMetadata>();
                }
            }

            {
                UsersClient ucli = new UsersClient(client);
                try
                {
                    res.User = await ucli.GetAsync(metadata.UserId);
                }
                catch
                {
                    res.User = null;
                }
            }

            return(res);
        }
Example #24
0
 private void UpdateHighscore()
 {
     var statistics = new StatisticsClient();
     statistics.GetHighscoresCompleted += GetHighscoreCompleted;
     statistics.GetHighscoresAsync(1, new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1), null);
 }
            public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
            {
                var expectedEndPoint = new Uri("repositories/1/stats/code_frequency", UriKind.Relative);

                var cancellationToken = new CancellationToken();
                long firstTimestamp = 159670861;
                long secondTimestamp = 0;
                IReadOnlyList<long[]> data = new ReadOnlyCollection<long[]>(new[]
                {
                    new[] { firstTimestamp, 10, 52 },
                    new[] { secondTimestamp, 0, 9 }
                });

                var connection = Substitute.For<IApiConnection>();
                connection.GetQueuedOperation<long[]>(expectedEndPoint, cancellationToken)
                    .Returns(Task.FromResult(data));
                var client = new StatisticsClient(connection);

                var codeFrequency = await client.GetCodeFrequency(1, cancellationToken);

                Assert.Equal(2, codeFrequency.AdditionsAndDeletionsByWeek.Count);
                Assert.Equal(firstTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[0].Timestamp);
                Assert.Equal(10, codeFrequency.AdditionsAndDeletionsByWeek[0].Additions);
                Assert.Equal(52, codeFrequency.AdditionsAndDeletionsByWeek[0].Deletions);
                Assert.Equal(secondTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[1].Timestamp);
                Assert.Equal(0, codeFrequency.AdditionsAndDeletionsByWeek[1].Additions);
                Assert.Equal(9, codeFrequency.AdditionsAndDeletionsByWeek[1].Deletions);
            }
Example #26
0
 private static void IncreaseValue(string name, int value)
 {
     var statistics = new StatisticsClient();
     statistics.IncreaseValueAsync(name, value);
 }
            public void RequestsCorrectUrl()
            {
                var expectedEndPoint = new Uri("repos/owner/name/stats/participation", UriKind.Relative);

                var client = Substitute.For<IApiConnection>();
                var statisticsClient = new StatisticsClient(client);

                statisticsClient.GetParticipation("owner", "name");

                client.Received().GetQueuedOperation<Participation>(expectedEndPoint, Args.CancellationToken);
            }
 public async Task ThrowsIfGivenNullRepositoryName()
 {
     var statisticsClient = new StatisticsClient(Substitute.For <IApiConnection>());
     await Assert.ThrowsAsync <ArgumentNullException>(() => statisticsClient.GetCommitActivity("owner", null));
 }
 public GrainsExecutivePool(StatisticsClient client, int poolSize) : base(client, poolSize)
 {
 }