Beispiel #1
0
        // [TestMethod]
        public async Task ApplyMetricLiftWithMediaFetchesFromActivityInject_GivesValidResult()
        {
            // Arrange
            User pAuth = await Operation.UserFavoritesStatistics("Drens5");

            // Set up metriclift
            GenreAndTagStatInfo statInfo = new GenreAndTagStatInfo(pAuth, StatInfoMode.Quick);
            await statInfo.Initialize();

            Metric metric = new Metric(statInfo, MetricMode.Count);

            MetricLift metricLift = new MetricLift(104051, 20714, 108147, MetricLiftMode.Connection, metric);

            // Set up media to aggregate with metriclift, using activity inject.
            List <int> injectMedia = new List <int>();

            injectMedia.Add(15227);
            ActivityInject testActivityInject = new ActivityInject(injectMedia, 50, ActivityInject.ListActivityStatusSelection.All, pAuth);

            List <Media> mediaToConsider = await testActivityInject.ActivityInjectMediaSelection();

            // Act
            List <MetricLiftAggregation> metricLiftResults = await metricLift.ApplyMetricLift(mediaToConsider);

            // Assert, by break point.
        }
Beispiel #2
0
        private async void ActivityInjectRunButton_Click(object sender, EventArgs e)
        {
            // Make form unresponsive to user input.
            ActivityInjectPanel.Enabled = false;

            // User Update
            ActivityInjectStatusLabel.Text    = "Parsing User Input.";
            ActivityInjectStatusLabel.Visible = true;

            // Parse inject media ids.
            String[]   textMediaIds = InjectMediaTextBox.Text.Split(new char[] { ',' });
            List <int> mediaIds     = new List <int>(textMediaIds.Length);

            foreach (string textMediaId in textMediaIds)
            {
                if (int.TryParse(textMediaId, out int mediaId))
                {
                    if (mediaIds.Exists(i => i == mediaId))
                    {
                        continue;
                    }
                    else
                    {
                        mediaIds.Add(mediaId);
                    }
                }
            }

            // Parse activity status.
            ActivityInject.ListActivityStatusSelection listActivitionStatusSelection;
            if (ActivityStatusSelectionRadioButtonAll.Checked)
            {
                listActivitionStatusSelection = ActivityInject.ListActivityStatusSelection.All;
            }
            else if (ActivityStatusSelectionRadioButtonCompleted.Checked)
            {
                listActivitionStatusSelection = ActivityInject.ListActivityStatusSelection.CompletedOnly;
            }
            else if (ActivityStatusSelectionRadioButtonNotPlanning.Checked)
            {
                listActivitionStatusSelection = ActivityInject.ListActivityStatusSelection.NotPlanning;
            }
            else
            {
                throw new ArgumentException("Invalid ListActivityStatusSelection in MainForm.");
            }

            // Parse Inject Amount.
            int amount = (int)SelectionPerMediaNumericUpDown.Value;

            // Parse Coupled Tags.
            List <CoupledTag> cTags;

            string[] cTagsRaw = CoupledTagsTextBox.Lines;
            if (cTagsRaw == null || cTagsRaw.Length == 0)
            {
                cTags = null;
            }
            else
            {
                cTags = new List <CoupledTag>(cTagsRaw.Length);
                foreach (string cTagRaw in cTagsRaw)
                {
                    // Skip lines with no text.
                    if (cTagRaw == null || cTagRaw.Length == 0)
                    {
                        continue;
                    }

                    string[]      cTagRawInnerTags        = cTagRaw.Split(new char[] { ',' });
                    List <string> cTagRawInnerTagsTrimmed = new List <string>(cTagRawInnerTags.Length);
                    foreach (string innerTag in cTagRawInnerTags)
                    {
                        cTagRawInnerTagsTrimmed.Add(innerTag.Trim());
                    }
                    cTags.Add(new CoupledTag(cTagRawInnerTagsTrimmed));
                }
            }

            // Parse user.
            User user = await Operation.UserFavoritesStatistics(AnilistUsernameTextBox.Text.Trim());

            // MetricLift Declerations, in case of addition.
            StatInfoMode   statInfoMode;
            MetricMode     metricMode;
            MetricLiftMode metricLiftMode;

            GenreAndTagStatInfo statInfo;
            Metric     metric;
            MetricLift metricLift = null;

            // Set up metriclift.
            if (metriclift)
            {
                // User Update
                ActivityInjectStatusLabel.Text = "Setting up MetricLift.";

                // Parse StatInfoMode
                if (MetricLiftStatInfoRadioButtonQuick.Checked)
                {
                    statInfoMode = StatInfoMode.Quick;
                }
                else if (MetricLiftStatInfoRadioButtonSophisticated.Checked)
                {
                    statInfoMode = StatInfoMode.Sophisticated;
                }
                else if (MetricLiftStatInfoRadioButtonFavourites.Checked)
                {
                    statInfoMode = StatInfoMode.Favourites;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Invalid StatInfoMode in MainForm MetricLiftPanel!");
                }

                // Parse MetricMode
                if (MetricLiftMetricModeCountRadioButton.Checked)
                {
                    metricMode = MetricMode.Count;
                }
                else if (MetricLiftMetricModeMinutesWatchedRadioButton.Checked)
                {
                    metricMode = MetricMode.MinutesWatched;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Invalid MetricMode in MainForm MetricLiftPanel!");
                }

                // Parse MetricLiftMode
                if (MetricLiftModeArrowRadioButton.Checked)
                {
                    metricLiftMode = MetricLiftMode.Arrow;
                }
                else if (MetricLiftModeConnectionRadioButton.Checked)
                {
                    metricLiftMode = MetricLiftMode.Connection;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Invalid MetricLiftMode in MainForm MetricLiftPanel!");
                }

                statInfo = new GenreAndTagStatInfo(user, statInfoMode);
                await statInfo.Initialize();

                metric     = new Metric(statInfo, metricMode);
                metricLift = new MetricLift(baseMediaId1, baseMediaId2, aptMediaId, metricLiftMode, metric);
            }

            // User Update
            ActivityInjectStatusLabel.Text = "Running Activity Inject.";

            // Run Activity Inject.
            ActivityInject activityInject = new ActivityInject(mediaIds, amount, listActivitionStatusSelection,
                                                               user, cTags);

            List <CountMedia>            result            = null;
            List <Media>                 mediaToConsider   = null;
            List <MetricLiftAggregation> metricLiftResults = null;

            // MetricLift + Activity Inject
            if (metriclift)
            {
                // Activity Inject part.
                mediaToConsider = await activityInject.ActivityInjectMediaSelection();

                // User Update
                ActivityInjectStatusLabel.Text = "Applying MetricLift.";

                // Apply MetricLift
                try
                {
                    // In this case, this is where the ArgumentNullException may appear, the one below is for solo activity inject.
                    metricLiftResults = await metricLift.ApplyMetricLift(mediaToConsider);
                }
                catch (ArgumentNullException)
                {
                    NoResultsLabel.Enabled = true;
                    NoResultsLabel.Visible = true;

                    // Disable the buttons
                    LocalPopularitySortedNextButton.Enabled     = false;
                    LocalPopularitySortedPreviousButton.Enabled = false;
                    MeanScoreSortedNextButton.Enabled           = false;
                    MeanScoreSortedPreviousButton.Enabled       = false;

                    // Disable links
                    MeanScoreSortedLinkLabel.Enabled       = false;
                    LocalPopularitySortedLinkLabel.Enabled = false;
                }
            }
            else
            {
                // Running Activity Inject solo.
                result = await activityInject.RunActivityInject();
            }

            // Go to next label with interactive UI to show results.
            ActivityInjectStatusLabel.Visible = false;
            ActivityInjectPanel.Visible       = false;
            ResultsPanel.Enabled = true;
            ResultsPanel.Visible = true;

            try
            {
                if (metriclift)
                {
                    InteractiveMetricLiftResultsPanel(metricLiftResults);
                }
                else
                {
                    InteractiveMeanScoreAndLocalPopularityResultsPanel(result);
                }
            }
            catch (ArgumentNullException)
            {
                NoResultsLabel.Enabled = true;
                NoResultsLabel.Visible = true;

                // Disable the buttons
                LocalPopularitySortedNextButton.Enabled     = false;
                LocalPopularitySortedPreviousButton.Enabled = false;
                MeanScoreSortedNextButton.Enabled           = false;
                MeanScoreSortedPreviousButton.Enabled       = false;

                // Disable links
                MeanScoreSortedLinkLabel.Enabled       = false;
                LocalPopularitySortedLinkLabel.Enabled = false;
            }
        }