/// <summary>
        /// This method gets the x most recent upvotes from the filled Upvote account to the author of the given post
        /// </summary>
        /// <param name="author">The author of the post</param>
        /// <param name="vars">Validation variables incl. upvote account name and various other variables to validate the post against</param>
        /// <returns>Returns the most recent upvotes and the one matching given minimum percentage criteria</returns>
        private GetAccountVotesViewModel GetLastUpvotesFromUpvoteAccountToAuthor(string author, ValidationVariables vars)
        {
            var model = new GetAccountVotesViewModel();

            model.MinPercentage = vars.MinPercentageUpvoteFromUpvoteAccount;

            // get top x most recent posts containing the upvote
            var posts = _postService.GetMostRecentPostsContainingVoter(author, vars.UpvoteAccount, ConfigurationHelper.RetrieveUpvoteAccountVoteCount);

            if (posts != null && posts.Any())
            {
                // map results to our FindVotesItemModel
                foreach (var p in posts)
                {
                    var pm = DiscussionMapper.ToFindVotesItemModel(p, vars.UpvoteAccount);
                    model.LastVotes.Add(pm);
                }

                // get timestamp details of most recent highest upvote
                // this is not stored in hivemind, so we need to make a call to Steem API
                if (model.MostRecentUpvote != null)
                {
                    // get vote details from Steem API's because hivemind doesn't contain detailed vote data
                    var lastUpdate = GetVoteDateOfMostRecentUpvote(author, model.MostRecentUpvote.permlink, vars.UpvoteAccount);
                    if (lastUpdate.HasValue)
                    {
                        model.MostRecentUpvote.last_update = lastUpdate.Value;
                    }
                }
            }

            return(model);
        }
Esempio n. 2
0
        public static ValidationItemViewModel ValidateMinDaysSinceLastUpvoteFromUpvoteAccount(string author, GetAccountVotesViewModel model, ValidationVariables vars)
        {
            var validationItem = new ValidationItemViewModel();

            ValidationPriority   prio       = ValidationPriority.High;
            ValidationResultType resultType = ValidationResultType.Failure;

            validationItem.Title               = string.Format("Min amount of days after the last upvote from {0} to {1} >= {2} with percentage >= {3}", vars.UpvoteAccount, author, vars.MinDaysLastUpvoteFromUpvoteAccount, vars.MinPercentageUpvoteFromUpvoteAccount);
            validationItem.Priority            = prio;
            validationItem.PriorityDescription = prio.ToString();
            validationItem.OrderId             = 60;

            var dateFrom = DateTime.Now.AddDays(-vars.MinDaysLastUpvoteFromUpvoteAccount);

            if (model.MostRecentUpvote != null && model.MostRecentUpvote.last_update > dateFrom)
            {
                resultType = ValidationResultType.Failure;

                var dateDiffDays = DateTime.Now.Subtract(model.MostRecentUpvote.last_update).TotalDays;
                validationItem.ResultMessage = string.Format("Last received upvote from {0} to {1} is {2} days ago", vars.UpvoteAccount, author, dateDiffDays.ToString("N"));
            }
            else
            {
                resultType = ValidationResultType.Success;

                if (model.MostRecentUpvote != null)
                {
                    var dateDiffDays = DateTime.Now.Subtract(model.MostRecentUpvote.last_update).TotalDays;
                    validationItem.ResultMessage = string.Format("Last received upvote from {0} to {1} is {2} days ago with {3} %", vars.UpvoteAccount, author, dateDiffDays.ToString("N"), (model.MostRecentUpvote.vote_percent / 100).ToString("N"));
                }
                else
                {
                    validationItem.ResultMessage = string.Format("Author {0} never received a vote from {1}", author, vars.UpvoteAccount);
                }
            }

            validationItem.ResultType            = resultType;
            validationItem.ResultTypeDescription = resultType.ToString();

            return(validationItem);
        }