added failing twitter user statistics
This commit is contained in:
parent
767b552929
commit
c91be2556c
6 changed files with 40 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BirdsiteLive.DAL.Contracts;
|
||||
using BirdsiteLive.Domain.Statistics;
|
||||
|
@ -16,7 +17,6 @@ namespace BirdsiteLive.Controllers
|
|||
private readonly ITwitterStatisticsHandler _twitterStatistics;
|
||||
private readonly IExtractionStatisticsHandler _extractionStatistics;
|
||||
|
||||
|
||||
#region Ctor
|
||||
public StatisticsController(ITwitterUserDal twitterUserDal, IFollowersDal followersDal, ITwitterStatisticsHandler twitterStatistics, IExtractionStatisticsHandler extractionStatistics)
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ namespace BirdsiteLive.Controllers
|
|||
FollowersCount = await _followersDal.GetFollowersCountAsync(),
|
||||
FailingFollowersCount = await _followersDal.GetFailingFollowersCountAsync(),
|
||||
TwitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync(),
|
||||
FailingTwitterUserCount = await _twitterUserDal.GetFailingTwitterUsersCountAsync(),
|
||||
TwitterStatistics = _twitterStatistics.GetStatistics(),
|
||||
ExtractionStatistics = _extractionStatistics.GetStatistics(),
|
||||
};
|
||||
|
|
|
@ -8,8 +8,8 @@ namespace BirdsiteLive.Models.StatisticsModels
|
|||
public int FollowersCount { get; set; }
|
||||
public int FailingFollowersCount { get; set; }
|
||||
public int TwitterUserCount { get; set; }
|
||||
public int FailingTwitterUserCount { get; set; }
|
||||
public ApiStatistics TwitterStatistics { get; set; }
|
||||
public ExtractionStatistics ExtractionStatistics { get; set; }
|
||||
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
<h4>Instance</h4>
|
||||
<ul>
|
||||
<li>Twitter Users: @Model.TwitterUserCount</li>
|
||||
<li>Failing Twitter Users: @Model.FailingTwitterUserCount</li>
|
||||
<li>Followers: @Model.FollowersCount</li>
|
||||
<li>Failing Followers: @Model.FailingFollowersCount</li>
|
||||
</ul>
|
||||
|
|
|
@ -73,6 +73,19 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<int> GetFailingTwitterUsersCountAsync()
|
||||
{
|
||||
var query = $"SELECT COUNT(*) FROM {_settings.TwitterUserTableName} WHERE fetchingErrorCount > 0";
|
||||
|
||||
using (var dbConnection = Connection)
|
||||
{
|
||||
dbConnection.Open();
|
||||
|
||||
var result = (await dbConnection.QueryAsync<int>(query)).FirstOrDefault();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<SyncTwitterUser[]> GetAllTwitterUsersAsync(int maxNumber)
|
||||
{
|
||||
var query = $"SELECT * FROM {_settings.TwitterUserTableName} ORDER BY lastSync ASC LIMIT @maxNumber";
|
||||
|
|
|
@ -16,5 +16,6 @@ namespace BirdsiteLive.DAL.Contracts
|
|||
Task DeleteTwitterUserAsync(string acct);
|
||||
Task DeleteTwitterUserAsync(int id);
|
||||
Task<int> GetTwitterUsersCountAsync();
|
||||
Task<int> GetFailingTwitterUsersCountAsync();
|
||||
}
|
||||
}
|
|
@ -301,5 +301,27 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
|||
var result = await dal.GetTwitterUsersCountAsync();
|
||||
Assert.AreEqual(10, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task CountFailingTwitterUsers()
|
||||
{
|
||||
var dal = new TwitterUserPostgresDal(_settings);
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var acct = $"myid{i}";
|
||||
var lastTweetId = 1548L;
|
||||
|
||||
await dal.CreateTwitterUserAsync(acct, lastTweetId);
|
||||
|
||||
if (i == 0 || i == 2 || i == 3)
|
||||
{
|
||||
var t = await dal.GetTwitterUserAsync(acct);
|
||||
await dal.UpdateTwitterUserAsync(t.Id ,1L,2L, 50+i*2, DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
||||
var result = await dal.GetFailingTwitterUsersCountAsync();
|
||||
Assert.AreEqual(3, result);
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue