Created
January 16, 2012 16:26
-
-
Save aviatrix/1621622 to your computer and use it in GitHub Desktop.
Calculating dansity of posts/items/events etc .. over 24 hr period
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
private static DateTime ConvertFromUnixTimestamp(double timestamp) | |
{ | |
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0); | |
return origin.AddSeconds(timestamp); | |
} | |
public Dictionary<int, int> CalculateDensity(List<int> timestamps) | |
{ | |
// the Key represents the hour , and the value represents the number of timestamps sent during a given hour | |
var converted = new Dictionary<int, int>(); | |
foreach (var stamp in timestamps) | |
{ | |
var hour = ConvertFromUnixTimestamp(stamp); | |
if (converted.ContainsKey(hour.Hour)) | |
{ | |
converted[hour.Hour]++; | |
} | |
else | |
{ | |
converted.Add(hour.Hour, 1); | |
} | |
} | |
return converted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment