Commit 1904365a authored by Laura Schlimmer's avatar Laura Schlimmer
Browse files

add 'rollup' to single metric view

parent a6511492
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ FnordMetric.util.MetricPreviewWidget = function(viewport, metric) {
  }

  function renderTable(table) {
    console.log(table);
    table_container.innerHTML = "";
    var table_view = FnordMetric.util.TableView(
      ["series", "x", "y"], table_container, 25);
@@ -69,6 +70,10 @@ FnordMetric.util.MetricPreviewWidget = function(viewport, metric) {
        group_btns.map(function(btn) {
          btn.className = "disabled";
        });
      } else {
        group_btns.map(function(btn) {
          btn.className = "";
        });
      }
    } else {
      tw_select.className = "";
@@ -83,7 +88,7 @@ FnordMetric.util.MetricPreviewWidget = function(viewport, metric) {
  }

  //FIXME works but seems to be ugly
  function updateEventHandler(elems) {
  function updateEventHandler(elems, columns) {
    var inputs = {
      "show" : "Value",
      "aggregation" : {
@@ -94,10 +99,10 @@ FnordMetric.util.MetricPreviewWidget = function(viewport, metric) {
        "time_to_end" : null,
        "end" : null
      },
      "group_by" : []
      "group_by" : [],
      "columns" : columns
    }

    console.log(elems.aggregation);

    elems.rollup.addEventListener('change', function() {
      inputs.show = this.value;
@@ -158,7 +163,7 @@ FnordMetric.util.MetricPreviewWidget = function(viewport, metric) {

    var rollup_select = document.createElement("select");
    rollup_group.appendChild(rollup_select);
    var rollup_options = ["Value", "Mean", "Count", "Sum"];
    var rollup_options = ["Value", "Mean", "Count", "Sum", "Rollup"];
    rollup_options.map(function(rollup) {
      var option = document.createElement("option");
      option.innerHTML = rollup;
@@ -303,7 +308,7 @@ FnordMetric.util.MetricPreviewWidget = function(viewport, metric) {
    secondary_controls.appendChild(updater_ttl);
    secondary_controls.appendChild(next_timespan);

    updateEventHandler(elems);
    updateEventHandler(elems, columns);

    var end_time = FnordMetric.util.humanDateToMikroTS(
      datepicker.value);
+22 −15
Original line number Diff line number Diff line
@@ -397,7 +397,8 @@ FnordMetric.util.toMilliSeconds = function(timestr) {
      "start" : null,
      "end" : null
    }
    "group_by" : []
    "group_by" : [],
    "columns" : [all possible group by columns]
  }
*/
FnordMetric.util.createQuery = function(inputs, metric) {
@@ -409,13 +410,25 @@ FnordMetric.util.createQuery = function(inputs, metric) {
  var select = "SELECT time AS x, ";
  var from = " FROM `" + metric + "`";
  var show;
  var group_by = "";
  var hasAggr;
  var hasTimeWindow;

  if (inputs.show == "Value") {
    show = "value as y";
    hasTimeWindow = false;
    hasAggr = false;
  } else if (inputs.show == "Rollup") {
    draw = "DRAW BARCHART AXIS BOTTOM AXIS LEFT; ";
    var column = (inputs.group_by.length > 0) ?
      inputs.group_by[0] : inputs.columns[0];
    select = "SELECT "+ column + " AS x, ";
    show = "sum(value) as y";
    hasAggr = true;
    hasTimeWindow = false;
  } else {
    hasAggr = true;
    hasTimeWindow = true;
    show = ((inputs.show).toLowerCase() + "(value) as y");
  }

@@ -440,27 +453,21 @@ FnordMetric.util.createQuery = function(inputs, metric) {
  //query += where;

  if (hasAggr) {
    /* group over timewindow needs a time and step info */
    if (inputs.aggregation.time != null &&
        inputs.aggregation.step != null) {
    var columns = (inputs.group_by.length > 0) ?
      inputs.group_by.join(", ") : inputs.columns[0];
    if (hasTimeWindow) {
      timewindow = 
        " GROUP OVER TIMEWINDOW(time, " +
        inputs.aggregation.time + ", " +
        inputs.aggregation.step + ")";

      query += timewindow;
    }

    if (inputs.group_by.length > 0) {
      var columns = inputs.group_by.join(", ");
      if (timewindow != null) {
      /* Group over timewindow clause */
        query += " BY " + columns;
      group_by = " BY " + columns;
    } else {
    /* GROUP BY */
        query += " GROUP BY " + columns;
      }
      group_by = " GROUP BY " + columns;
    }
    query += group_by;
  }

  query += ";";