Beispiel #1
0
        /// <summary>
        /// Gets the vote partitions of a plan.
        /// </summary>
        /// <param name="lines">The lines of a vote plan.</param>
        /// <param name="partitionMode">The partition mode being used.</param>
        /// <param name="author">The author of the post.</param>
        /// <returns>Returns the vote partitioned appropriately.</returns>
        private List <string> GetVotePartitionsFromPlan(IEnumerable <string> lines, PartitionMode partitionMode, string author)
        {
            switch (partitionMode)
            {
            case PartitionMode.None:
                // No partitioning; no special treatment
                return(PartitionByNone(lines, author));

            case PartitionMode.ByLine:
                // When partitioning by line, promote the plan first.
                // The label line can be discarded, and the others treated as less indented.
                return(PartitionByLine(PromoteLines(lines), author));

            case PartitionMode.ByLineTask:
                // When partitioning by line, promote the plan first.
                // The label line can be discarded, and the others treated as less indented.
                return(PartitionByLineTask(lines, author));

            case PartitionMode.ByBlock:
                // Normal block partitioning means we don't partition plans.
                // They will end up as a single block for the regular vote to consume.
                return(PartitionByNone(lines, author));

            case PartitionMode.ByBlockAll:
                // When partitioning by BlockAll, any plans are themselves partitioned by block (after promotion).
                // Make sure to preserve the task from the main line on the resulting blocks.
                string planTask = VoteString.GetVoteTask(lines.First());
                var    blocks   = PartitionByBlock(PromoteLines(lines), author);
                return(ApplyTaskToBlocks(blocks, planTask));

            default:
                throw new ArgumentException($"Unknown partition mode: {partitionMode}");
            }
        }
Beispiel #2
0
        public static List <VotePartition> GetPartitionsFrom(Vote vote, PartitionMode partitionMode)
        {
            List <VotePartition> partitions = new List <VotePartition>();


            return(partitions);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the partitions of a vote based on partition mode and vote type.
        /// </summary>
        /// <param name="lines">The lines of a vote.</param>
        /// <param name="partitionMode">The partition mode being used.</param>
        /// <param name="voteType">The vote type being partitioned.</param>
        /// <param name="author">The author of the post.</param>
        /// <returns>Returns a list of partitions, representing the pieces of the vote.</returns>
        private List <string> GetVotePartitions(IEnumerable <string> lines, PartitionMode partitionMode, VoteType voteType, string author)
        {
            if (lines == null)
            {
                throw new ArgumentNullException(nameof(lines));
            }
            if (string.IsNullOrEmpty(author))
            {
                throw new ArgumentNullException(nameof(author));
            }
            if (!lines.Any())
            {
                return(new List <string>());
            }

            switch (voteType)
            {
            case VoteType.Rank:
                return(GetVotePartitionsFromRank(lines, partitionMode, author));

            case VoteType.Plan:
                return(GetVotePartitionsFromPlan(lines, partitionMode, author));

            case VoteType.Vote:
                return(GetVotePartitionsFromVote(lines, partitionMode, author));

            default:
                throw new ArgumentException($"Unknown vote type: {voteType}");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets the partitions of a vote.
        /// </summary>
        /// <param name="lines">The lines of a vote.</param>
        /// <param name="partitionMode">The partition mode being used.</param>
        /// <param name="author">The author of the post.</param>
        /// <returns>Returns the vote, partitioned according to the requested mode.</returns>
        private List <string> GetVotePartitionsFromVote(IEnumerable <string> lines, PartitionMode partitionMode, string author)
        {
            switch (partitionMode)
            {
            case PartitionMode.None:
                // No partitioning
                return(PartitionByNone(lines, author));

            case PartitionMode.ByLine:
                // Partition by line
                return(PartitionByLine(lines, author));

            case PartitionMode.ByLineTask:
                // Partition by line; keep parent tasks
                return(PartitionByLineTask(lines, author));

            case PartitionMode.ByBlock:
                // Partition by block.  Plans are considered single blocks.
                return(PartitionByBlock(lines, author));

            case PartitionMode.ByBlockAll:
                // BlockAll partitioning means any plans are partitioned by block as well.
                return(PartitionByBlock(lines, author));

            default:
                throw new ArgumentException($"Unknown partition mode: {partitionMode}");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Partition the vote and store the vote and voter.
        /// </summary>
        /// <param name="post">The post it was derived from.</param>
        /// <param name="partitionMode">The partition mode being used.</param>
        private void ProcessVote(PostComponents post, PartitionMode partitionMode)
        {
            // Get the list of all vote partitions, built according to current preferences.
            // One of: By line, By block, or By post (ie: entire vote)
            List <string> votePartitions = GetVotePartitions(post.WorkingVote, partitionMode, VoteType.Vote, post.Author);

            VoteCounter.AddVotes(votePartitions, post.Author, post.ID, VoteType.Vote);
        }
Beispiel #6
0
        /// <summary>
        /// Adds a merge record.
        /// </summary>
        /// <param name="fromRecord">The original vote string.</param>
        /// <param name="toRecord">The revised vote string.</param>
        /// <param name="partitionMode">The partition mode.</param>
        public void AddMergeRecord(VoteLineBlock fromRecord, List <VoteLineBlock> toRecords,
                                   UndoActionType actionType, PartitionMode partitionMode)
        {
            var merges = GetMergesFor(partitionMode);

            MergeData data = new MergeData(fromRecord, toRecords, actionType);

            merges.Add(data);
        }
Beispiel #7
0
        /// <summary>
        /// Gets the merges for the specified partition mode.
        /// </summary>
        /// <param name="partitionMode">The partition mode.</param>
        /// <returns>Returns the lookup dictionary for the specifed partition mode.</returns>
        private Dictionary <string, string> GetMergesFor(PartitionMode partitionMode)
        {
            if (!MergeLookup.TryGetValue(partitionMode, out Dictionary <string, string> merges))
            {
                merges = new Dictionary <string, string>();
                MergeLookup.Add(partitionMode, merges);
            }

            return(merges);
        }
Beispiel #8
0
        /// <summary>
        /// Gets the list of merges for the specified partition mode.
        /// Creates a new list if necessary.
        /// </summary>
        /// <param name="partitionMode">The partition mode.</param>
        /// <returns>Returns the list of merges stored for the specifed partition mode.</returns>
        private List <MergeData> GetMergesFor(PartitionMode partitionMode)
        {
            if (!MergeLookup.TryGetValue(partitionMode, out var merges))
            {
                merges = new List <MergeData>();
                MergeLookup.Add(partitionMode, merges);
            }

            return(merges);
        }
Beispiel #9
0
        /// <summary>
        /// Allows partitioning a provided vote (unified vote string) using the specified partition mode.
        /// </summary>
        /// <param name="vote">The vote string.</param>
        /// <param name="quest">The quest, for filter parameters.</param>
        /// <param name="partitionMode">The partition mode to use.</param>
        /// <returns>Returns the partitioned vote as a list of strings.</returns>
        public List <string> PartitionVoteString(string vote, IQuest quest, PartitionMode partitionMode)
        {
            if (string.IsNullOrEmpty(vote))
            {
                return(new List <string>());
            }

            var voteLines = vote.GetStringLines();

            return(PartitionVoteStrings(voteLines, quest, partitionMode));
        }
        protected override void Render()
        {
            this.mainGameComponent.Subdivs       = this.Subdivs;
            this.mainGameComponent.DrawWires     = this.DrawWires;
            this.mainGameComponent.PartitionMode = this.PartitionMode;

            // Get the projection & view matrix from the camera class
            this.mainGameComponent.ViewMatrix       = this.camera.GetViewMatrix();
            this.mainGameComponent.EyePt            = this.camera.GetEyePt();
            this.mainGameComponent.ProjectionMatrix = this.camera.GetProjMatrix();

            this.mainGameComponent.Render();
        }
Beispiel #11
0
        /// <summary>
        /// Removes the most recently added merge record of the given partition mode.
        /// </summary>
        /// <param name="partitionMode">The partition mode.</param>
        public void RemoveLastMergeRecord(PartitionMode partitionMode, UndoActionType actionType)
        {
            var merges = GetMergesFor(partitionMode);

            if (merges.Count > 0)
            {
                int index = merges.FindLastIndex(a => a.UndoActionType == actionType);

                if (index >= 0)
                {
                    merges.RemoveAt(index);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Tries the get merge record for the provided vote.
        /// Will recurse through votes til it finds the last one that was modified.
        /// </summary>
        /// <param name="original">The original vote string to check for.</param>
        /// <param name="partitionMode">The partition mode.</param>
        /// <param name="result">The result of the lookup.</param>
        /// <returns></returns>
        public bool TryGetMergeRecord(string original, PartitionMode partitionMode, out string result)
        {
            result = null;

            var merges = GetMergesFor(partitionMode);

            while (merges.TryGetValue(original, out string lookupResult))
            {
                result   = lookupResult;
                original = lookupResult;
            }

            return(!string.IsNullOrEmpty(result));
        }
Beispiel #13
0
        /// <summary>
        /// Adds a merge record.
        /// </summary>
        /// <param name="original">The original vote string.</param>
        /// <param name="revised">The revised vote string.</param>
        /// <param name="partitionMode">The partition mode.</param>
        /// <exception cref="System.ArgumentNullException">
        /// original
        /// or
        /// merge
        /// </exception>
        public void AddMergeRecord(string original, string revised, PartitionMode partitionMode)
        {
            if (string.IsNullOrEmpty(original))
            {
                throw new ArgumentNullException(nameof(original));
            }
            if (string.IsNullOrEmpty(revised))
            {
                throw new ArgumentNullException(nameof(revised));
            }

            var merges = GetMergesFor(partitionMode);

            merges[original] = revised;
        }
Beispiel #14
0
        /// <summary>
        /// Vote lines grouped into blocks.
        /// </summary>
        public List <VoteLines> GetComponents(PartitionMode partitionMode)
        {
            List <VoteLines> bigList = new List <VoteLines>();

            var voteGrouping = GetVoteMarkerGroups();

            if (partitionMode == PartitionMode.ByLine)
            {
                var transfer = voteGrouping.Select(a => CommuteLines(a));

                bigList.AddRange(transfer.SelectMany(a => a));
            }
            else if (partitionMode == PartitionMode.ByBlock)
            {
                bigList.AddRange(voteGrouping.Select(g => new VoteLines(g)));
            }


            return(bigList);
        }
Beispiel #15
0
        /// <summary>
        /// Tries the get merge record for the provided vote.
        /// Will recurse through votes til it finds the last one that was modified.
        /// </summary>
        /// <param name="original">The original vote string to check for.</param>
        /// <param name="partitionMode">The partition mode.</param>
        /// <param name="result">The result of the lookup.</param>
        /// <returns>Returns true if the record was found, and false if not.</returns>
        public IReadOnlyList <MergeData> GetMergeRecordList(PartitionMode partitionMode)
        {
            var merges = GetMergesFor(partitionMode);

            return(merges);
        }
Beispiel #16
0
        /// <summary>
        /// Get the partitions of a ranked vote.
        /// </summary>
        /// <param name="lines">The lines of a ranked vote.</param>
        /// <param name="partitionMode">The partition mode being used.</param>
        /// <param name="author">The author of the post.</param>
        /// <returns>Returns the vote broken into rank partitions.</returns>
        private static List <string> GetVotePartitionsFromRank(IEnumerable <string> lines, PartitionMode partitionMode, string author)
        {
            // Ranked votes only ever have one line of content.
            // Add CRLF to the end, and return that as a list.
            var partitions = lines.Select(a => a + "\r\n");

            return(new List <string>(partitions));
        }
Beispiel #17
0
        /// <summary>
        /// Put any plans found in the grouped vote lines into the standard tracking sets,
        /// after handling any partitioning needed.
        /// </summary>
        /// <param name="plans">List of plans to be processed.</param>
        /// <param name="post">Post the plans were pulled from.</param>
        /// <param name="partitionMode">Partition mode being used.</param>
        private void ProcessPlans(IEnumerable <List <string> > plans, PostComponents post, PartitionMode partitionMode)
        {
            foreach (var plan in plans)
            {
                string planName  = VoteString.GetMarkedPlanName(plan.First());
                string cleanName = VoteString.RemoveBBCode(planName);
                cleanName = VoteString.DeUrlContent(cleanName);

                if (!VoteCounter.HasPlan(cleanName))
                {
                    var nPlan = NormalizePlanName(plan);

                    // Get the list of all vote partitions, built according to current preferences.
                    // One of: By line, By block, or By post (ie: entire vote)
                    var votePartitions = GetVotePartitions(nPlan, partitionMode, VoteType.Plan, post.Author);

                    VoteCounter.AddVotes(votePartitions, cleanName, post.ID, VoteType.Plan);
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// Allows partitioning a provided vote (already broken into a list of lines) using the
        /// specified partition mode.
        /// </summary>
        /// <param name="voteLines">The vote lines.</param>
        /// <param name="quest">The quest, for filter parameters.</param>
        /// <param name="partitionMode">The partition mode to use.</param>
        /// <returns>Returns the partitioned vote as a list of strings.</returns>
        public List <string> PartitionVoteStrings(List <string> voteLines, IQuest quest, PartitionMode partitionMode)
        {
            if (voteLines == null)
            {
                throw new ArgumentNullException(nameof(voteLines));
            }
            if (quest == null)
            {
                throw new ArgumentNullException(nameof(quest));
            }

            if (voteLines.Count == 0)
            {
                return(new List <string>());
            }

            // Get the list of all vote partitions, built according to current preferences.
            // One of: By line, By block, or By post (ie: entire vote)
            List <string> votePartitions = GetVotePartitions(voteLines, partitionMode, VoteType.Vote, "This is a fake voter name~~~~~~~");

            var filteredPartitions = FilterVotesByTask(votePartitions, quest);

            return(filteredPartitions);
        }