本文整理汇总了C#中IObservable.ToPointStream方法的典型用法代码示例。如果您正苦于以下问题:C# IObservable.ToPointStream方法的具体用法?C# IObservable.ToPointStream怎么用?C# IObservable.ToPointStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IObservable
的用法示例。
在下文中一共展示了IObservable.ToPointStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessorUtilizationSustainedThreshold
/// <summary>
/// Produces output whenever the processor utilization exceeds a threshold consistently over some duration. Both the threshold
/// and duration are configurable in real-time via the UI.
/// </summary>
/// <param name="application">Application hosting the query.</param>
/// <param name="configurationSource">Real-time configuration data from UI.</param>
/// <returns>IObservable event sink for the StreamInsight query.</returns>
public static dynamic ProcessorUtilizationSustainedThreshold(
Application application,
IObservable<ThresholdConfiguration> configurationSource)
{
const string dataStreamName = "dataStream";
var dataStream = InputData.CreateProcessorTimeInput(application, streamName: dataStreamName);
// first, smooth the processor time to avoid false negatives (when we dip below threshold)
var smoothed = from win in dataStream.HoppingWindow(
TimeSpan.FromSeconds(2.0),
TimeSpan.FromSeconds(0.25),
HoppingWindowOutputPolicy.ClipToWindowEnd)
select new { Value = win.Avg(s => s.Value) };
// drive advance time settings from the data stream to the configuration stream
var ats = new AdvanceTimeSettings(
null,
new AdvanceTimeImportSettings(dataStreamName),
AdvanceTimePolicy.Adjust);
var configurationStream = configurationSource.ToPointStream(
application,
c => PointEvent.CreateInsert(DateTime.UtcNow, c),
ats,
"configurationStream");
// treat the configuration stream as a signal: the start of each event is the end
// of the previous event
configurationStream = configurationStream
.AlterEventDuration(e => TimeSpan.MaxValue)
.ClipEventDuration(configurationStream, (s, e) => true);
// join data and configuration streams
var joined = from d in dataStream
from c in configurationStream
select new { d.Value, c.Duration, c.Threshold };
// use alter lifetime to apply the requested duration
joined = joined.AlterEventDuration(e => e.Payload.Duration);
// detect when the threshold is sustained for the requested duration
var query = from win in joined.SnapshotWindow(SnapshotWindowOutputPolicy.Clip)
select new { Min = win.Min(s => s.Value), Threshold = win.Avg(s => s.Threshold) } into a
where a.Min > a.Threshold
select a;
return from p in query.ToPointObservable()
where p.EventKind == EventKind.Insert
select new { p.StartTime, p.Payload.Min };
}