Hi,
I wrote a custom ordering LINQ extension method as below but I think it can be optimized for large results.
Here is the code :
public static IEnumerable<T> OrderByAncesty<T>(this IEnumerable<T> source, Func<T, DateTime> dateSelector, Func<T, float> scoreSelector)
{
var original = source.ToList();
var maxDate = source.Max(dateSelector);
var list = from p in original
let date = dateSelector(p)
let score = scoreSelector(p)
let date1 = date.ToOADate()
let date2 = maxDate.ToOADate()
let ancesty = (1 - (float)date1 / (float)date2) * score
select new
{
TObject = p,
Ancesty = ancesty
};
return list.OrderBy(p => p.Ancesty).Select(p => p.TObject);
}