private static ContractTransactionInfo BuildContractInfo(Dictionary <string, string> lineDictionary, DateTime transactionDate) { if (null == lineDictionary || lineDictionary.Count == 0) { return(null); } int index = lineDictionary["PRODUCTID"].IndexOf('_'); if (index < 0) { return(null); } string commodity = lineDictionary["PRODUCTID"].Substring(0, index); string month = lineDictionary["DELIVERYMONTH"]; if (string.IsNullOrEmpty(month) || month.Equals("小计")) { return(null); } double open = DoubleUtility.Parse(lineDictionary["OPENPRICE"], GlobalDefinition.FormatProvider, -1); double high = DoubleUtility.Parse(lineDictionary["HIGHESTPRICE"], GlobalDefinition.FormatProvider, -1); double low = DoubleUtility.Parse(lineDictionary["LOWESTPRICE"], GlobalDefinition.FormatProvider, -1); double close = DoubleUtility.Parse(lineDictionary["CLOSEPRICE"], GlobalDefinition.FormatProvider, -1); double settle = DoubleUtility.Parse(lineDictionary["SETTLEMENTPRICE"], GlobalDefinition.FormatProvider, -1); int volume = Int32.Parse(lineDictionary["VOLUME"], NumberStyles.Any, GlobalDefinition.FormatProvider); int position = Int32.Parse(lineDictionary["OPENINTEREST"], NumberStyles.Any, GlobalDefinition.FormatProvider); return(new ContractTransactionInfo(transactionDate, "shfe", commodity, month, open, high, low, close, settle, volume, position)); }
protected bool SetDoubleProperty(double value, double epsilon, ref double property, Expression <Func <double> > fireNotifyProperty) { if (!DoubleUtility.AreClose(value, property)) { return(SetProperty(value, ref property, fireNotifyProperty)); } return(false); }
public override void Draw(DrawingContext dc) { if (!IsVisible) { return; } // // https://en.wikipedia.org/wiki/B%C3%A9zier_curve // base.Draw(dc); Vector vector = EndPoint - StartPoint; if (vector.Length > 0) { // Bezier curve defined by StartPoint, EndPoint and BendingOffset // Drawing the curve is no problem, determining the EndConnectorPoint is more difficult. Vector endApproachVector = !DoubleUtility.AreClose(0.0, BendingOffset) ? GetDirectionVectorOnCurve(EndOffset) : vector; var v1 = endApproachVector * Utils.Rotation30Matrix; var v2 = endApproachVector * Utils.RotationMin30Matrix; v1.Normalize(); v2.Normalize(); var p3 = EndConnectorPoint - v1 * ArrowLength; var p4 = EndConnectorPoint - v2 * ArrowLength; dc.DrawLine(Utils.DefaultPen, EndConnectorPoint, p3); dc.DrawLine(Utils.DefaultPen, EndConnectorPoint, p4); //// https://books.google.nl/books?id=7MtkGjIgOxkC&pg=PA135&lpg=PA135&dq=drawingcontext+drawgeometry+bezier+wpf&source=bl&ots=TApW1D5bmd&sig=vlS5sD3lPpH3OfQfTeaRa3bsLxI&hl=nl&sa=X&ved=0CFcQ6AEwBmoVChMI0qXZ4YGSyAIV5afbCh1Jfgzd#v=onepage&q=drawingcontext%20drawgeometry%20bezier%20wpf&f=false if (!DoubleUtility.AreClose(0.0, BendingOffset)) { PathGeometry geo = new PathGeometry(); PathFigure figure = new PathFigure(); figure.StartPoint = StartPoint; PolyQuadraticBezierSegment bezier = new PolyQuadraticBezierSegment(); bezier.Points.Add(BendingPoint); bezier.Points.Add(EndPoint); figure.Segments.Add(bezier); geo.Figures.Add(figure); dc.DrawGeometry(null, GetMainLinePen(), geo); } else { dc.DrawLine(GetMainLinePen(), StartPoint, EndPoint); } } }
public Collection <ContractTransactionInfo> GetContractList(string htmlText, DateTime transactionDate) { if (string.IsNullOrWhiteSpace(htmlText)) { return(new Collection <ContractTransactionInfo>()); } htmlParser.LoadHtml(htmlText); var table = htmlParser.DocumentNode.SelectNodes("//table[@id=\"senfe\"]"); if (null == table) { return(new Collection <ContractTransactionInfo>()); } var result = new Collection <ContractTransactionInfo>(); var rows = table.Descendants("tr").Skip(1); foreach (var row in rows) { var columns = row.Descendants("td").ToArray(); if (null == columns || columns.Count() == 0 || !Char.IsDigit(columns[0].InnerText.Last())) { continue; } int index = columns[0].InnerText.Length - 1; while (index >= 0 && Char.IsDigit(columns[0].InnerText[index])) { --index; } string commodity = columns[0].InnerText.Substring(0, index + 1); string month = columns[0].InnerText.Substring(index + 1); double open = DoubleUtility.Parse(columns[2].InnerText, GlobalDefinition.FormatProvider, -1); double high = DoubleUtility.Parse(columns[3].InnerText, GlobalDefinition.FormatProvider, -1); double low = DoubleUtility.Parse(columns[4].InnerText, GlobalDefinition.FormatProvider, -1); double close = DoubleUtility.Parse(columns[5].InnerText, GlobalDefinition.FormatProvider, -1); double settle = DoubleUtility.Parse(columns[6].InnerText, GlobalDefinition.FormatProvider, -1); int volume = Int32.Parse(columns[9].InnerText, NumberStyles.Any, GlobalDefinition.FormatProvider); int position = Int32.Parse(columns[10].InnerText, NumberStyles.Any, GlobalDefinition.FormatProvider); result.Add(new ContractTransactionInfo(transactionDate, "czce", commodity, month, open, high, low, close, settle, volume, position)); } return(result); }
private static bool AreIntersecting(Point p1, Point p2, Point p3, Point p4) { var dx12 = p2.X - p1.X; var dy12 = p2.Y - p1.Y; var dx34 = p4.X - p3.X; var dy34 = p4.Y - p3.Y; var denominator = dy12 * dx34 - dx12 * dy34; if (DoubleUtility.AreClose(denominator, 0)) { return(false); } var t1 = ((p1.X - p3.X) * dy34 + (p3.Y - p1.Y) * dx34) / denominator; var t2 = -((p3.X - p1.X) * dy12 + (p1.Y - p3.Y) * dx12) / denominator; //var intersection = new Point(p1.X + dx12*t1, p1.Y + dy12*t1); return(t1 >= 0 && t1 <= 1.0 && t2 >= 0.0 && t2 <= 1.0); }
public Collection <ContractTransactionInfo> GetContractList(string htmlText, DateTime transactionDate) { if (string.IsNullOrWhiteSpace(htmlText)) { return(new Collection <ContractTransactionInfo>()); } htmlParser.LoadHtml(htmlText); var tableContent = htmlParser.DocumentNode.SelectNodes("//table[@class=\"table\"]"); if (null == tableContent) { return(new Collection <ContractTransactionInfo>()); } var result = new Collection <ContractTransactionInfo>(); foreach (var row in tableContent.Descendants("tr").Skip(1)) { var columns = row.Descendants("td").ToArray(); if (!Char.IsDigit(columns[1].InnerText.First())) { continue; } string commodity = DceCommodityCodeHelper.GetCommodityCode(columns[0].InnerText); if (string.IsNullOrWhiteSpace(commodity)) { throw new HtmlParseException("DCE Daily Transaction Parse Error at" + transactionDate.ToString(GlobalDefinition.DateFormat, GlobalDefinition.FormatProvider)); } string month = columns[1].InnerText.Trim(); double open = DoubleUtility.Parse(columns[2].InnerText, GlobalDefinition.FormatProvider, -1); double high = DoubleUtility.Parse(columns[3].InnerText, GlobalDefinition.FormatProvider, -1); double low = DoubleUtility.Parse(columns[4].InnerText, GlobalDefinition.FormatProvider, -1); double close = DoubleUtility.Parse(columns[5].InnerText, GlobalDefinition.FormatProvider, -1); double settle = DoubleUtility.Parse(columns[7].InnerText, GlobalDefinition.FormatProvider, -1); int volume = Int32.Parse(columns[10].InnerText, NumberStyles.Any, GlobalDefinition.FormatProvider); int position = Int32.Parse(columns[11].InnerText, NumberStyles.Any, GlobalDefinition.FormatProvider); result.Add(new ContractTransactionInfo(transactionDate, "dce", commodity, month, open, high, low, close, settle, volume, position)); } return(result); }
public bool Equals(ContractTransactionInfo another) { if (null == another) { return(false); } if (this == another) { return(true); } string dateString1 = TransactionDate.ToString(GlobalDefinition.DateFormat, GlobalDefinition.FormatProvider); string dateString2 = another.TransactionDate.ToString(GlobalDefinition.DateFormat, GlobalDefinition.FormatProvider); return(dateString1.Equals(dateString2) && Commodity.Equals(another.Commodity) && DoubleUtility.Equals(OpenPrice, another.OpenPrice) && DoubleUtility.Equals(HighPrice, another.HighPrice) && DoubleUtility.Equals(LowPrice, another.LowPrice) && DoubleUtility.Equals(ClosePrice, another.ClosePrice) && DoubleUtility.Equals(SettlePrice, another.SettlePrice) && Volume == another.Volume && Position == another.Position); }
public override void Draw(DrawingContext dc) { if (!IsVisible) { return; } base.Draw(dc); // // p2 // /\ // p4 _/ \_ p5 // \ / // \/_ p3 // | // p1 // Vector v = EndPoint - StartPoint; var vn = v; vn.Normalize(); if (v.Length > 0) { // // Startpoint that lies on the edge of an UmlDiagramClass // var p1 = StartConnectorPoint; // // Endpoint that lies on the edge of an UmlDiagramClass // var p2 = EndConnectorPoint; Vector endApproachVector = !DoubleUtility.AreClose(0.0, BendingOffset) ? GetDirectionVectorOnCurve(EndOffset) : vn; var v1 = endApproachVector * Utils.Rotation30Matrix; var v2 = endApproachVector * Utils.RotationMin30Matrix; v1.Normalize(); v2.Normalize(); var p3 = p2 - 2 * endApproachVector * Math.Cos(30 * Math.PI / 180) * ArrowLength; var p4 = p2 - v1 * ArrowLength; var p5 = p2 - v2 * ArrowLength; PathGeometry geo = new PathGeometry(); PathFigure figure = new PathFigure(); figure.StartPoint = StartPoint; if (!DoubleUtility.AreClose(0.0, BendingOffset)) { PolyQuadraticBezierSegment bezier = new PolyQuadraticBezierSegment(); bezier.Points.Add(BendingPoint); bezier.Points.Add(EndPoint); figure.Segments.Add(bezier); } else { LineSegment lineSegment = new LineSegment(EndPoint, true); figure.Segments.Add(lineSegment); } PathGeometry geo2 = new PathGeometry(); PathFigure arrowFigure = new PathFigure(); arrowFigure.StartPoint = p2; PolyLineSegment polyLineSegment = new PolyLineSegment(new[] { p4, p3, p5, p2 }, true); arrowFigure.Segments.Add(polyLineSegment); geo.Figures.Add(figure); geo2.Figures.Add(arrowFigure); dc.DrawGeometry(null, Utils.DefaultPen, geo); dc.DrawGeometry(GetFillBrush(), Utils.DefaultPen, geo2); } }