MCPcopy
hub / github.com/OpenTSDB/opentsdb / scale

Method scale

src/query/expression/Scale.java:81–102  ·  view source on GitHub ↗

Multiplies each data point in the series by the scale factor, maintaining integers if both the data point and scale are integers. @param points The data points to factor @param scale_factor The factor to multiply by @return The resulting data points

(final DataPoints points, final double scale_factor)

Source from the content-addressed store, hash-verified

79 * @return The resulting data points
80 */
81 private DataPoints scale(final DataPoints points, final double scale_factor) {
82 // TODO(cl) - Using an array as the size function may not return the exact
83 // results and we should figure a way to avoid copying data anyway.
84 final List<DataPoint> dps = new ArrayList<DataPoint>();
85 final boolean scale_is_int = (scale_factor == Math.floor(scale_factor)) &&
86 !Double.isInfinite(scale_factor);
87 final SeekableView view = points.iterator();
88 while (view.hasNext()) {
89 DataPoint pt = view.next();
90 if (pt.isInteger() && scale_is_int) {
91 dps.add(MutableDataPoint.ofLongValue(pt.timestamp(),
92 (long)scale_factor * pt.longValue()));
93 } else {
94 // NaNs are fine here, they'll just be re-computed as NaN
95 dps.add(MutableDataPoint.ofDoubleValue(pt.timestamp(),
96 scale_factor * pt.toDouble()));
97 }
98 }
99 final DataPoint[] results = new DataPoint[dps.size()];
100 dps.toArray(results);
101 return new PostAggregatedDataPoints(points, results);
102 }
103
104 @Override
105 public String writeStringField(final List<String> query_params,

Callers 1

evaluateMethod · 0.95

Calls 11

hasNextMethod · 0.95
nextMethod · 0.95
isIntegerMethod · 0.95
ofLongValueMethod · 0.95
timestampMethod · 0.95
longValueMethod · 0.95
ofDoubleValueMethod · 0.95
toDoubleMethod · 0.95
iteratorMethod · 0.65
sizeMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected