示例#1
0
  @Test
  public void testBasicFieldStats() {
    Field f = Data.makeColumnField("a", "label", new Object[] {"1", "2", "a", "2", null, 0});
    Field g = Data.makeColumnField("a", "label", new Object[] {100, 200, 400, 500, 600});
    Field h = Data.makeColumnField("a", "label", new Object[] {"a", "b", "c", "c"});
    Field i = Data.makeIndexingField("a", "label", 20);
    Field c = Data.makeConstantField("a", "label", 5.0, 2000);

    assertEquals(0, f.min(), 0.01);
    assertEquals(2, f.max(), 0.01);

    assertEquals(100, g.min(), 0.01);
    assertEquals(600, g.max(), 0.01);

    assertEquals(null, h.min());
    assertEquals(null, h.max());

    assertEquals(1, i.min(), 0.01);
    assertEquals(20, i.max(), 0.01);

    assertEquals(5.0, c.min(), 0.01);
    assertEquals(5.0, c.max(), 0.01);

    int[] counts = (int[]) h.property("categoryCounts");
    Assert.assertEquals(1, counts[0]);
    Assert.assertEquals(1, counts[1]);
    Assert.assertEquals(2, counts[2]);

    assertEquals(4, f.uniqueValuesCount());
    assertEquals(5, g.uniqueValuesCount());
    assertEquals(3, h.uniqueValuesCount());
    assertEquals(20, i.uniqueValuesCount());
    assertEquals(1, c.uniqueValuesCount());
  }
示例#2
0
  @Test
  public void testAutoConvertDate() {
    // Make some dates
    Date d1 = Data.asDate("1971-1-3");
    Date d2 = Data.asDate("1971-1-9");
    Date d3 = Data.asDate("1971-1-31");

    Field a = Data.makeColumnField("field", null, new Object[] {d1, d2, d3, null});
    Field b = Auto.convert(a);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(true, b.isDate());

    // Should ignore one error
    a = Data.makeColumnField("field", null, new Object[] {d1, d2, "oops", d3, null, null});
    b = Auto.convert(a);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(true, b.isDate());
    assertEquals(3, b.valid());

    a = Data.makeColumnField("field", null, new Object[] {"1971-1-3", "1971-1-12"});
    b = Auto.convert(a);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(true, b.isDate());
    assertEquals(2, b.valid());
    assertEquals(9.0, b.max() - b.min(), 0.001);

    a = Data.makeColumnField("field", null, new Object[] {1970, 1972, 1978});
    b = Auto.convert(a);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(true, b.isDate());
    assertEquals(3, b.valid());
    assertEquals(8 * 365 + 2, b.max() - b.min(), 0.001);

    a = Data.makeColumnField("field", null, new Object[] {1970, 1971.5, 1978});
    b = Auto.convert(a);
    Assert.assertEquals(true, b.isNumeric());
    Assert.assertEquals(false, b.isDate());
    assertEquals(3, b.valid());
    assertEquals(8, b.max() - b.min(), 0.001);
  }
示例#3
0
  @Test
  public void testDateScaleHoursOrLess() {
    Field a;
    double[] pad = {0, 0};

    a = Data.toDate(Data.makeColumnField("a", "label", new Object[] {"09:45:22", "09:45:24"}));
    Assert.assertEquals(
        "date : 09:45:22 09:45:24 : |09:45:22|09:45:23|09:45:24",
        asString(NumericScale.makeDateScale(a, false, pad, 5), a));

    a = Data.toDate(Data.makeColumnField("a", "label", new Object[] {"09:45:22", "09:45:54"}));
    assertEquals(0.40650462963, a.min(), 1e-9);
    assertEquals(0.406875, a.max(), 1e-9);
    Assert.assertEquals(
        "date : 09:45:22 09:45:54 : |09:45:30|09:45:40|09:45:50",
        asString(NumericScale.makeDateScale(a, false, pad, 5), a));

    a = Data.toDate(Data.makeColumnField("a", "label", new Object[] {"09:45:22", "09:45:54"}));
    Assert.assertEquals(
        "date : 09:45:20 09:46:00 : |09:45:20|09:45:30|09:45:40|09:45:50|09:46:00",
        asString(NumericScale.makeDateScale(a, true, pad, 5), a));

    a = Data.toDate(Data.makeColumnField("a", "label", new Object[] {"09:45:22", "10:01:54"}));
    Assert.assertEquals(
        "date : 09:45 10:05 : |09:45|09:50|09:55|10:00|10:05",
        asString(NumericScale.makeDateScale(a, true, pad, 5), a));

    a = Data.toDate(Data.makeColumnField("a", "label", new Object[] {"09:45:22", "12:01:54"}));
    Assert.assertEquals(
        "date : 09:30 12:30 : |09:30|10:00|10:30|11:00|11:30|12:00|12:30",
        asString(NumericScale.makeDateScale(a, true, pad, 5), a));

    a = Data.toDate(Data.makeColumnField("a", "label", new Object[] {"09:45:22", "23:01:54"}));
    Assert.assertEquals(
        "date : 09:00 00:00 : |09:00|12:00|15:00|18:00|21:00|00:00",
        asString(NumericScale.makeDateScale(a, true, pad, 5), a));
  }
示例#4
0
  @Test
  public void testDate() {
    Field a;

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 00:00:01"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(1.0 / 3600 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.second, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 00:04:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(4.0 / 60 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.minute, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 00:06:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(6.0 / 60 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.minute, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 00:45:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(45.0 / 60 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.minute, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 04:59:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(DateUnit.hour, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 05:00:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(5.0 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.hour, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 4, 1970"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(3.0, a.max(), 1e-9);
    assertEquals(DateUnit.day, a.property("dateUnit"));

    // Note that only three days are needed to get days as a unit -- this an exception to the usual
    // "5 ticks" rule
    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 2, 1970"}));
    assertEquals(1.0, a.min(), 1e-9);
    assertEquals(9.0, a.max(), 1e-9);
    assertEquals(DateUnit.day, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField("a", "label", new Object[] {"January 10, 1970", "March 2, 1970"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(60.0, a.max(), 1e-9);
    assertEquals(DateUnit.week, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "December 31, 1970"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(364.0, a.max(), 1e-9);
    assertEquals(DateUnit.quarter, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 10, 1972"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(2 * 365 + 9, a.max(), 1e-9);
    assertEquals(DateUnit.quarter, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 10, 1974"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(4 * 365 + 1 + 9, a.max(), 1e-9);
    assertEquals(DateUnit.year, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 10, 1976"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(6 * 365 + 1 + 9, a.max(), 1e-9);
    assertEquals(DateUnit.year, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 10, 2030"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(60 * 365 + 15 + 9, a.max(), 1e-9);
    assertEquals(DateUnit.decade, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.toDate(
                Data.makeColumnField("a", "label", new Object[] {"09:45:22", "09:45:24"}), null));
    assertEquals((9 + 45 / 60.0 + 22 / 3600.0) / 24.0, a.min(), 1e-9);
    assertEquals((9 + 45 / 60.0 + 24 / 3600.0) / 24.0, a.max(), 1e-9);
    assertEquals(DateUnit.second, a.property("dateUnit"));
  }