コード例 #1
0
        private IEnumerable <PhotoWithCommentsAndLikes> ParsePhotosWithCommentsAndLikes(IOrderedEnumerable <Dictionary <string, AttributeValue> > sortedResult)
        {
            PhotoId latestPhotoId = Guid.Empty;
            List <PhotoWithCommentsAndLikes> result = new List <PhotoWithCommentsAndLikes>();

            PhotoWithCommentsAndLikes currentResult        = null;
            List <PhotoComment>       currentPhotoComments = null;
            List <PhotoLikeRecord>    currentPhotoLikes    = null;

            foreach (var item in sortedResult)
            {
                var    photoId    = PhotoId.FromDbValue(item[FieldMappings.PartitionKey].S);
                string recordType = item[FieldMappings.RecordType].S;


                if (latestPhotoId != photoId)
                {
                    if (currentResult != null)
                    {
                        result.Add(currentResult);
                    }

                    currentResult          = new PhotoWithCommentsAndLikes();
                    currentResult.Comments = (currentPhotoComments = new List <PhotoComment>());
                    currentResult.Likes    = (currentPhotoLikes = new List <PhotoLikeRecord>());

                    latestPhotoId = photoId;
                }

                switch (recordType.ToLowerInvariant())
                {
                case "photo":
                    currentResult.Photo = Mappers.PhotoModel.FromDbItem(item);
                    break;

                case "photocomment":
                    currentPhotoComments.Add(Mappers.PhotoComment.FromDbItem(item));
                    break;

                case "photolike":
                    currentPhotoLikes.Add(Mappers.PhotoLike.FromDbItem(item));
                    break;

                default:
                    logWriter.LogWarning($"RecordType '{recordType}' was not expected in {nameof(ParsePhotosWithCommentsAndLikes)}");
                    break;
                }
            }

            if (currentResult != null)
            {
                result.Add(currentResult);
            }

            return(result);
        }
コード例 #2
0
        private PhotoScore GetScore(PhotoWithCommentsAndLikes item)
        {
            double photoScore = GetPhotoScore(item.Photo);

            double commentScore = GetCommentScore(item.Comments.ToArray());
            double likeScore    = GetLikeScore(item.Likes.ToArray());
            double totalScore   = photoScore + commentScore + likeScore;

            return(new PhotoScore
            {
                PhotoId = item.Photo.PhotoId,
                Score = totalScore
            });
        }
コード例 #3
0
        private double GetPhotoScore(PhotoWithCommentsAndLikes item, IList <string> decisionLog)
        {
            TimeSpan itemAge = system.Time.UtcNow - item.Photo.CreatedTime;

            var defaultPhotoScore = GetWeightedScore(itemAge, PhotoAgeWeight);

            var titleScore = !string.IsNullOrWhiteSpace(item.Photo.RawText)
                ? GetWeightedScore(itemAge, TitleWeight)
                : 0;

            decisionLog.Add($"Photo created {itemAge.GetPastTimeString()} -> score {defaultPhotoScore}");
            decisionLog.Add($"RawText is '{item.Photo.RawText}', created {itemAge.GetPastTimeString()} -> score {titleScore}");

            return(titleScore + defaultPhotoScore);
        }
コード例 #4
0
        private PhotoScore GetScore(PhotoWithCommentsAndLikes item)
        {
            List <string> decisionLog = new List <string>();

            decisionLog.Add($"Scoring for {item.Photo.PhotoId.ToDbValue()}");

            double photoScore   = GetPhotoScore(item, decisionLog);
            double commentScore = GetCommentScore(item.Comments, decisionLog);
            double likeScore    = GetLikeScore(item.Likes, decisionLog);
            double totalScore   = photoScore + commentScore + likeScore;

            decisionLog.Add($"Total score for {item.Photo.PhotoId.ToDbValue()} -> {totalScore}");
            logger.LogInformation(string.Join("\n", decisionLog));

            return(new PhotoScore
            {
                PhotoId = item.Photo.PhotoId,
                Score = totalScore
            });
        }