Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a couple bugs and add a simple test #1007

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Microsoft.InsightsGenerator/DataArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum DataType

public string[] ColumnNames { get; set; }

public string[] TransformedColumnNames { get; set; }

public DataType[] ColumnDataType { get; set; }

public object[][] Cells { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.InsightsGenerator/DataTransformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ private class ColumnInfo

public DataArray Transform(DataArray array)
{
if (array == null || array.Cells == null && array.Cells.Length > 0)
if (array == null || array.Cells == null || array.Cells.Length == 0)
{
return array;
}

array.ColumnNames = GetColumnLabels(array);
array.TransformedColumnNames = GetColumnLabels(array);
return array;
}

Expand Down Expand Up @@ -72,9 +72,9 @@ private string[] GetColumnLabels(DataArray array)
++startingIndex;
}

for (int i = startingIndex; i < stringColumns.Count; ++i)
for (int i = 0; i < stringColumns.Count - startingIndex; ++i)
{
labels[stringColumns[i].ColumnIndex] = "slicer_" + i;
labels[stringColumns[i + startingIndex].ColumnIndex] = "slicer_" + i;
}
}

Expand Down
120 changes: 116 additions & 4 deletions test/Microsoft.InsightsGenerator.UnitTests/DataTransformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,125 @@ namespace Microsoft.InsightsGenerator.UnitTests
public class DataTransformerTests
{
[Fact]
public void TransformTest()
public void Tranform_NullInput()
{
DataTransformer transformer = new DataTransformer();
DataArray array = new DataArray();
DataArray array = null;
array = transformer.Transform(array);
Assert.NotNull(array);
Assert.Null(array);
}

[Fact]
public void Tranform_TimeSlicerCount_DeduceTypes()
{
DataTransformer transformer = new DataTransformer();
object[][] cells = new object[2][];
cells[0] = new object[3] { "1/15/2020", "Redmond", 50 };
cells[1] = new object[3] { "1/25/2020", "Bellevue", 75 };

DataArray array = new DataArray()
{
ColumnNames = new string[] { "Date", "City", "Count" },
Cells = cells
};

array = transformer.Transform(array);
Assert.Equal(array.TransformedColumnNames[0], "input_t_0");
Assert.Equal(array.TransformedColumnNames[1], "slicer_0");
Assert.Equal(array.TransformedColumnNames[2], "output_0");
}

[Fact]
public void Tranform_TimeSlicerCount_ProvidedTypes()
{
DataTransformer transformer = new DataTransformer();
object[][] cells = new object[2][];
cells[0] = new object[3] { "1/15/2020", "Redmond", 50 };
cells[1] = new object[3] { "1/25/2020", "Bellevue", 75 };

DataArray array = new DataArray()
{
ColumnNames = new string[] { "Date", "City", "Count" },
ColumnDataType = new DataArray.DataType[] {
DataArray.DataType.String,
DataArray.DataType.DateTime,
DataArray.DataType.Number },
Cells = cells
};

array = transformer.Transform(array);
Assert.Equal(array.TransformedColumnNames[0], "slicer_0");
Assert.Equal(array.TransformedColumnNames[1], "input_t_0");
Assert.Equal(array.TransformedColumnNames[2], "output_0");
}

[Fact]
public void Tranform_TimeGroupSlicerCount()
{
DataTransformer transformer = new DataTransformer();
object[][] cells = new object[5][];
cells[0] = new object[4] { "1/15/2020", "Redmond", "1st Street", 50 };
cells[1] = new object[4] { "1/25/2020", "Redmond", "2nd Street", 75 };
cells[2] = new object[4] { "1/10/2020", "Bellevue", "3rd Street", 125 };
cells[3] = new object[4] { "1/13/2020", "Bellevue", "4th Street", 55 };
cells[4] = new object[4] { "1/20/2020", "Bellevue", "5th Street", 95 };

DataArray array = new DataArray()
{
ColumnNames = new string[] { "Date", "City", "Address", "Count" },
Cells = cells
};

array = transformer.Transform(array);
Assert.Equal(array.TransformedColumnNames[0], "input_t_0");
Assert.Equal(array.TransformedColumnNames[1], "input_g_0");
Assert.Equal(array.TransformedColumnNames[2], "slicer_0");
Assert.Equal(array.TransformedColumnNames[3], "output_0");
}

[Fact]
public void Tranform_TimeSlicerCountGroup()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is currently failing but describes desired behavior

{
DataTransformer transformer = new DataTransformer();
object[][] cells = new object[5][];
cells[0] = new object[4] { "1/15/2020", "1st Street", 50, "Redmond" };
cells[1] = new object[4] { "1/25/2020", "2nd Street", 75, "Redmond" };
cells[2] = new object[4] { "1/10/2020", "3rd Street", 125, "Bellevue" };
cells[3] = new object[4] { "1/13/2020", "4th Street", 55, "Bellevue" };
cells[4] = new object[4] { "1/20/2020", "5th Street", 95, "Bellevue" };

DataArray array = new DataArray()
{
ColumnNames = new string[] { "Date", "Address", "Count", "City" },
Cells = cells
};

array = transformer.Transform(array);
Assert.Equal(array.TransformedColumnNames[0], "input_t_0");
Assert.Equal(array.TransformedColumnNames[1], "slicer_0");
Assert.Equal(array.TransformedColumnNames[2], "output_0");
Assert.Equal(array.TransformedColumnNames[3], "input_g_0");
}

[Fact]
public void Tranform_TimeSlicerCountCount()
{
DataTransformer transformer = new DataTransformer();
object[][] cells = new object[2][];
cells[0] = new object[4] { "1/15/2020", "1st Street", 50, 110 };
cells[1] = new object[4] { "1/25/2020", "2nd Street", 75, 160 };

DataArray array = new DataArray()
{
ColumnNames = new string[] { "Date", "Adress", "Count1", "Count2" },
Cells = cells
};

array = transformer.Transform(array);
Assert.Equal(array.TransformedColumnNames[0], "input_t_0");
Assert.Equal(array.TransformedColumnNames[1], "slicer_0");
Assert.Equal(array.TransformedColumnNames[2], "output_0");
Assert.Equal(array.TransformedColumnNames[3], "output_1");
}
}
}