public ReviewStatisticsRepository()
 {
     _reviewsRepository = new DBRepository.MongoRepository<ReviewData>("Reviews");
     _allTimeStatsRepository = new DBRepository.MongoRepository<UserStatisticData>("AllTimeStats");
     _rollingStatsRepository = new DBRepository.MongoRepository<UserStatisticData>("Rolling30Stats");
     _monthlyStatsRepository = new DBRepository.MongoRepository<UserStatisticData>("MonthlyStats");
 }
 public ReviewRepository()
 {
     _reviewRepository = new DBRepository.MongoRepository<ReviewData>("Reviews");
     _imagesRepository = new DBRepository.MongoRepository<ImageData>("Images");
     _reviewableRepository = new DBRepository.MongoRepository<ReviewableData>("Reviewables");
     _rr = new ReviewableRepository();
     _rsr = new ReviewStatisticsRepository();
 }
Beispiel #3
0
        protected void Button5_Click(object sender, EventArgs e)
        {
            string x = Guid.NewGuid().ToString();
            var operations = new BsonDocument[]
            {
                new BsonDocument("$match", new BsonDocument("parentReviewableId", "79ffe6e1-05f0-438a-a928-467e6119c460" )),
                //new BsonDocument("$project", new BsonDocument { { "_id", 1 }, { "words", 1 } }),
                //new BsonDocument("$unwind", "$words"),
                //new BsonDocument("$group", new BsonDocument { { "_id", new BsonDocument("tags", "$words") }, { "count", new BsonDocument("$sum", 1) } }),
                //new BsonDocument("$sort", new BsonDocument("count", 1)),
                //new BsonDocument("$limit", 5)
                //new BsonDocument("$project", new BsonDocument { { "_id", 1 }, { "type", 1 }, { "dateCreated", 1 } }),
                //new BsonDocument("$group", new BsonDocument { { "type", "$type" } }),
                //new BsonDocument("$sort", new BsonDocument { { "type", -1 }, { "dateCreated", -1 } }),
                new BsonDocument("$group", new BsonDocument { { "_id", new BsonDocument("product", "$parentName") }, { "parentId", new BsonDocument("$first", "$parentReviewableId") }, { "numReviews", new BsonDocument("$sum", 1) }, { "composite", new BsonDocument("$avg", "$rating") }}),
                //new BsonDocument("$project", new BsonDocument { { "id", 1 }, { "type", 1 }, { "dateCreated", 1 } }),
                //new BsonDocument("$sort", new BsonDocument("dateCreated", -1)),
                //new BsonDocument("$limit", 5)
            };

            DBRepository.MongoRepository<ReviewData> _reviewsRepository = new DBRepository.MongoRepository<ReviewData>("Reviews");
            DBRepository.MongoRepository<ReviewableData> _reviewablesRepository = new DBRepository.MongoRepository<ReviewableData>("Reviewables");

            var results = _reviewsRepository.Collection.Aggregate(operations);
            Label1.Text = results.ResultDocuments.ToJson();

            foreach (BsonDocument doc in results.ResultDocuments)
            {
                BsonValue val; // = new BsonObjectId(;
                doc.TryGetValue("parentId", out val);
                Guid o = Guid.Parse(val.AsString);
                ReviewableRepository rr = new ReviewableRepository();
                ReviewableData r = rr.Get(o, Guid.Empty);
                doc.TryGetValue("numReviews", out val);
                r.numReviews = val.AsInt32;
                doc.TryGetValue("composite", out val);
                r.compositRating = val.AsDouble;
                rr.Update(r, Guid.Empty, false);
            }
        }
Beispiel #4
0
 public ImageRepository()
 {
     _imageRepository = new DBRepository.MongoRepository<ImageData>("Images");
 }
Beispiel #5
0
 public UserRepository()
 {
     _userRepository = new DBRepository.MongoRepository<UserData>("Users");
 }
 public ReviewableRepository()
 {
     _reviewableRepository = new DBRepository.MongoRepository<ReviewableData>("Reviewables");
     _imagesRepository = new DBRepository.MongoRepository<ImageData>("Images");
     _reviewsRepository = new DBRepository.MongoRepository<ReviewData>("Reviews");
 }
        public void UpdateStatistics(Guid reviewableId)
        {
            //return;
            var operations = new BsonDocument[]
            {
                new BsonDocument("$match", new BsonDocument("parentReviewableId", reviewableId.ToString() )),
                new BsonDocument("$group", new BsonDocument { { "_id", new BsonDocument("product", "$parentName") }, { "parentId", new BsonDocument("$first", "$parentReviewableId") }, { "numReviews", new BsonDocument("$sum", 1) }, { "composite", new BsonDocument("$avg", "$rating") }}),

            };

            DBRepository.MongoRepository<ReviewData> _reviewsRepository = new DBRepository.MongoRepository<ReviewData>("Reviews");
            DBRepository.MongoRepository<ReviewableData> _reviewablesRepository = new DBRepository.MongoRepository<ReviewableData>("Reviewables");

            var results = _reviewsRepository.Collection.Aggregate(operations);
            if (results.ResultDocuments.Count() != 0)
            {
                BsonDocument doc = results.ResultDocuments.Take<BsonDocument>(1).First();

                BsonValue val;
                doc.TryGetValue("parentId", out val);
                Guid o = Guid.Parse(val.AsString);
                ReviewableData r = Get(o, Guid.Empty);
                doc.TryGetValue("numReviews", out val);
                r.numReviews = val.AsInt32;
                doc.TryGetValue("composite", out val);
                r.compositRating = val.AsDouble;
                Update(r, Guid.Empty, false);

            }
        }