ruby/ddl/app/controllers/metric_controller.rb
def add_datapoint
    # Adds a new datapoint to an existing metric.
    metric = Metric.where(id: add_params[:metric_id], account_id: add_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

    datapoint = metric.datapoints.new({ts: add_params[:ts], value: add_params[:value]})
    if datapoint.save
      render status: 201, nothing: true
    else
      render status: 400, json: {error: datapoint.errors}
    end
  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 add_datapoint
    metric = Metric.where(id: add_params[:metric_id], account_id: add_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
    datapoint = metric.datapoints.new({ts: add_params[:ts], value: add_params[:value]})
    if datapoint.save
      render status: 201, nothing: true
    else
      render status: 400, json: {error: datapoint.errors}
    end
  end
def add_datapoint metric = Metric . where ( id : add_params [ :metric_id ] , account_id : add_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 datapoint = metric . datapoints . new ( { ts : add_params [ :ts ] , value : add_params [ :value ] } ) if datapoint . save render status : 201 , nothing : true else render status : 400 , json : { error : datapoint . errors } end end
Handles the API for creating metrics and posting data to them.
Handles the API for creating metrics and posting data to them .
# Adds a new datapoint to an existing metric.