ruby/ddl/app/controllers/metric_controller.rb
def read_datapoints
    metric = Metric.where(id: read_params[:metric_id], account_id: read_params[:account_id]).first
    unless metric
      return render status: 404, json: {error: "Unable to find metric to update with id #{update_params[:metric_id]}"}
    end

    # TODO correctly build the query.
    if read_params.has_key?(:start) && !read_params.has_key?(:end)
      datapoints = metric.datapoints.select('ts, value')
        .where('ts >= ?', read_params[:start])
    elsif !read_params.has_key?(:start) && read_params.has_key?(:end)
      datapoints = metric.datapoints.select('ts, value')
        .where('ts <= ?', read_params[:end])
    elsif !read_params.has_key?(:start) && !read_params.has_key?(:end)
      datapoints = metric.datapoints
    else
      datapoints = metric.datapoints.select('ts, value')
        .where('ts >= ?', read_params[:start])
        .where('ts <= ?', read_params[:end])
    end

    render status: 200, json: datapoints
  end
# Handles the API for creating metrics and posting data to them.
Handles the API for creating metrics and posting data to them.
Handles the API for creating metrics and posting data to them .
def read_datapoints
    metric = Metric.where(id: read_params[:metric_id], account_id: read_params[:account_id]).first
    unless metric
      return render status: 404, json: {error: "Unable to find metric to update with id #{update_params[:metric_id]}"}
    end
    if read_params.has_key?(:start) && !read_params.has_key?(:end)
      datapoints = metric.datapoints.select('ts, value')
        .where('ts >= ?', read_params[:start])
    elsif !read_params.has_key?(:start) && read_params.has_key?(:end)
      datapoints = metric.datapoints.select('ts, value')
        .where('ts <= ?', read_params[:end])
    elsif !read_params.has_key?(:start) && !read_params.has_key?(:end)
      datapoints = metric.datapoints
    else
      datapoints = metric.datapoints.select('ts, value')
        .where('ts >= ?', read_params[:start])
        .where('ts <= ?', read_params[:end])
    end
    render status: 200, json: datapoints
  end
def read_datapoints metric = Metric . where ( id : read_params [ :metric_id ] , account_id : read_params [ :account_id ] ) . first unless metric return render status : 404 , json : { error : "Unable to find metric to update with id #{update_params[:metric_id]}" } end if read_params . has_key? ( :start ) && ! read_params . has_key? ( :end ) datapoints = metric . datapoints . select ( 'ts, value' ) . where ( 'ts >= ?' , read_params [ :start ] ) elsif ! read_params . has_key? ( :start ) && read_params . has_key? ( :end ) datapoints = metric . datapoints . select ( 'ts, value' ) . where ( 'ts <= ?' , read_params [ :end ] ) elsif ! read_params . has_key? ( :start ) && ! read_params . has_key? ( :end ) datapoints = metric . datapoints else datapoints = metric . datapoints . select ( 'ts, value' ) . where ( 'ts >= ?' , read_params [ :start ] ) . where ( 'ts <= ?' , read_params [ :end ] ) end render status : 200 , json : datapoints end
Handles the API for creating metrics and posting data to them.
Handles the API for creating metrics and posting data to them .
# TODO correctly build the query.