Create a Statistic object in the Tracker.
182349
def track_statistic(self, name, description='', max_rows=None):
        
        if name in self._tables:
            raise TableConflictError(name)
        if max_rows is None:
            max_rows = AnonymousUsageTracker.MAX_ROWS_PER_TABLE
        self.register_table(name, self.uuid, 'Statistic', description)
        self._tables[name] = Statistic(name, self, max_rows=max_rows)
781003
function createProductTrack(track, properties) {
  properties.currency = properties.currency || track.currency();
  return new Track({ properties: properties });
}
1181846
def updateTrackerItem( self, point = None ):
        
        item = self.trackerItem()
        if not item:
            return
        
        gridRect = self._buildData.get('grid_rect')
        
        if ( not (gridRect and gridRect.isValid()) ):
            item.setVisible(False)
            return
        
        if ( point is not None ):
            item.setPos(point.x(), gridRect.top())
        
        if ( not gridRect.contains(item.pos()) ):
            item.setVisible(False)
            return
        
        if ( self.chartType() != self.Type.Line ):
            item.setVisible(False)
            return
        
        if ( not self.isTrackingEnabled() ):
            item.setVisible(False)
            return
        
        item.rebuild(gridRect)
794645
def add_stats(self, args):
        """"""
        bg_name, stats = args
        logger.debug("Stats: %s %s", bg_name, stats)
        
        for motif_id in stats.keys():
            if motif_id not in self.stats:
                self.stats[motif_id] = {}
        
            self.stats[motif_id][bg_name] = stats[motif_id]
1152073
def CreateCounterMetadata(metric_name, fields=None, docstring=None, units=None):
  """"""
  return rdf_stats.MetricMetadata(
      varname=metric_name,
      metric_type=rdf_stats.MetricMetadata.MetricType.COUNTER,
      value_type=rdf_stats.MetricMetadata.ValueType.INT,
      fields_defs=FieldDefinitionProtosFromTuples(fields or []),
      docstring=docstring,
      units=units)
13442
function (obj) {
                var t = shared.tracker.getTracker(obj);
                t.tc().disable++;
                // Loop old props to find any to delete
                var oldProps = shared.utils.cloneArray(t.type().props());
                var newProps = Object.keys(obj);
                for(var i = 0; i < oldProps.length; i++) {
                    if(!obj.hasOwnProperty(oldProps[i]) || !shared.tracker.isPropTracked(obj, oldProps[i])) {
                        t.addDelete(obj, oldProps[i]);
                    } else {
                        // Remove any old ones for next step
                        var idx = newProps.indexOf(oldProps[i]);
                        newProps[idx] = null;
                    }
                }
                // Add any new props
                for(var i = 0; i < newProps.length; i++) {
                    if(newProps[i] !== null) {
                        t.addNew(obj, newProps[i], obj[newProps[i]]);
                        t.track(obj, newProps[i]);
                    }
                }
                if(t.hasChanges()) {
                    t.uprev(obj);
                }
                t.tc().disable--;
            }
450204
function logStat(stat, value) {
  if (!statsTracker[stat]) {
    statsTracker[stat] = [];
  }
  statsTracker[stat].push(value);
  clearTimeout(statsTimer);
  statsTimer = setTimeout(printStats, 100);
}
508753
def statsId(obj):
  """"""
  if hasattr(obj, ID_KEY):
    return getattr(obj, ID_KEY)
  newId = next(NEXT_ID)
  setattr(obj, ID_KEY, newId)
  return newId
110187
function (obj) {
                shared.utils.dassert(getTracker(obj) === this);
                for(var prop in obj) {
                    if(!isPropTracked(obj, prop)) {
                        this.track(obj, prop);
                    }
                }
                this._type = shared.types.TypeStore.instance().type(obj);
            }
1007112
def update_stats(stats, start_time, data):
    '''
    
    '''
    end_time = time.time()
    cmd = data['cmd']
    # the jid is used as the create time
    try:
        jid = data['jid']
    except KeyError:
        try:
            jid = data['data']['__pub_jid']
        except KeyError:
            log.info('jid not found in data, stats not updated')
            return stats
    create_time = int(time.mktime(time.strptime(jid, '%Y%m%d%H%M%S%f')))
    latency = start_time - create_time
    duration = end_time - start_time

    stats[cmd]['runs'] += 1
    stats[cmd]['latency'] = (stats[cmd]['latency'] * (stats[cmd]['runs'] - 1) + latency) / stats[cmd]['runs']
    stats[cmd]['mean'] = (stats[cmd]['mean'] * (stats[cmd]['runs'] - 1) + duration) / stats[cmd]['runs']

    return stats
548093
function createTrackerEntity(data) {

    let result = data.data

    return new TrackerInfo({
        attempts: 1,
        id: data.gearTrackID,
        origin: result.fromCountry,
        destiny: result.destinationCountry,
        states: result.events.map((elem) => {
            return {
                state: elem.operationAttributeTranslated,
                date: moment.tz(elem.operationDateTime, "DD.MM.YYYY HH:mm:ss", zone),
                area: elem.operationPlaceNameTranslated,
                service: elem.serviceName
            }
        }).filter(state => {
            if (state.state == 'The track code is added to the database Track24.ru for automatic monitoring.')
                return false
            return true
        }).sort((a, b) => {
            let dateA = moment(a.date),
                dateB = moment(b.date)

            if (dateA.isBefore(dateB))
                return 1

            return -1
        })
    })
}
1368106
def create(self):
        
        if self._track is None:
            self._track = self.db[self.tracking_collection_name]
1008416
def collection(path, *stats):
  """"""

  def initMethod(self):
    """Init method for the underlying stat object's class."""
    init(self, path)

  attributes = {'__init__': initMethod}
  for stat in stats:
    attributes[stat.getName()] = stat
  newClass = type('Stats:%s' % path, (object,), attributes)
  instance = newClass()
  for stat in stats:
    default = stat._getInit() # Consider this method package-protected. # pylint: disable=W0212
    if default:
      setattr(instance, stat.getName(), default)
  return instance
594665
static int addTracingStatistic(TracingStatistic tracingStatistic) {
    // Check to see if we can enable the tracing statistic before actually
    // adding it.
    if (tracingStatistic.enable()) {
      // No synchronization needed, since this is a copy-on-write array.
      extraTracingStatistics.add(tracingStatistic);
      // 99.9% of the time, this will be O(1) and return
      // extraTracingStatistics.length - 1
      return extraTracingStatistics.lastIndexOf(tracingStatistic);
    } else {
      return -1;
    }
  }
264612
private static void createStats(List<ComponentSpan> statsSpanList,
      Map<Integer, Integer> positionsData,
      Map<MtasSpanQuery, Map<Integer, Integer>> spansNumberData,
      Integer[] docSet) throws IOException {
    if (statsSpanList != null) {
      for (ComponentSpan span : statsSpanList) {
        if (span.parser.needArgumentsNumber() > span.queries.length) {
          throw new IOException(
              "function " + span.parser + " expects (at least) "
                  + span.parser.needArgumentsNumber() + " queries");
        }
        // collect
        Map<Integer, long[]> args = computeArguments(spansNumberData,
            span.queries, docSet);
        if (span.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {
          // try to call functionParser as little as possible
          if (span.statsType.equals(CodecUtil.STATS_BASIC)
              && (span.minimumLong == null) && (span.maximumLong == null)
              && (span.functions == null
                  || (span.functionBasic() && span.functionSumRule()
                      && !span.functionNeedPositions()))) {
            // initialise
            int length = span.parser.needArgumentsNumber();
            long[] valueSum = new long[length];
            long valuePositions = 0;
            // collect
            if (docSet.length > 0) {
              long[] tmpArgs;
              for (int docId : docSet) {
                tmpArgs = args.get(docId);
                valuePositions += (positionsData == null) ? 0
                    : positionsData.get(docId);
                if (tmpArgs != null) {
                  for (int i = 0; i < length; i++) {
                    valueSum[i] += tmpArgs[i];
                  }
                }
              }
              long valueLong;
              span.dataCollector.initNewList(1);
              try {
                valueLong = span.parser.getValueLong(valueSum, valuePositions);
                span.dataCollector.add(valueLong, docSet.length);
              } catch (IOException e) {
                log.debug(e);
                span.dataCollector.error(e.getMessage());
              }
              if (span.functions != null) {
                for (SubComponentFunction function : span.functions) {
                  function.dataCollector.initNewList(1);
                  if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {
                    try {
                      valueLong = function.parserFunction.getValueLong(valueSum,
                          valuePositions);
                      function.dataCollector.add(valueLong, docSet.length);
                    } catch (IOException e) {
                      log.debug(e);
                      function.dataCollector.error(e.getMessage());
                    }
                  } else if (function.dataType
                      .equals(CodecUtil.DATA_TYPE_DOUBLE)) {
                    try {
                      double valueDouble = function.parserFunction
                          .getValueDouble(valueSum, valuePositions);
                      function.dataCollector.add(valueDouble, docSet.length);
                    } catch (IOException e) {
                      log.debug(e);
                      function.dataCollector.error(e.getMessage());
                    }
                  } else {
                    throw new IOException(
                        "can't handle function dataType " + function.dataType);
                  }
                  function.dataCollector.closeNewList();
                }
              }
              span.dataCollector.closeNewList();
            }
          } else {
            // collect
            if (docSet.length > 0) {
              int number = 0;
              int positions;
              long valueLong;
              double valueDouble;
              long[] values = new long[docSet.length];
              long[][] functionValuesLong = null;
              double[][] functionValuesDouble = null;
              span.dataCollector.initNewList(1);
              if (span.functions != null) {
                functionValuesLong = new long[span.functions.size()][];
                functionValuesDouble = new double[span.functions.size()][];
                for (int i = 0; i < span.functions.size(); i++) {
                  SubComponentFunction function = span.functions.get(i);
                  if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {
                    functionValuesLong[i] = new long[docSet.length];
                    functionValuesDouble[i] = null;
                  } else if (function.dataType
                      .equals(CodecUtil.DATA_TYPE_DOUBLE)) {
                    functionValuesLong[i] = null;
                    functionValuesDouble[i] = new double[docSet.length];
                  }
                  function.dataCollector.initNewList(1);
                }
              }
              for (int docId : docSet) {
                if (positionsData == null) {
                  positions = 0;
                } else {
                  positions = (positionsData.get(docId) == null ? 0
                      : positionsData.get(docId));
                }
                valueLong = span.parser.getValueLong(args.get(docId),
                    positions);
                if (((span.minimumLong == null)
                    || (valueLong >= span.minimumLong))
                    && ((span.maximumLong == null)
                        || (valueLong <= span.maximumLong))) {
                  values[number] = valueLong;
                  if (span.functions != null) {
                    for (int i = 0; i < span.functions.size(); i++) {
                      SubComponentFunction function = span.functions.get(i);
                      try {
                        if (function.dataType
                            .equals(CodecUtil.DATA_TYPE_LONG)) {
                          valueLong = function.parserFunction
                              .getValueLong(args.get(docId), positions);
                          functionValuesLong[i][number] = valueLong;
                        } else if (function.dataType
                            .equals(CodecUtil.DATA_TYPE_DOUBLE)) {
                          valueDouble = function.parserFunction
                              .getValueDouble(args.get(docId), positions);
                          functionValuesDouble[i][number] = valueDouble;
                        }
                      } catch (IOException e) {
                        log.debug(e);
                        function.dataCollector.error(e.getMessage());
                      }
                    }
                  }
                  number++;
                }
              }
              if (number > 0) {
                span.dataCollector.add(values, number);
                if (span.functions != null) {
                  for (int i = 0; i < span.functions.size(); i++) {
                    SubComponentFunction function = span.functions.get(i);
                    if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {
                      function.dataCollector.add(functionValuesLong[i], number);
                    } else if (function.dataType
                        .equals(CodecUtil.DATA_TYPE_DOUBLE)) {
                      function.dataCollector.add(functionValuesDouble[i],
                          number);
                    }
                  }
                }
              }
              span.dataCollector.closeNewList();
              if (span.functions != null) {
                for (SubComponentFunction function : span.functions) {
                  function.dataCollector.closeNewList();
                }
              }
            }
          }
        } else {
          throw new IOException("unexpected dataType " + span.dataType);
        }
      }
    }
  }
168196
def setRepCount(self, count):
        """"""
        self._rep_default_cache[0] = count
        self.ui.trackview.model().setRepCount(count)
254545
void createTaskEntry(TaskAttemptID taskid, String taskTracker, TaskInProgress tip) {
    LOG.info("Adding task (" + tip.getAttemptType(taskid) + ") " +
      "'"  + taskid + "' to tip " +
      tip.getTIPId() + ", for tracker '" + taskTracker + "'");

    // taskid --> tracker
    taskidToTrackerMap.put(taskid, taskTracker);

    // tracker --> taskid
    Set<TaskAttemptIDWithTip> taskset = trackerToTaskMap.get(taskTracker);
    if (taskset == null) {
      taskset = new HashSet<TaskAttemptIDWithTip>();
      trackerToTaskMap.put(taskTracker, taskset);
    }
    taskset.add(new TaskAttemptIDWithTip(taskid, tip));

    // taskid --> TIP
    taskidToTIPMap.put(taskid, tip);

  }