@@ -0,0 +1,2559 @@
+// This file is part of OpenTSDB.%0A// Copyright (C) 2015  The OpenTSDB Authors.%0A//%0A// This program is free software: you can redistribute it and/or modify it%0A// under the terms of the GNU Lesser General Public License as published by%0A// the Free Software Foundation, either version 2.1 of the License, or (at your%0A// option) any later version.  This program is distributed in the hope that it%0A// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty%0A// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser%0A// General Public License for more details.  You should have received a copy%0A// of the GNU Lesser General Public License along with this program.  If not,%0A// see %3Chttp://www.gnu.org/licenses/%3E.%0Apackage net.opentsdb.query.expression;%0A%0Aimport java.util.List;%0A%0Aimport net.opentsdb.core.DataPoint;%0Aimport net.opentsdb.core.DataPoints;%0Aimport net.opentsdb.core.MutableDataPoint;%0Aimport net.opentsdb.core.SeekableView;%0Aimport net.opentsdb.core.TSQuery;%0A%0Apublic class Scale implements Expression %7B%0A  @Override%0A  public DataPoints%5B%5D evaluate(TSQuery data_query, List%3CDataPoints%5B%5D%3E queryResults, List%3CString%3E params) %7B%0A    if (queryResults == null %7C%7C queryResults.isEmpty()) %7B%0A      throw new NullPointerException(%22Query results cannot be empty%22);%0A    %7D%0A%0A    if (params == null %7C%7C params.isEmpty()) %7B%0A      throw new NullPointerException(%22Scaling parameter not available%22);%0A    %7D%0A%0A    String factor = params.get(0);%0A    factor = factor.replaceAll(%22'%7C%5C%22%22, %22%22).trim();%0A    double scaleFactor = Double.parseDouble(factor);%0A%0A    DataPoints%5B%5D inputPoints = queryResults.get(0);%0A    DataPoints%5B%5D outputPoints = new DataPoints%5BinputPoints.length%5D;%0A%0A    for (int i=0; i%3CinputPoints.length; i++) %7B%0A      outputPoints%5Bi%5D = scale(inputPoints%5Bi%5D, scaleFactor);%0A    %7D%0A%0A    return outputPoints;%0A  %7D%0A%0A  protected DataPoints scale(DataPoints points, double scaleFactor) %7B%0A    int size = points.size();%0A    DataPoint%5B%5D dps = new DataPoint%5Bsize%5D;%0A%0A    SeekableView view = points.iterator();%0A    int i=0;%0A    while (view.hasNext()) %7B%0A      DataPoint pt = view.next();%0A      if (pt.isInteger()) %7B%0A        dps%5Bi%5D = MutableDataPoint.ofDoubleValue(pt.timestamp(), scaleFactor * pt.longValue());%0A      %7D else %7B%0A        dps%5Bi%5D = MutableDataPoint.ofDoubleValue(pt.timestamp(), scaleFactor * pt.doubleValue());%0A      %7D%0A      i++;%0A    %7D%0A%0A    return new PostAggregatedDataPoints(points, dps);%0A  %7D%0A%0A  @Override%0A  public String writeStringField(List%3CString%3E queryParams, String innerExpression) %7B%0A    return %22scale(%22 + innerExpression + %22)%22;%0A  %7D%0A%0A%7D%0A

Add the Scale function for multiplying each series by some factor.