/// <summary> /// Creates a new <see cref="Insight"/> object from the specified serialized form /// </summary> /// <param name="serializedInsight">The insight DTO</param> /// <returns>A new insight containing the information specified</returns> public static Insight FromSerializedInsight(SerializedInsight serializedInsight) { var insight = new Insight( Time.UnixTimeStampToDateTime(serializedInsight.CreatedTime), new Symbol(SecurityIdentifier.Parse(serializedInsight.Symbol), serializedInsight.Ticker), TimeSpan.FromSeconds(serializedInsight.Period), serializedInsight.Type, serializedInsight.Direction, serializedInsight.Magnitude, serializedInsight.Confidence, serializedInsight.SourceModel, serializedInsight.Weight ) { Id = Guid.Parse(serializedInsight.Id), CloseTimeUtc = Time.UnixTimeStampToDateTime(serializedInsight.CloseTime), EstimatedValue = serializedInsight.EstimatedValue, ReferenceValue = serializedInsight.ReferenceValue, ReferenceValueFinal = serializedInsight.ReferenceValueFinal, GroupId = string.IsNullOrEmpty(serializedInsight.GroupId) ? (Guid?)null : Guid.Parse(serializedInsight.GroupId) }; // only set score values if non-zero or if they're the final scores if (serializedInsight.ScoreIsFinal) { insight.Score.SetScore(InsightScoreType.Magnitude, serializedInsight.ScoreMagnitude, insight.CloseTimeUtc); insight.Score.SetScore(InsightScoreType.Direction, serializedInsight.ScoreDirection, insight.CloseTimeUtc); insight.Score.Finalize(insight.CloseTimeUtc); } else { if (serializedInsight.ScoreMagnitude != 0) { insight.Score.SetScore(InsightScoreType.Magnitude, serializedInsight.ScoreMagnitude, insight.CloseTimeUtc); } if (serializedInsight.ScoreDirection != 0) { insight.Score.SetScore(InsightScoreType.Direction, serializedInsight.ScoreDirection, insight.CloseTimeUtc); } } return(insight); }
/// <summary> /// Creates a new <see cref="Insight"/> object from the specified serialized form /// </summary> /// <param name="serializedInsight">The insight DTO</param> /// <returns>A new insight containing the information specified</returns> internal static Insight FromSerializedInsight(SerializedInsight serializedInsight) { var insight = new Insight( Time.UnixTimeStampToDateTime(serializedInsight.GeneratedTime), new Symbol(SecurityIdentifier.Parse(serializedInsight.Symbol), serializedInsight.Ticker), serializedInsight.Type, serializedInsight.Direction, TimeSpan.FromSeconds(serializedInsight.Period), serializedInsight.Magnitude, serializedInsight.Confidence ) { Id = Guid.Parse(serializedInsight.Id), CloseTimeUtc = Time.UnixTimeStampToDateTime(serializedInsight.CloseTime), EstimatedValue = serializedInsight.EstimatedValue, ReferenceValue = serializedInsight.ReferenceValue }; // only set score values if non-zero or if they're the final scores if (serializedInsight.ScoreIsFinal) { insight.Score.SetScore(InsightScoreType.Magnitude, serializedInsight.ScoreMagnitude, insight.CloseTimeUtc); insight.Score.SetScore(InsightScoreType.Direction, serializedInsight.ScoreDirection, insight.CloseTimeUtc); insight.Score.Finalize(insight.CloseTimeUtc); } else { if (serializedInsight.ScoreMagnitude != 0) { insight.Score.SetScore(InsightScoreType.Magnitude, serializedInsight.ScoreMagnitude, insight.CloseTimeUtc); } if (serializedInsight.ScoreDirection != 0) { insight.Score.SetScore(InsightScoreType.Direction, serializedInsight.ScoreDirection, insight.CloseTimeUtc); } } return(insight); }