Code iS Poetry!
Calculating density of posts/items/events etc .. over 24 hr period
This is a small function i wrote in C# to calculate the density of say twitter posts or events … it takes as a parameter a list of UNIX timestamps. It can be easily moddified to get a list of DateTime items.
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;
}
Споделете това във фейсбук и натиснете F13 и ще видите скрита страница в блога ми !
-
avioli
-
http://nsivkov.com Никола
Categories
- Google (3)
- infinity (1)
- ROFL (9)
- Shit i like! (18)
- Still Life (18)
- Uncategorized (2)
- web 3.0 (4)
- Социална медия (2)
- Wish List (2)
- Благинки (6)
- Изблици (5)
- Лични (9)
- Мисли (7)
- музика (15)
- Мюзик ланд (2)
- Опера (4)
- Пари от интернет (3)
- Програмиране (6)
- C# (3)
- Разни (22)
- Скукотрепач (16)
- Филмотека (10)
Мои неща
Tags
C# edno23 FaceBook Google hip-hop ILLMATE internet love love story in pictures manifesto Manu Chao matrix me Micro23 Music Opera pronobozo Qlimax song sotry Still Life Trapped by love Мисли Опера Песен Програмиране Скукотрепач въпроси живот лудост любов миризма музика наркотици неща нов помощ смърт смях социална мрежа усмивки училище филм хора чорапи

