public void Increment(double value, IncrementType type) { double y, yl, yr; var valSq = value * value; switch (type) { case IncrementType.Left: NoLeft++; NoRight--; SumLeft += value; SumRight -= value; SqSumLeft += valSq; SqSumRight -= valSq; break; case IncrementType.Right: NoLeft--; NoRight++; SumLeft -= value; SumRight += value; SqSumLeft -= valSq; SqSumRight += valSq; break; case IncrementType.None: break; default: throw new ArgumentOutOfRangeException(type.ToString(), type, null); } VarLeft = NoLeft <= 0 ? 0 : Math.Abs(NoLeft * SqSumLeft - SumLeft * SumLeft) / (NoLeft * NoLeft); VarRight = NoRight <= 0 ? 0 : Math.Abs(NoRight * SqSumRight - SumRight * SumRight) / (NoRight * NoRight); if (Order <= 0) { throw new ArgumentException("Splitter order must be larger than 0"); } if (Order.IsAlmost(1)) { y = VarTotal; yl = VarLeft; yr = VarRight; } else { y = Math.Pow(VarTotal, 1.0 / Order); yl = Math.Pow(VarLeft, 1.0 / Order); yr = Math.Pow(VarRight, 1.0 / Order); } if (NoLeft <= 0.0 || NoRight <= 0.0) { Impurity = double.MinValue; //Splitter = 0; } else { Impurity = y - (NoLeft * yl + NoRight * yr) / (NoRight + NoLeft); } }
/// <summary> /// Print the object's XML to the XmlWriter. /// </summary> /// <param name="objWriter">XmlTextWriter to write with.</param> /// <param name="objCulture">Culture in which to print.</param> /// <param name="strLanguageToPrint">Language in which to print</param> public void Print(XmlTextWriter objWriter, CultureInfo objCulture, string strLanguageToPrint) { objWriter.WriteStartElement("lifestyle"); objWriter.WriteElementString("name", CustomName); objWriter.WriteElementString("cost", Cost.ToString(_objCharacter.Options.NuyenFormat, objCulture)); objWriter.WriteElementString("totalmonthlycost", TotalMonthlyCost.ToString(_objCharacter.Options.NuyenFormat, objCulture)); objWriter.WriteElementString("totalcost", TotalCost.ToString(_objCharacter.Options.NuyenFormat, objCulture)); objWriter.WriteElementString("dice", Dice.ToString(objCulture)); objWriter.WriteElementString("multiplier", Multiplier.ToString(_objCharacter.Options.NuyenFormat, objCulture)); objWriter.WriteElementString("months", Increments.ToString(objCulture)); objWriter.WriteElementString("purchased", Purchased.ToString()); objWriter.WriteElementString("type", StyleType.ToString()); objWriter.WriteElementString("increment", IncrementType.ToString()); objWriter.WriteElementString("sourceid", SourceID.ToString("D")); objWriter.WriteElementString("bonuslp", BonusLP.ToString(objCulture)); string strBaseLifestyle = string.Empty; // Retrieve the Advanced Lifestyle information if applicable. if (!string.IsNullOrEmpty(BaseLifestyle)) { XmlNode objXmlAspect = GetNode(); if (objXmlAspect != null) { strBaseLifestyle = objXmlAspect["translate"]?.InnerText ?? objXmlAspect["name"]?.InnerText ?? strBaseLifestyle; } } objWriter.WriteElementString("baselifestyle", strBaseLifestyle); objWriter.WriteElementString("trustfund", TrustFund.ToString()); objWriter.WriteElementString("source", CommonFunctions.LanguageBookShort(Source, strLanguageToPrint)); objWriter.WriteElementString("page", DisplayPage(strLanguageToPrint)); objWriter.WriteStartElement("qualities"); // Retrieve the Qualities for the Advanced Lifestyle if applicable. foreach (LifestyleQuality objQuality in LifestyleQualities) { objQuality.Print(objWriter, objCulture, strLanguageToPrint); } // Retrieve the free Grids for the Advanced Lifestyle if applicable. foreach (LifestyleQuality objQuality in FreeGrids) { objQuality.Print(objWriter, objCulture, strLanguageToPrint); } objWriter.WriteEndElement(); if (_objCharacter.Options.PrintNotes) { objWriter.WriteElementString("notes", Notes); } objWriter.WriteEndElement(); }
//increment will be other values than 1, only if the incrementType of first and second cell is same. private int FindIncrementValue(string str1, string str2, IncrementType iType) { int increment = 1; try { IncrementType incrType = CheckIncrementType(str2); int firstVal = 0; int secondVal = 0; if (iType == incrType) { switch (iType) { case IncrementType.AllInteger: firstVal = int.Parse(str1); secondVal = int.Parse(str2); increment = secondVal - firstVal; break; case IncrementType.StartInteger: firstVal = int.Parse(str1.Substring(0, FindDigitOfInteger(str1, IncrementType.StartInteger))); secondVal = int.Parse(str2.Substring(0, FindDigitOfInteger(str2, IncrementType.StartInteger))); increment = secondVal - firstVal; break; case IncrementType.EndInteger: firstVal = int.Parse(str1.Substring(str1.Length - FindDigitOfInteger(str1, IncrementType.EndInteger))); secondVal = int.Parse(str2.Substring(str2.Length - FindDigitOfInteger(str2, IncrementType.EndInteger))); increment = secondVal - firstVal; break; } } } catch (Exception ex) { MessageBox.Show("Failed find increment value with increment type: " + iType.ToString() + "\n" + ex.Message, "CellValueControl Error:", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(increment); }