PivotData getSamplePivotData(bool diag = false) { var vals = new List <object>(); var keys = new List <uint[]>(); for (uint a = 0; a < 3; a++) { for (uint b = (diag?a:0); b < 3; b++) { for (uint c = (diag?b:0); c < 3; c++) { keys.Add(new uint[] { a, b + 3, c + 6 }); vals.Add(2); } } } var pvtState = new PivotDataState() { DimCount = 3, KeyValues = new object[] { "A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3" }, Values = vals.ToArray(), ValueKeys = keys.ToArray() }; var pvt = new PivotData(new string[] { "A", "B", "C" }, new CountAggregatorFactory(), true); pvt.SetState(pvtState); /*foreach (var v in pvt.AllValues) { * Console.WriteLine(v.Key.ToString() ); * } * Console.WriteLine("*******");*/ return(pvt); }
protected void CheckSerializerPerf(PivotData pvtData, string serializerName, Func <PivotDataState, object> serialize, Func <object, PivotDataState> deserialize) { var sw = new Stopwatch(); sw.Start(); var pvtState = pvtData.GetState(); sw.Stop(); Console.WriteLine("PivotData GetState time: {0}", sw.Elapsed); sw.Restart(); var serializedState = serialize(pvtState); sw.Stop(); Console.WriteLine("PivotDataState {0} serialize time: {1}", serializerName, sw.Elapsed); sw.Restart(); var pvtStateFromSerialized = deserialize(serializedState); sw.Stop(); Console.WriteLine("PivotDataState {0} Deserialize time: {1}", serializerName, sw.Elapsed); var pvtData3 = new PivotData(new string[] { "year", "month", "a", "i" }, new CountAggregatorFactory(), true); sw.Restart(); pvtData3.SetState(pvtStateFromSerialized); sw.Stop(); Console.WriteLine("PivotData SetState time: {0}", sw.Elapsed); Assert.Equal(pvtState.KeyValues.Length, pvtStateFromSerialized.KeyValues.Length); Assert.Equal(pvtState.ValueKeys.Length, pvtStateFromSerialized.ValueKeys.Length); Assert.Equal(pvtState.Values.Length, pvtStateFromSerialized.Values.Length); }
public void PivotData_GetState() { var testData = generateData(); var pvtData = new PivotData(new string[] { "name", "qty" }, new CountAggregatorFactory(), testData, false); var pvtState = pvtData.GetState(); var pvtData2 = new PivotData(new string[] { "name", "qty" }, new CountAggregatorFactory(), false); pvtData2.SetState(pvtState); Action <PivotData, PivotData> check = (pvt1, pvt2) => { Assert.Equal(pvt1.AllValues.Count, pvt2.AllValues.Count); Assert.Equal(pvt1[ValueKey.Empty2D].Value, pvt2[ValueKey.Empty2D].Value); foreach (var vk in pvt1.AllValues) { Assert.Equal(pvt1[vk.Key].Value, pvt2[vk.Key].Value); Assert.Equal(pvt1[vk.Key].Count, pvt2[vk.Key].Count); } }; check(pvtData, pvtData2); var jsonState = JsonConvert.SerializeObject(pvtState); //Output.WriteLine(jsonState); var pvtStateFromJson = JsonConvert.DeserializeObject <PivotDataState>(jsonState); var pvtData3 = new PivotData(new string[] { "name", "qty" }, new CountAggregatorFactory(), false); pvtData3.SetState(pvtStateFromJson); check(pvtData, pvtData3); // internal serialization var memStream = new MemoryStream(); pvtState.Serialize(memStream); memStream = new MemoryStream(memStream.ToArray()); var pvtStateFromSerialized = PivotDataState.Deserialize(memStream); var pvtData4 = new PivotData(new string[] { "name", "qty" }, new CountAggregatorFactory(), false); pvtData4.SetState(pvtStateFromSerialized); check(pvtData, pvtData4); }
public PivotData GetDataCube() { // load serialized cube from sample file (aggregation result of 'TechCrunchcontinentalUSA.csv' from CsvDemo example) var cubeFile = HttpContext.Server.MapPath("~/App_Data/TechCrunchCube.dat"); // configuration of the serialized cube var pvtData = new PivotData(new[] { "company", "category", "fundedDate", "funded_year_quarter", "round" }, new CompositeAggregatorFactory( new CountAggregatorFactory(), new SumAggregatorFactory("raisedAmt"), new AverageAggregatorFactory("raisedAmt"), new MaxAggregatorFactory("raisedAmt") ), false); using (var fs = new FileStream(cubeFile, FileMode.Open)) { var pvtState = PivotDataState.Deserialize(fs); pvtData.SetState(pvtState); } return(pvtData); }
public void PivotData_SetState() { // check set state with duplicate keys for values var pvtState = new PivotDataState() { DimCount = 2, KeyValues = new object[] { "a1", "a2", "b1", "b2" }, ValueKeys = new uint[][] { new uint[] { 0, 2 }, new uint[] { 0, 3 }, new uint[] { 1, 2 }, new uint[] { 1, 3 }, new uint[] { 0, 2 } // duplicate key! }, Values = new object[] { 1, 2, 3, 4, 5 } }; var pvtData = new PivotData(new[] { "a", "b" }, new CountAggregatorFactory()); pvtData.SetState(pvtState); Assert.Equal(6, Convert.ToInt32(pvtData["a1", "b1"].Value)); Assert.Equal(15, Convert.ToInt32(pvtData[Key.Empty, Key.Empty].Value)); }
public void Serialization_KeyEmpty() { var pivotDataState = new PivotDataState(2, new object[] { Key.Empty, "AAA" }, new uint[1][] { new uint[2] { 0, 1 }, }, new object[] { new object[] { (uint)1, 2M } } ); var memStream = new MemoryStream(); pivotDataState.Serialize(memStream); var deserializedState = PivotDataState.Deserialize(new MemoryStream(memStream.ToArray())); var pvtData = new PivotData(new[] { "a", "b" }, new SumAggregatorFactory("c")); pvtData.SetState(deserializedState); Assert.Equal(2M, pvtData[Key.Empty, "AAA"].Value); }