本文整理汇总了C#中DataPoint类的典型用法代码示例。如果您正苦于以下问题:C# DataPoint类的具体用法?C# DataPoint怎么用?C# DataPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataPoint类属于命名空间,在下文中一共展示了DataPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetData
// Retrieve end of day price data from yahoo finance
public void GetData(string symbol, int period, int observations)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://ichart.yahoo.com/table.csv?s=" + symbol);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
DataPointCollection logReturns = new DataPointCollection();
int i = 0;
string line = sr.ReadLine();// skip first line (header)
string[] m = sr.ReadLine().Split(',');
// The # of items we need to retrieve (make sure right amount)
int j = period*4 + 1;
if (j <= observations*4+1)
{
j = ((observations * 4) + 1);
}
while (i < j)
{
string[] n = sr.ReadLine().Split(',');
double l = Convert.ToDouble(m[4]);
double k = Convert.ToDouble(n[4]);
DataPoint t = new DataPoint(Math.Log(l / k), Convert.ToDateTime(m[0]));
logReturns.Add(t);
m = n;
i++;
}
// Calculate volatilities
double annualFactor = Math.Sqrt(252);
for (i = 0; i < j / 2; ++i)
{
double vol = StandardDeviation(logReturns.GetRange(i, period)) * annualFactor;
DataPoint t = new DataPoint(vol, logReturns[i].Date);
_vols.Add(t);
}
// Calculate std-dev of all volatilities
for(i = 0; i < observations; ++i)
{
double stdDev = StandardDeviation(_vols.GetRange(i, period));
DataPoint t = new DataPoint(stdDev, _vols[i].Date);
_volStdDev.Add(t);
}
// Take subset so we can plot on graph
_vols = _vols.GetRange(0, observations);
}
示例2: PointsTest
public void PointsTest(int i, double x, double y)
{
var s = GetSpectrum();
var expected = new DataPoint(i, x, y);
var actual = s.Points.ToArray()[i];
Assert.AreEqual(expected, actual);
}
示例3: CreateChart
public static void CreateChart(string imagePath,string name, IEnumerable<BenchResult> results, Func<BenchResult,double> selector)
{
Chart chart = new Chart();
chart.Width = 500;
chart.Height = 400;
chart.Titles.Add(name);
var area = new ChartArea("Default");
chart.ChartAreas.Add(area);
var series = new Series("Default");
chart.Series.Add(series);
area.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep90;
area.AxisX.LabelStyle.TruncatedLabels = false;
area.AxisX.Interval = 1;
series.ChartType = SeriesChartType.Column;
series.IsValueShownAsLabel = true;
series.XValueType = ChartValueType.String;
series.YValueType = ChartValueType.Int32;
foreach(var r in results.OrderBy( r => selector(r)))
{
DataPoint point = new DataPoint();
point.SetValueXY(r.Serializer.Replace("Adapter",""),(int)Math.Round(selector(r)));
point.AxisLabel = r.Serializer.Replace("Adapter", "");
series.Points.Add(point);
}
chart.SaveImage(imagePath, ChartImageFormat.Png);
}
示例4: uxGamesRepeater_ItemDataBound
protected void uxGamesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
UserMeanGameScore mgs = (UserMeanGameScore)e.Item.DataItem;
//e.Item.FindControl("uxIndividualCharge");
if (Session["SessionId"] != null)
{
Guid sessionId = new Guid(Session["SessionId"].ToString());
GamesScoreWS.GameScoreService gsClient = new GamesScoreWS.GameScoreService();
IndividualGameResults igResults = gsClient.FetchIndividualGames(sessionId, mgs.GameId);
if (igResults.Success)
{
Chart createChart = (Chart)e.Item.FindControl("uxIndividualCharge");
createChart.Titles.Add(mgs.Game);
Series resultsSeries = createChart.Series["GameScores"];
foreach (t_GameResults gr in igResults.GameResultList)
{
DataPoint dp = new DataPoint();
decimal indexical = ((decimal)gr.Score / (decimal)gr.Total) * 100;
dp.SetValueXY(gr.Created.ToShortDateString(), indexical);
dp.ToolTip = string.Format("{0} out of {1} in {2} seconds", gr.Score, gr.Total, gr.TestDuration);
resultsSeries.Points.Add(dp);
}
}
}
}
示例5: Add
protected override void Add(DataPoint<decimal> dataPoint)
{
//TimeSeriesLock.EnterWriteLock();
try
{
TimeSeries.Add(dataPoint);
}
finally
{
// TimeSeriesLock.ExitWriteLock();
}
OnNewDataPoint(dataPoint);
bool haveToProcess = false;
//TimeSeriesLock.EnterReadLock();
try
{
haveToProcess = TimeSeries.Count >= _period;
}
finally
{
//TimeSeriesLock.ExitReadLock();
}
// not ideal, value can still change, but it is acceptable for the stats
if (haveToProcess)
ProcessNewValue();
}
示例6: GetPaletteEntryIndex
private int GetPaletteEntryIndex(DataPoint dp)
{
var series = (ChartSeries)dp.Presenter;
var cartesianChart = series.Chart as RadCartesianChart;
var pieChart = series.Chart as RadPieChart;
int index;
if (cartesianChart != null)
{
BarSeries barSeries = series as BarSeries;
BubbleSeries bubbleSeries = series as BubbleSeries;
if ((barSeries != null && barSeries.PaletteMode == SeriesPaletteMode.DataPoint) ||
(bubbleSeries != null && bubbleSeries.PaletteMode == SeriesPaletteMode.DataPoint))
{
index = dp.Index;
}
else
{
index = cartesianChart.Series.IndexOf((CartesianSeries)series);
}
}
else if (pieChart != null)
{
index = pieChart.Series.IndexOf((PieSeries)series);
}
else
{
index = ((RadPolarChart)series.Chart).Series.IndexOf((PolarSeries)series);
}
return index;
}
示例7: Slope
public static double Slope(DataPoint[] points)
{
double xAvg = 0, yAvg = 0;
for (int i = 0; i < points.Length; i++)
{
xAvg += points[i].temperature;
yAvg += points[i].position;
}
xAvg = xAvg / points.Length;
yAvg = yAvg / points.Length;
double v1 = 0;
double v2 = 0;
for (int i = 0; i < points.Length; i++)
{
v1 += (points[i].temperature - xAvg) * (points[i].position - yAvg);
v2 += Math.Pow(points[i].temperature - xAvg, 2);
}
double a = v1 / v2;
return a;
}
示例8: RestClient_posts_metrics
public async void RestClient_posts_metrics()
{
var metricName = GetUniqueMetricName();
var dataPoint = new DataPoint(DateTime.UtcNow.MillisecondsSinceEpoch(), 5L);
var metric = new Metric(metricName)
.AddTag("route_id", "1")
.AddDataPoint(dataPoint);
await _client.AddMetricsAsync(new[] {metric});
var query = new QueryBuilder()
.SetStart(TimeSpan.FromSeconds(5))
.AddQueryMetric(new QueryMetric(metricName));
Thread.Sleep(TimeSpan.FromSeconds(2));
var response = await _client.QueryMetricsAsync(query);
response.Queries.Should().HaveCount(1);
response.Queries[0].SampleSize.Should().Be(1);
response.Queries[0].Results.Should().HaveCount(1);
response.Queries[0].Results[0].DataPoints.Single().ShouldBeEquivalentTo(dataPoint);
}
示例9: QueryMetricsAsync_uses_sum_aggregator
public async void QueryMetricsAsync_uses_sum_aggregator()
{
var metricName = GetUniqueMetricName();
var time = DateTime.UtcNow.MillisecondsSinceEpoch();
var dataPoint = new DataPoint(time, 10L);
var dataPoint2 = new DataPoint(time + 1, 30L);
var metric = new Metric(metricName)
.AddTag("route_id", "1")
.AddDataPoint(dataPoint2)
.AddDataPoint(dataPoint);
await _client.AddMetricsAsync(new[] { metric });
var queryMetric = new QueryMetric(metricName)
.AddAggregator(new SumAggregator(1, TimeUnit.Minutes));
var query = new QueryBuilder()
.SetStart(TimeSpan.FromSeconds(10))
.AddQueryMetric(queryMetric);
Thread.Sleep(TimeSpan.FromSeconds(2));
var response = await _client.QueryMetricsAsync(query);
response.Queries.Should().HaveCount(1);
response.Queries[0].Results.Should().HaveCount(1);
response.Queries[0].Results[0].DataPoints.Single().Value.Should().Be(40L);
}
示例10: AddChartSeries
// Override the AddChartSeries method to provide the chart data
protected override void AddChartSeries()
{
ChartSeriesData = new List<Series>();
var series = new Series()
{
ChartType = SeriesChartType.Pie,
BorderWidth = 1
};
var shares = chartData.ShareData;
foreach (var share in shares)
{
var point = new DataPoint();
point.IsValueShownAsLabel = true;
point.AxisLabel = share.Name;
point.ToolTip = share.Name + " " +
share.Share.ToString("#0.##%");
if (share.Url != null)
{
point.MapAreaAttributes = "href=\"" +
share.Url + "\"";
}
point.YValues = new double[] { share.Share };
point.LabelFormat = "P1";
series.Points.Add(point);
}
ChartSeriesData.Add(series);
}
示例11: ValidMessage_ProducesValidJson
public void ValidMessage_ProducesValidJson()
{
var name = "foo";
var value = 1923;
var instance = "i-349da92";
var collectedAt = new DateTime(2012, 1, 2);
var collectedAtEpochSeconds = (long) collectedAt.Subtract(CustomMetricsMessage.EpochTime).TotalSeconds;
var dp = new DataPoint(name, value, collectedAt, instance);
var now = DateTime.UtcNow;
var msg = new CustomMetricsMessage(dp);
var json = msg.ToJson();
Assert.NotNull(json);
var deserialized = (JObject)JsonConvert.DeserializeObject(json);
Assert.Equal(CustomMetricsMessage.ProtocolVersion, deserialized["proto_version"].Value<int>());
Assert.True(deserialized["timestamp"].Value<long>() >= CustomMetricsMessage.EpochTime.Subtract(now).TotalSeconds);
var pointsArray = deserialized["data"].Value<JArray>();
Assert.NotNull(pointsArray);
Assert.Equal(1, pointsArray.Count);
var data0 = (JObject)pointsArray[0];
Assert.Equal(name, data0["name"].Value<string>());
Assert.Equal(value, data0["value"].Value<int>());
Assert.Equal(instance, data0["instance"].Value<string>());
Assert.Equal(collectedAtEpochSeconds, data0["collected_at"].Value<long>());
}
示例12: BindProductSalesChart
public void BindProductSalesChart(int year)
{
using (CartDataClassesDataContext context = new CartDataClassesDataContext())
{
var productSales = from o in context.Orders
where o.DatePlaced.Value.Year == year
group o by o.DatePlaced.Value.Month into g
orderby g.Key
select new
{
Month = g,
TopProducts = (from op in context.OrderProducts
where op.OrderDate.Value.Year == year && op.OrderDate.Value.Month == g.Key
group op by op.ProductID into opg
orderby opg.Count() descending
select new { ProductName = context.Products.Where(p => p.ProductID == opg.Key).Single().ProductName, ProductCount = opg.Count() }).Take(5)
};
foreach (var sale in productSales)
{
Series series = new Series(Enum.Parse(typeof(Month), sale.Month.FirstOrDefault().DatePlaced.Value.Month.ToString()).ToString()) { ChartType = SeriesChartType.Bubble};
foreach (var topProduct in sale.TopProducts){
DataPoint point = new DataPoint() { XValue = sale.Month.Key, YValues = new double[] { (double)topProduct.ProductCount }, Label = topProduct.ProductName };
series.Points.Add(point);
}
ProductSalesChart.Series.Add(series);
}
}
}
示例13: DataPoint
public static DataPoint operator +(DataPoint d1, DataPoint d2)
{
DataPoint temp = new DataPoint();
temp.Commits = d1.Commits + d2.Commits;
temp.AddedLines = d1.AddedLines + d2.AddedLines;
temp.DeletedLines = d1.DeletedLines + d2.DeletedLines;
return temp;
}
示例14: addPoint
public void addPoint(DataPoint point)
{
lock (this.theLock)
{
points.Add(point);
dataPoints.Add(point.AsDataObject());
}
}
示例15: DataVector
public DataVector(DataPoint pt1, DataPoint pt2)
{
xDiff = pt2.X - pt1.X;
yDiff = pt2.Y - pt1.Y;
if (xDiff != 0 || yDiff != 0)
{
isZero = false;
}
}