-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from NicolasConstant/develop
0.7.0 PR
- Loading branch information
Showing
11 changed files
with
186 additions
and
27 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/BirdsiteLive.Domain/Statistics/ExtractionStatisticsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Threading; | ||
using System.Timers; | ||
|
||
namespace BirdsiteLive.Domain.Statistics | ||
{ | ||
public interface IExtractionStatisticsHandler | ||
{ | ||
void ExtractedDescription(int mentionsCount); | ||
void ExtractedStatus(int mentionsCount); | ||
ExtractionStatistics GetStatistics(); | ||
} | ||
|
||
public class ExtractionStatisticsHandler : IExtractionStatisticsHandler | ||
{ | ||
private static int _lastDescriptionMentionsExtracted; | ||
private static int _lastStatusMentionsExtracted; | ||
|
||
private static int _descriptionMentionsExtracted; | ||
private static int _statusMentionsExtracted; | ||
|
||
private static System.Timers.Timer _resetTimer; | ||
|
||
#region Ctor | ||
public ExtractionStatisticsHandler() | ||
{ | ||
if (_resetTimer == null) | ||
{ | ||
_resetTimer = new System.Timers.Timer(); | ||
_resetTimer.Elapsed += OnTimeResetEvent; | ||
_resetTimer.Interval = 24 * 60 * 60 * 1000; // 24h | ||
_resetTimer.Enabled = true; | ||
} | ||
} | ||
#endregion | ||
|
||
private void OnTimeResetEvent(object sender, ElapsedEventArgs e) | ||
{ | ||
_lastDescriptionMentionsExtracted = _descriptionMentionsExtracted; | ||
_lastStatusMentionsExtracted = _statusMentionsExtracted; | ||
|
||
// Reset | ||
Interlocked.Exchange(ref _descriptionMentionsExtracted, 0); | ||
Interlocked.Exchange(ref _statusMentionsExtracted, 0); | ||
} | ||
|
||
public void ExtractedDescription(int mentionsCount) | ||
{ | ||
Interlocked.Increment(ref _descriptionMentionsExtracted); | ||
} | ||
|
||
public void ExtractedStatus(int mentionsCount) | ||
{ | ||
Interlocked.Increment(ref _statusMentionsExtracted); | ||
} | ||
|
||
public ExtractionStatistics GetStatistics() | ||
{ | ||
return new ExtractionStatistics(_descriptionMentionsExtracted, _statusMentionsExtracted, _lastDescriptionMentionsExtracted, _lastStatusMentionsExtracted); | ||
} | ||
} | ||
|
||
public class ExtractionStatistics | ||
{ | ||
#region Ctor | ||
public ExtractionStatistics(int mentionsInDescriptionsExtraction, int mentionsInStatusesExtraction, int lastMentionsInDescriptionsExtraction, int lastMentionsInStatusesExtraction) | ||
{ | ||
MentionsInDescriptionsExtraction = mentionsInDescriptionsExtraction; | ||
MentionsInStatusesExtraction = mentionsInStatusesExtraction; | ||
LastMentionsInDescriptionsExtraction = lastMentionsInDescriptionsExtraction; | ||
LastMentionsInStatusesExtraction = lastMentionsInStatusesExtraction; | ||
} | ||
#endregion | ||
|
||
public int MentionsInDescriptionsExtraction { get; } | ||
public int MentionsInStatusesExtraction { get; } | ||
|
||
public int LastMentionsInDescriptionsExtraction { get; } | ||
public int LastMentionsInStatusesExtraction { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters