Ejemplo n.º 1
0
 private Action makeLineChart(Field x, Field y) {
   // If there is close to one data point per x coordinate just use lines
   if (x.numericProperty("unique") > 0.95 * x.numericProperty("validNumeric"))
     return get("line").apply(x, y);
   // Otherwise show lines and points
   return get("lineWithPoints").apply(x, y);
 }
Ejemplo n.º 2
0
 private boolean goodForWordle(Field f) {
   if (!f.preferCategorical()) return false;
   if (f.numericProperty("unique") > 100 || f.numericProperty("unique") < 7) return false;
   // Too long names are not good
   for (Object c : f.categories()) if (c.toString().length() > 20) return false;
   return true;
 }
Ejemplo n.º 3
0
  @Test
  public void testAutoConvertNumeric() {
    Field a = Data.makeColumnField("field", null, new Object[] {1, 2, 3, 4});
    Field b = Auto.convert(a);
    assertEquals(a, b);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
    Assert.assertEquals(2.5, b.numericProperty("mean"), 0.001);

    a = Data.makeColumnField("field", null, new Object[] {"1", "2", "3", "4"});
    b = Auto.convert(a);
    Assert.assertEquals(false, a == b);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
    Assert.assertEquals(2.5, b.numericProperty("mean"), 0.001);

    a = Data.makeColumnField("field", null, new Object[] {"a", "2", "3", "4"});
    b = Auto.convert(a);
    Assert.assertEquals(false, a == b);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
    Assert.assertEquals(3.0, b.numericProperty("mean"), 0.001);

    a = Data.makeColumnField("field", null, new Object[] {"a", "2", "c", "4"});
    b = Auto.convert(a);
    Assert.assertEquals(true, a == b);
    Assert.assertEquals(false, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
  }
Ejemplo n.º 4
0
  @Test
  public void testTiedValues() {
    Field f = Data.makeColumnField("a", "label", new Object[] {200, 100, 400, 500, 100});
    Field g = Data.makeColumnField("a", "label", new Object[] {200, 100, 400, 500, 600});
    Field h = Data.makeColumnField("a", "label", new Object[] {200, 100, 400, 100, 200});
    Field i = Data.makeColumnField("a", "label", new Object[] {100, 100, 100, 500, 500});
    Field j =
        Data.makeColumnField("a", "label", new Object[] {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 3, 4});

    assertEquals(100, f.numericProperty("mode"), 0.01);
    assertEquals(400, g.numericProperty("mode"), 0.01);
    assertEquals(100, h.numericProperty("mode"), 0.01);
    assertEquals(100, i.numericProperty("mode"), 0.01);
    assertEquals(3, j.numericProperty("mode"), 0.01);
  }
Ejemplo n.º 5
0
  @Test
  public void testProperties() {
    Field f = Data.makeColumnField("a", "label", new Object[0]);
    assertEquals(null, f.property("xyz"));
    f.set("xyz", "12");
    assertEquals("12", f.stringProperty("xyz"));
    assertEquals(12.00001, f.numericProperty("xyz"), 0.001);

    f.set("abc", false);
    assertEquals(Boolean.FALSE, f.property("abc"));
    f.set("abc", true);
    assertEquals(Boolean.TRUE, f.property("abc"));
  }
Ejemplo n.º 6
0
  @Test
  public void testFieldStats() {
    Field uniform = Data.makeColumnField("a", "label", new Object[] {100, 200, 300, 400, 500, 600});
    Field uniformWithMissing =
        Data.makeColumnField("a", "label", new Object[] {100, 200, null, 300, "a", 400, 500, 600});
    Field peak = Data.makeColumnField("b", "label", new Object[] {1, 2, 2, 2, 2, 2, 2, 3});
    Field skew = Data.makeColumnField("c", "label", new Object[] {1, 1, 1, 1, 1, 2, 2, 2, 5, 10});
    Field a =
        Data.makeColumnField("f", "label", new Object[] {0, 1, 1, 1, 1, 2, 2, 2, 5, 10, 100, 1000});
    Field b = Data.makeColumnField("f", "label", new Object[] {10, 20, 30, 40, 22, 50, 60});

    uniform = uniform.dropData();
    uniformWithMissing = uniformWithMissing.dropData();
    peak = peak.dropData();
    skew = skew.dropData();
    a = a.dropData();
    b = b.dropData();

    // Basics
    assertEquals(6, uniform.rowCount());
    assertEquals(8, uniformWithMissing.rowCount());

    assertEquals(350, uniform.numericProperty("median"), 0.01);
    assertEquals(350, uniformWithMissing.numericProperty("median"), 0.01);
    assertEquals(2, peak.numericProperty("median"), 0.01);
    assertEquals(1.5, skew.numericProperty("median"), 0.01);
    assertEquals(2, a.numericProperty("median"), 0.01);
    assertEquals(30, b.numericProperty("median"), 0.01);

    assertEquals(200, uniform.numericProperty("q1"), 0.01);
    assertEquals(200, uniformWithMissing.numericProperty("q1"), 0.01);
    assertEquals(2, peak.numericProperty("q1"), 0.01);
    assertEquals(1, skew.numericProperty("q1"), 0.01);
    assertEquals(1, a.numericProperty("q1"), 0.01);
    assertEquals(21, b.numericProperty("q1"), 0.01);

    assertEquals(500, uniform.numericProperty("q3"), 0.01);
    assertEquals(500, uniformWithMissing.numericProperty("q3"), 0.01);
    assertEquals(2, peak.numericProperty("q3"), 0.01);
    assertEquals(2, skew.numericProperty("q3"), 0.01);
    assertEquals(7.5, a.numericProperty("q3"), 0.01);
    assertEquals(45, b.numericProperty("q3"), 0.01);

    assertEquals(100, uniform.numericProperty("granularity"), 0.01);
    assertEquals(100, uniformWithMissing.numericProperty("granularity"), 0.01);
    assertEquals(1, peak.numericProperty("granularity"), 0.01);
    assertEquals(1, skew.numericProperty("granularity"), 0.01);
    assertEquals(1, a.numericProperty("granularity"), 0.01);
    assertEquals(2, b.numericProperty("granularity"), 0.01);
  }
Ejemplo n.º 7
0
  @Test
  public void testMomentFieldStats() {
    Field uniform = Data.makeColumnField("a", "label", new Object[] {100, 200, 300, 400, 500, 600});
    Field uniformWithMissing =
        Data.makeColumnField("a", "label", new Object[] {100, 200, null, 300, "a", 400, 500, 600});
    Field peak = Data.makeColumnField("b", "label", new Object[] {1, 2, 2, 2, 2, 2, 2, 3});
    Field skew = Data.makeColumnField("c", "label", new Object[] {1, 1, 1, 1, 1, 2, 2, 2, 5, 10});

    assertEquals(350, uniform.numericProperty("mean"), 0.01);
    assertEquals(350, uniformWithMissing.numericProperty("mean"), 0.01);
    assertEquals(2, peak.numericProperty("mean"), 0.01);
    assertEquals(2.6, skew.numericProperty("mean"), 0.01);

    assertEquals(187.08, uniform.numericProperty("stddev"), 0.01);
    assertEquals(187.08, uniformWithMissing.numericProperty("stddev"), 0.01);
    assertEquals(0.534, peak.numericProperty("stddev"), 0.01);
    assertEquals(2.875, skew.numericProperty("stddev"), 0.01);

    assertEquals(0, uniform.numericProperty("skew"), 0.01);
    assertEquals(0, uniformWithMissing.numericProperty("skew"), 0.01);
    assertEquals(0, peak.numericProperty("skew"), 0.01);
    assertEquals(1.86, skew.numericProperty("skew"), 0.01);

    assertEquals(-1.557, uniform.numericProperty("kurtosis"), 0.01);
    assertEquals(-1.557, uniformWithMissing.numericProperty("kurtosis"), 0.01);
    assertEquals(0.5, peak.numericProperty("kurtosis"), 0.01);
    assertEquals(1.983, skew.numericProperty("kurtosis"), 0.01);
  }