/// <summary> /// Calcul de la serie E /// </summary> /// <param name="eSerie">Série E</param> private string CalculateESerie(ESerie.ESeries eSerie) { if (ResistorValue.HasValue) { double temp = Resistor.Value; int divisions = 0; while (temp >= 10) { temp /= 10; divisions++; } ESerie serie = ESeries.Where(x => x.Name == eSerie).Single(); double closest = serie.Values.OrderBy(item => Math.Abs(temp - item)).First(); double val = closest * Math.Pow(10, divisions); double gap = ((Resistor.Value - val) / Resistor.Value) * 100; int index = 0; while (val >= 1000) { val /= 1000; ++index; } return(eSerie.ToString() + " : " + val + " " + Multiples[index].Display + " (écart : " + gap.ToString("n2") + " %)"); } return(string.Empty); }
/// <summary> /// Constructeur vide par défaut /// </summary> public MainWindowViewModel() { Multiples = Multiple.GetMultiples(); Tolerances = Tolerance.GetTolerances(); TemperatureCoefficients = TemperatureCoefficient.GetTemperatureCoefficients(); ESeries = ESerie.GetESeries(); ResistorRings = ResistorRing.GetResistorRings(); Rings1 = Ring.GetRings().Where(x => x.Digit != null).OrderBy(x => x.DigitOrder).ToList(); Rings2 = Ring.GetRings().Where(x => x.Digit != null).OrderBy(x => x.DigitOrder).ToList(); Rings3 = Ring.GetRings().Where(x => x.Digit != null).OrderBy(x => x.DigitOrder).ToList(); Rings4 = Ring.GetRings().Where(x => x.Multiplicator != null).OrderBy(x => x.MultiplicatorOrder).ToList(); Rings5 = Ring.GetRings().Where(x => x.Tolerance != null).OrderBy(x => x.ToleranceOrder).ToList(); Rings6 = Ring.GetRings().Where(x => x.TemperatureCoefficient != null).OrderBy(x => x.TemperatureCoefficientOrder).ToList(); Ring blackRing = Rings1.Where(x => x.Digit == 0).Single(); List <Ring> except = new List <Ring>() { blackRing }; SetRing5Color(Rings5.OrderBy(a => a.Tolerance.Index == 2).First()); SetRing1Color(Rings1.Except(except).ToList().OrderBy(a => Guid.NewGuid()).First()); SetRing2Color(Rings2.OrderBy(a => Guid.NewGuid()).First()); SetRing4Color(Rings4.OrderBy(a => Guid.NewGuid()).First()); }