
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/


/**
 * AUTO-GENERATED FILE. DO NOT MODIFY.
 */

function hours(count) {
  return count * 60 * 60 * 1000;
}
function minutes(count) {
  return count * 60 * 1000;
}
function seconds(count) {
  return count * 1000;
}
var intradayWeightDivisors = [{
  divisor: seconds(1),
  weight: 10 /* Second */
}, {
  divisor: minutes(1),
  weight: 20 /* Minute1 */
}, {
  divisor: minutes(5),
  weight: 21 /* Minute5 */
}, {
  divisor: minutes(30),
  weight: 22 /* Minute30 */
}, {
  divisor: hours(1),
  weight: 30 /* Hour1 */
}, {
  divisor: hours(3),
  weight: 31 /* Hour3 */
}, {
  divisor: hours(6),
  weight: 32 /* Hour6 */
}, {
  divisor: hours(12),
  weight: 33 /* Hour12 */
}];
// 服务端转换了本地时间 先用本地时间处理
function weightByTime(currentDate, prevDate) {
  // if (currentDate.getUTCFullYear() !== prevDate.getUTCFullYear()) {
  // 	return TickMarkWeight.Year;
  // }
  // else if (currentDate.getUTCMonth() !== prevDate.getUTCMonth()) {
  // 	return TickMarkWeight.Month;
  // }
  // else if (currentDate.getUTCDate() !== prevDate.getUTCDate()) {
  // 	return TickMarkWeight.Day;
  // }
  if (currentDate.getFullYear() !== prevDate.getFullYear()) {
    return 70 /* Year */;
  } else if (currentDate.getMonth() !== prevDate.getMonth()) {
    return 60 /* Month */;
  } else if (currentDate.getDate() !== prevDate.getDate()) {
    return 50 /* Day */;
  }

  for (var i = intradayWeightDivisors.length - 1; i >= 0; --i) {
    if (Math.floor(prevDate.getTime() / intradayWeightDivisors[i].divisor) !== Math.floor(currentDate.getTime() / intradayWeightDivisors[i].divisor)) {
      return intradayWeightDivisors[i].weight;
    }
  }
  return 0 /* LessThanSecond */;
}

export function fillWeightsForPoints(sortedTimePoints, startIndex) {
  if (startIndex === void 0) {
    startIndex = 0;
  }
  if (sortedTimePoints.length === 0) {
    return;
  }
  var prevTime = startIndex === 0 ? null : sortedTimePoints[startIndex - 1].timestamp;
  var prevDate = prevTime !== null ? new Date(prevTime * 1000) : null;
  var totalTimeDiff = 0;
  for (var index = startIndex; index < sortedTimePoints.length; ++index) {
    var currentPoint = sortedTimePoints[index];
    var currentDate = new Date(currentPoint.timestamp * 1000);
    if (prevDate !== null) {
      currentPoint.weight = weightByTime(currentDate, prevDate);
    }
    totalTimeDiff += currentPoint.timestamp - (prevTime || currentPoint.timestamp);
    prevTime = currentPoint.timestamp;
    prevDate = currentDate;
  }
  if (startIndex === 0 && sortedTimePoints.length > 1) {
    // let's guess a weight for the first point
    // let's say the previous point was average time back in the history
    var averageTimeDiff = Math.ceil(totalTimeDiff / (sortedTimePoints.length - 1));
    var approxPrevDate = new Date((sortedTimePoints[0].timestamp - averageTimeDiff) * 1000);
    sortedTimePoints[0].weight = weightByTime(new Date(sortedTimePoints[0].timestamp * 1000), approxPrevDate);
  }
}