这是我的英文问题:
WidgetContainer
个对象。 WidgetContainer
至少有一个Widget
。 WidgetContainer
想要每天Widgets
n
次显示其中一个。Widgets
可以显示在Venues
的Widget
t
取代之前,WidgetContainer's
会显示Widget
秒。t
秒内均匀分散)以下是伪代码所代表的对象:
var WidgetContainers = [
{
DailyImpressionsRequired: 52, // should be split between Venues
Widgets: ["one", "two"],
Venues: ["here", "there"]
},
{
DailyImpressionsRequired: 20,
Widgets: ["foo"],
Venues: ["here", "there", "everywhere"]
},
{
DailyImpressionsRequired: 78,
Widgets: ["bar", "bat", "heyhey!"],
Venues: ["up", "down", "allAround"]
}
];
var SecondsInADay = 86400;
var DisplayInterval = 30; // seconds
var TotalNumverOrVenues = /*eh, some calulations...*/;
var AvailableSlots = /*eh, some calulations...*/;
var SlotsNeeded = /*eh, some calulations...*/;
我需要找到一种有效的方法来计算这些对象的均匀分布式计划。这些“对象”是linq-to-sql对象,因此一些linq建议会很好
我现在的想法是将WidgetContainers
压平为Widgets
;将DailyImpressions
除以Widgets
的数量。
如果没有多个不同的场地可以考虑,我可以轻松搞清楚。
我有一种感觉,我需要看到别人对这个问题的看法,因为我一直盯着这么久。
所以,任何帮助可能会指出我正确的方向或提供一些问题的观点,即使很明显,也会非常感激!
答案 0 :(得分:0)
基于那个地段,如果我明白了,这应该给你正确答案:
static void Main(string[] args)
{
List<WidgetContainer> data = new List<WidgetContainer>();
data.Add(new WidgetContainer {
Widgets = new List<String> {"one","two"},
Venues = new List<String>{"here","there"},
DailyImpressionsRequired=52});
data.Add(new WidgetContainer {
Widgets = new List<String> {"foo"},
Venues = new List<String>{"here","there","everywhere"},
DailyImpressionsRequired=20});
data.Add(new WidgetContainer {
Widgets = new List<String> {"bar","bat", "heyhey!"},
Venues = new List<String>{"up","down", "allAround"},
DailyImpressionsRequired=78});
var SecondsInADay = 86400;
var DisplayInterval = 30; // seconds
var TotalNumverOfVenues = data.SelectMany(x=> x.Venues).Distinct().Count();
var AvailableSlots = SecondsInADay * data.SelectMany(x=> x.Venues).Distinct().Count() / DisplayInterval ; //assuming you didn't already have the count as a variable - will re-evaluate so don't use this for real!
//var AvailableSlots = SecondsInADay * TotalNumverOfVenues / DisplayInterval ; //the better way - avoids recalculating count
var SlotsNeeded = data.Sum(x => x.DailyImpressionsRequired);
}