/// <summary> /// Author: Nathali Aguayo /// Description: This program was created to solve the "Day 2: Inventory Management System" challenge. /// </summary> /// <param name="boxIDs"></param> /// <returns>Repetitions</returns> public Repetitions Checksum(String[] boxIDs) { Repetitions repetitions = new Repetitions(); for (int boxId = 0; boxId < boxIDs.Length; boxId++) { var idSummary = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase); for (int id = 0; id < boxIDs[boxId].Length; id++) { var character = boxIDs[boxId][id].ToString(); if (idSummary.ContainsKey(character)) //if is duplicate { idSummary[character]++; } else { idSummary.Add(character, 1); } } if (idSummary.ContainsValue(2))// if appears exactly twice { repetitions.idWithTwo += 1; } if (idSummary.ContainsValue(3))// if appears exactly three times { repetitions.idWithThree += 1; } } return(repetitions); }
//Methods /// <summary> /// Checks consistency /// </summary> protected override void Check() { if (TestDataRatio <= 0 || TestDataRatio > MaxTestDataRatio) { throw new ArgumentException($"Invalid TestDataRatio {TestDataRatio.ToString(CultureInfo.InvariantCulture)}. TestDataRatio must be GT 0 and GE {MaxTestDataRatio.ToString(CultureInfo.InvariantCulture)}.", "TestDataRatio"); } if (Folds < 0) { throw new ArgumentException($"Invalid Folds {Folds.ToString(CultureInfo.InvariantCulture)}. Folds must be GE to 0 (0 means Auto folds).", "Folds"); } if (Repetitions < 1) { throw new ArgumentException($"Invalid Repetitions {Repetitions.ToString(CultureInfo.InvariantCulture)}. Repetitions must be GE to 1.", "Repetitions"); } foreach (ReadoutUnitSettings rus in ReadoutUnitsCfg.ReadoutUnitCfgCollection) { if (rus.TaskCfg.NetworkCfgCollection.Count == 0) { if (DefaultNetworksCfg.GetTaskNetworksCfgs(rus.TaskCfg.Type).Count == 0) { throw new ArgumentException($"Readout unit {rus.Name} has not associated network(s) settings.", "ReadoutUnitsCfg"); } } } return; }
/// <summary> /// Generates xml element containing the settings. /// </summary> /// <param name="rootElemName">Name to be used as a name of the root element.</param> /// <param name="suppressDefaults">Specifies whether to ommit optional nodes having set default values</param> /// <returns>XElement containing the settings</returns> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); if (!suppressDefaults || !IsDefaultDensity) { rootElem.Add(new XAttribute("density", Density.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultAvgDistance) { rootElem.Add(new XAttribute("avgDistance", IsDefaultAvgDistance ? DefaultAvgDistanceCode : AvgDistance.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultAllowSelfConnection) { rootElem.Add(new XAttribute("allowSelfConnection", AllowSelfConnection.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultConstantNumOfConnections) { rootElem.Add(new XAttribute("constantNumOfConnections", ConstantNumOfConnections.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultReplaceExistingConnections) { rootElem.Add(new XAttribute("replaceExistingConnections", ReplaceExistingConnections.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultRepetitions) { rootElem.Add(new XAttribute("repetitions", Repetitions.ToString(CultureInfo.InvariantCulture))); } Validate(rootElem, XsdTypeName); return(rootElem); }
/// <inheritdoc/> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); if (!suppressDefaults || !IsDefaultRatio) { rootElem.Add(new XAttribute("ratio", Ratio.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultLDiagonalSelf) { rootElem.Add(new XAttribute("lDiagonalSelf", LDiagonalSelf.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultRDiagonalSelf) { rootElem.Add(new XAttribute("rDiagonalSelf", RDiagonalSelf.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultReplaceExistingConnections) { rootElem.Add(new XAttribute("replaceExistingConnections", ReplaceExistingConnections.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } if (!suppressDefaults || !IsDefaultRepetitions) { rootElem.Add(new XAttribute("repetitions", Repetitions.ToString(CultureInfo.InvariantCulture))); } Validate(rootElem, XsdTypeName); return(rootElem); }
//Methods /// <inheritdoc/> protected override void Check() { if (Ratio <= 0 || Ratio > 1) { throw new ArgumentException($"Invalid Ratio {Ratio.ToString(CultureInfo.InvariantCulture)}. Ratio must be GT 0 and LE to 1.", "Ratio"); } if (Repetitions < 1) { throw new ArgumentException($"Invalid Repetitions {Repetitions.ToString(CultureInfo.InvariantCulture)}. Repetitions must be GT 0.", "Repetitions"); } return; }
public override int GetHashCode() { unchecked { var hashCode = Id; hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Repetitions.GetHashCode(); hashCode = (hashCode * 397) ^ (CategoryName != null ? CategoryName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (UnitType != null ? UnitType.GetHashCode() : 0); return(hashCode); } }
private void ShowInfo() { try { Repetitions re = (Repetitions)gridView1.GetRow(gridView1.FocusedRowHandle); ShowRepetition show = new ShowRepetition(re); show.Show(); } catch (Exception) { MessageBox.Show("没有要显示的记录"); return; } }
//Methods /// <summary> /// Checks consistency /// </summary> protected override void Check() { if (Density <= 0 || Density > 1) { throw new ArgumentException($"Invalid Density {Density.ToString(CultureInfo.InvariantCulture)}. Density must be GT 0 and LE to 1.", "Density"); } if (AvgDistance < 0) { throw new ArgumentException($"Invalid AvgDistance {AvgDistance.ToString(CultureInfo.InvariantCulture)}. AvgDistance must be GE to 0.", "AvgDistance"); } if (Repetitions < 1) { throw new ArgumentException($"Invalid Repetitions {Repetitions.ToString(CultureInfo.InvariantCulture)}. Repetitions must be GT 0.", "Repetitions"); } return; }
//Methods /// <inheritdoc/> protected override void Check() { if (FoldDataRatio <= 0 || FoldDataRatio > MaxFoldDataRatio) { throw new ArgumentException($"Invalid FoldDataRatio {FoldDataRatio.ToString(CultureInfo.InvariantCulture)}. TestDataRatio must be GT 0 and GE {MaxFoldDataRatio.ToString(CultureInfo.InvariantCulture)}.", "FoldDataRatio"); } if (Folds < 0) { throw new ArgumentException($"Invalid Folds {Folds.ToString(CultureInfo.InvariantCulture)}. Folds must be GE to 0 (0 means Auto folds).", "Folds"); } if (Repetitions < 1) { throw new ArgumentException($"Invalid Repetitions {Repetitions.ToString(CultureInfo.InvariantCulture)}. Repetitions must be GE to 1.", "Repetitions"); } return; }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { Repetitions re = (Repetitions)gridView1.GetRow(gridView1.FocusedRowHandle); if (MessageBox.Show($"是否删除编号{re.ID}的记录?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } if (!VideoData.DeleteRepetition(re.ID)) { MessageBox.Show("删除记录失败"); Program.log.Error($"删除查重记录{re.ID}--失败"); return; } MessageBox.Show("删除成功"); Program.log.Info($"删除查重记录{re.ID}"); SetINfo(); }
/// <inheritdoc/> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); if (!suppressDefaults || !IsDefaultFoldDataRatio) { rootElem.Add(new XAttribute("foldDataRatio", FoldDataRatio.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultFolds) { rootElem.Add(new XAttribute("folds", Folds == DefaultFoldsNum ? DefaultFoldsString : Folds.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultRepetitions) { rootElem.Add(new XAttribute("repetitions", Repetitions.ToString(CultureInfo.InvariantCulture))); } Validate(rootElem, XsdTypeName); return(rootElem); }
/// <summary> /// Generates xml element containing the settings. /// </summary> /// <param name="rootElemName">Name to be used as a name of the root element.</param> /// <param name="suppressDefaults">Specifies whether to ommit optional nodes having set default values</param> /// <returns>XElement containing the settings</returns> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); rootElem.Add(new XAttribute("testDataRatio", TestDataRatio.ToString(CultureInfo.InvariantCulture))); if (!suppressDefaults || !IsDefaultFolds) { rootElem.Add(new XAttribute("folds", Folds == DefaultFoldsNum ? DefaultFoldsString : Folds.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultRepetitions) { rootElem.Add(new XAttribute("repetitions", Repetitions.ToString(CultureInfo.InvariantCulture))); } if (!DefaultNetworksCfg.ContainsOnlyDefaults) { rootElem.Add(DefaultNetworksCfg.GetXml(suppressDefaults)); } rootElem.Add(ReadoutUnitsCfg.GetXml(suppressDefaults)); Validate(rootElem, XsdTypeName); return(rootElem); }
public usrSupplementsCycleDosageEditor() { InitializeComponent(); foreach (DosageType dosageType in Enum.GetValues(typeof(DosageType))) { DosageTypes.Add(new ListItem <DosageType>(EnumLocalizer.Default.Translate(dosageType), dosageType)); } foreach (DosageUnit dosageUnit in Enum.GetValues(typeof(DosageUnit))) { DosageUnits.Add(new ListItem <DosageUnit>(EnumLocalizer.Default.Translate(dosageUnit), dosageUnit)); } foreach (SupplementCycleDayRepetitions repetition in Enum.GetValues(typeof(SupplementCycleDayRepetitions))) { Repetitions.Add(new ListItem <SupplementCycleDayRepetitions>(EnumLocalizer.Default.Translate(repetition), repetition)); } foreach (TimeType timeType in Enum.GetValues(typeof(TimeType))) { TimeTypes.Add(new ListItem <TimeType>(EnumLocalizer.Default.Translate(timeType), timeType)); } }
public void PerturbedTest() { const int Repetitions = 100; var rng = new Random(235711); foreach (var width in new[] { 5, 36 }) { foreach (var height in new[] { 5, 50, 150 }) { foreach (var _ in Repetitions.Range()) { var matrix = width.Range().Select(e => new int[height]).ToArray(); matrix[0][0] = rng.Next(5); foreach (var r in height.Range().Skip(1)) { matrix[0][r] = matrix[0][r - 1] + rng.Next(5); } foreach (var c in width.Range().Skip(1)) { matrix[c][0] = matrix[c - 1][0] + rng.Next(5); } foreach (var r in height.Range().Skip(1)) { foreach (var c in width.Range().Skip(1)) { matrix[c][r] = Math.Max(matrix[c - 1][r], matrix[c][r - 1]) + rng.Next(5); } } var target = matrix[rng.Next(width)][rng.Next(height)]; var index = matrix.TryFindItemInSortedMatrix(target); (index != null).AssertIsTrue(); matrix[index.Item1][index.Item2].AssertEquals(target); } } } }
private void AppendFields(ThingReference ThingReference, List <Field> Fields, ISensorReadout Request, XmlElement Value, string Prefix) { foreach (XmlAttribute Attribute in Value.Attributes) { if (string.IsNullOrEmpty(Prefix)) { this.Add(ThingReference, Fields, Attribute.Name, Attribute.Value, Request); } else { this.Add(ThingReference, Fields, this.Append(Prefix, Attribute.Name), Attribute.Value, Request); } } Dictionary <string, int> Repetitions = null; string s; foreach (XmlNode N in Value) { if (N is XmlElement ChildElement) { s = ChildElement.LocalName; if (Repetitions == null) { Repetitions = new Dictionary <string, int>(); } if (Repetitions.TryGetValue(s, out int i)) { Repetitions[s] = i - 1; } else { Repetitions[s] = 0; } } } foreach (XmlNode N in Value) { if (N is XmlElement ChildElement) { s = ChildElement.LocalName; if (Repetitions.TryGetValue(s, out int i)) { if (i < 0) { Repetitions[s] = i = 1; } else if (i > 0) { Repetitions[s] = ++i; } if (i != 0) { s += ", #" + i.ToString(); } } if (string.IsNullOrEmpty(Prefix)) { this.AppendFields(ThingReference, Fields, Request, ChildElement, s); } else { this.AppendFields(ThingReference, Fields, Request, ChildElement, Prefix + ", " + s); } } else if (N is XmlText XmlText) { if (string.IsNullOrEmpty(Prefix)) { this.Add(ThingReference, Fields, "Value", XmlText.InnerText, Request); } else { this.Add(ThingReference, Fields, Prefix, XmlText.InnerText, Request); } } } }
protected bool Equals(OutputDtoGetTraining other) { return(Repetitions.Equals(other.Repetitions) && ActivityName == other.ActivityName && TrainingDateValue.Equals(other.TrainingDateValue) && Points.Equals(other.Points)); }
public ShowRepetition(Repetitions repetitions) { InitializeComponent(); SetData(repetitions); }
//equals protected bool Equals(Training other) { return(Equals(User, other.User) && Repetitions.Equals(other.Repetitions) && Id == other.Id && Equals(Activity, other.Activity) && Equals(TrainingDate, other.TrainingDate) && Points.Equals(other.Points)); }
public void SetData(Repetitions repetitions) { returns = VideoData.GetOutResult(repetitions.ID); bindingSource1.DataSource = returns; }
protected bool Equals(OutputDtoAddActivity other) { return(Id == other.Id && Name == other.Name && Repetitions.Equals(other.Repetitions) && CategoryName == other.CategoryName && UnitType == other.UnitType); }
/// <summary> /// Converts the <see cref="Repetitions"/> to string, so code looks less clustered. /// </summary> /// <returns></returns> public string SetToString() { return(Repetitions.ToString()); }
/* * Equals */ protected bool Equals(Activity other) { return(Id == other.Id && Name == other.Name && Repetitions.Equals(other.Repetitions) && Equals(Unit, other.Unit) && Equals(Category, other.Category)); }