public void TestAggregatingLabeledDataWithoutMapFile() { const string originalData = "Data.csv"; const string mapToLocation = "MapTo.csv"; try { // create the data that is going to be mapped using (var writer = new StreamWriter(originalData)) { writer.WriteLine("Label,Data"); for (int i = 0; i < 26; i++) { writer.Write((char)('a' + i)); writer.Write(','); writer.WriteLine(i); } } // create the data that will define the new shape using (var writer = new StreamWriter(mapToLocation)) { writer.WriteLine("Label,Data"); for (int i = 0; i < 26; i += 2) { writer.Write((char)('a' + i)); writer.Write(','); writer.WriteLine(i); } } // now that our data files have been created create the aggregation AggregateLabeledDataToShape agg = new AggregateLabeledDataToShape(); agg.DataToAggregate = new TestDataSource <LabeledData <float> >(LoadLabeledData(originalData)); agg.FitToShape = new TestDataSource <LabeledData <float> >(LoadLabeledData(mapToLocation)); agg.LoadData(); var combinedData = agg.GiveData(); agg.UnloadData(); // now test the properties Assert.AreEqual(13, combinedData.Count); Assert.AreEqual(156.00, combinedData.Sum(val => val.Value), 0.00001); } finally { File.Delete(originalData); File.Delete(mapToLocation); } }
public void TestAggregatingLabeledData() { const string originalData = "Data.csv"; const string mapToLocation = "MapTo.csv"; const string mapLocation = "Map.csv"; try { // create the data that is going to be mapped using (var writer = new StreamWriter(originalData)) { writer.WriteLine("Label,Data"); for (int i = 0; i < 26; i++) { writer.Write((char)('a' + i)); writer.Write(','); writer.WriteLine(i); } } // create the data that will define the new shape using (var writer = new StreamWriter(mapToLocation)) { writer.WriteLine("Label,Data"); for (int i = 0; i < 2; i++) { writer.Write((char)('1' + i)); writer.Write(','); writer.WriteLine(i); } } // create the mapping file using (var writer = new StreamWriter(mapLocation)) { writer.WriteLine("DestLabel,OriginLabel,Amount"); for (int i = 0; i < 26; i++) { writer.Write((char)('1' + (i / 13))); writer.Write(','); writer.Write((char)('a' + i)); writer.Write(','); writer.WriteLine(1.0f); } } // now that our data files have been created create the aggregation AggregateLabeledDataToShape agg = new AggregateLabeledDataToShape(); agg.DataMap = CreateFileLocationFromOutputDirectory(mapLocation); agg.DataToAggregate = new TestDataSource <LabeledData <float> >(LoadLabeledData(originalData)); agg.FitToShape = new TestDataSource <LabeledData <float> >(LoadLabeledData(mapToLocation)); agg.LoadData(); var combinedData = agg.GiveData(); agg.UnloadData(); // now test the properties Assert.AreEqual(2, combinedData.Count); Assert.IsTrue(combinedData.ContainsKey("1")); Assert.AreEqual(78, combinedData["1"]); Assert.IsTrue(combinedData.ContainsKey("2")); Assert.AreEqual(247, combinedData["2"]); } finally { File.Delete(originalData); File.Delete(mapToLocation); File.Delete(mapLocation); } }