Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Use CompletedReviewsCount property instead + fix 0% bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticEcho committed Mar 29, 2016
1 parent 8dbd64a commit 061ad4a
Showing 1 changed file with 8 additions and 16 deletions.
Expand Up @@ -2,10 +2,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ChatExchangeDotNet;
using TCL.Extensions;
using System.Reflection;

namespace SOCVR.Chatbot.ChatbotActions.Commands.Stats
{
Expand All @@ -30,29 +28,23 @@ public override void RunAction(Message incomingChatMessage, Room chatRoom)
//get the number of reviews done today by the entire site
var sa = new CloseQueueStatsAccessor();
var stats = sa.GetOverallQueueStats();
var tracker = (UserTracking)typeof(Program).GetField("watcher", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);

var reviewsInDbToday = db.ReviewedItems
.Where(x => x.ReviewedOn.Date == DateTimeOffset.UtcNow.Date)
.ToList();
var totalReviews = tracker.WatchedUsers.Values.Sum(x => x.CompletedReviewsCount);

if (reviewsInDbToday.Count == 0)
if (totalReviews == 0)
{
chatRoom.PostReplyOrThrow(incomingChatMessage, "I don't have enough data to produce those stats.");
return;
}

var reviewerCount = reviewsInDbToday
.Select(x => x.ReviewerId)
.Distinct()
.Count();
var reviewerCount = tracker.WatchedUsers.Values.Count(x => x.CompletedReviewsCount > 0);

var reviewItemCount = reviewsInDbToday.Count;
var percentage = Math.Round(totalReviews * 1.0 / stats.ReviewsToday * 100, 2);

var percentage = Math.Round(reviewItemCount * 1.0 / stats.ReviewsToday * 100, 2);
var usersPercentage = Math.Round(reviewerCount * 100D / chatRoom.PingableUsers.Count(x => x.Reputation >= 3000));

var usersPercentage = Math.Round((double)reviewerCount / chatRoom.PingableUsers.Count(x => x.Reputation >= 3000));

var message = $"{reviewerCount} members ({usersPercentage}% of this room's able reviewers) have processed {reviewItemCount} review items today, which accounts for {percentage}% of all CV reviews today.";
var message = $"{reviewerCount} members ({usersPercentage}% of this room's able reviewers) have processed {totalReviews} review items today, which accounts for {percentage}% of all CV reviews today.";

chatRoom.PostReplyOrThrow(incomingChatMessage, message);
}
Expand Down

0 comments on commit 061ad4a

Please sign in to comment.