// Boston, MA 02110-1301, USA.
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
namespace OpenTween.Models
public override MyCommon.TabUsageType TabType
=> MyCommon.TabUsageType.Home;
+ public int TweetsPerHour => this.tweetsPerHour;
+
+ // 流速計測用
+ private int tweetsPerHour = 0;
+ private ConcurrentDictionary<DateTime, int> tweetsTimestamps = new ConcurrentDictionary<DateTime, int>();
+
public HomeTabModel() : this(MyCommon.DEFAULTTAB.RECENT)
{
}
public HomeTabModel(string tabName) : base(tabName)
{
}
+
+ public override void AddPostQueue(PostClass post)
+ {
+ base.AddPostQueue(post);
+ this.UpdateTimelineSpeed(post.CreatedAt);
+ }
+
+ /// <summary>
+ /// タイムラインに追加された発言件数を反映し、タイムラインの流速を更新します
+ /// </summary>
+ private void UpdateTimelineSpeed(DateTime postCreatedAt)
+ {
+ var now = DateTime.Now;
+
+ // 1 時間以上前の時刻は追加しない
+ var oneHour = TimeSpan.FromHours(1);
+ if (now - postCreatedAt > oneHour)
+ return;
+
+ this.tweetsTimestamps.AddOrUpdate(postCreatedAt, 1, (k, v) => v + 1);
+
+ var removeKeys = new List<DateTime>();
+ var tweetsInWindow = 0;
+ foreach (var pair in this.tweetsTimestamps)
+ {
+ if (now - pair.Key > oneHour)
+ removeKeys.Add(pair.Key);
+ else
+ tweetsInWindow += pair.Value;
+ }
+ Interlocked.Exchange(ref this.tweetsPerHour, tweetsInWindow);
+
+ int _;
+ foreach (var key in removeKeys)
+ this.tweetsTimestamps.TryRemove(key, out _);
+ }
}
}
//時速表示用
private List<DateTime> _postTimestamps = new List<DateTime>();
private List<DateTime> _favTimestamps = new List<DateTime>();
- private ConcurrentDictionary<DateTime, int> _tlTimestamps = new ConcurrentDictionary<DateTime, int>();
- private int _tlCount;
// 以下DrawItem関連
private SolidBrush _brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
this._statuses.SetReadHomeTab();
var addCount = this._statuses.DistributePosts();
-
- if (!this._initial)
- this.UpdateTimelineSpeed(addCount);
});
if (ct.IsCancellationRequested)
this.RefreshTimeline();
}
- /// <summary>
- /// タイムラインに追加された発言件数を反映し、タイムラインの流速を更新します
- /// </summary>
- /// <param name="addCount">直前にタイムラインに追加した発言件数</param>
- private void UpdateTimelineSpeed(int addCount)
- {
- var now = DateTime.Now;
- this._tlTimestamps.AddOrUpdate(now, addCount, (k, v) => v + addCount);
-
- var removeKeys = new List<DateTime>();
- var oneHour = TimeSpan.FromHours(1);
- var tlCount = 0;
- foreach (var pair in this._tlTimestamps)
- {
- if (now - pair.Key > oneHour)
- removeKeys.Add(pair.Key);
- else
- tlCount += pair.Value;
- }
- Interlocked.Exchange(ref this._tlCount, tlCount);
-
- int _;
- foreach (var key in removeKeys)
- this._tlTimestamps.TryRemove(key, out _);
- }
-
private Task GetReplyAsync()
{
return this.GetReplyAsync(loadMore: false);
UnreadCounter = ur;
UnreadAtCounter = urat;
- slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, _tlCount);
+ var homeTab = this._statuses.GetTabByType<HomeTabModel>();
+
+ slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, homeTab.TweetsPerHour);
if (this._cfgCommon.TimelinePeriod == 0)
{
slbl.Append(Properties.Resources.SetStatusLabelText2);
int rsltAddCount = _statuses.DistributePosts();
- this.UpdateTimelineSpeed(rsltAddCount);
-
if (this._cfgCommon.UserstreamPeriod > 0) return;
// userStreamsRefreshing が 0 (インクリメント後は1) であれば RefreshTimeline を実行