Collector for getting count of consistancy points
12569
def consistency_point(self):
        

        cp_delta = {}
        xml_path = 'instances/instance-data/counters'
        netapp_api = NaElement('perf-object-get-instances')
        netapp_api.child_add_string('objectname', 'wafl')
        instance = NaElement('instances')
        instance.child_add_string('instance', 'wafl')
        counter = NaElement('counters')
        counter.child_add_string('counter', 'cp_count')
        netapp_api.child_add(counter)
        netapp_api.child_add(instance)

        cp_1 = self.get_netapp_elem(netapp_api, xml_path)
        time.sleep(3)
        cp_2 = self.get_netapp_elem(netapp_api, xml_path)

        for element in cp_1:
            if element.find('name').text == 'cp_count':
                cp_1 = element.find('value').text.rsplit(',')
                break
        for element in cp_2:
            if element.find('name').text == 'cp_count':
                cp_2 = element.find('value').text.rsplit(',')
                break

        if not type(cp_2) is list or not type(cp_1) is list:
            log.error("consistency point data not available for filer: %s"
                      % self.device)
            return

        cp_1 = {
            'wafl_timer': cp_1[0],
            'snapshot': cp_1[1],
            'wafl_avail_bufs': cp_1[2],
            'dirty_blk_cnt': cp_1[3],
            'full_nv_log': cp_1[4],
            'b2b': cp_1[5],
            'flush_gen': cp_1[6],
            'sync_gen': cp_1[7],
            'def_b2b': cp_1[8],
            'con_ind_pin': cp_1[9],
            'low_mbuf_gen': cp_1[10],
            'low_datavec_gen': cp_1[11]
        }

        cp_2 = {
            'wafl_timer': cp_2[0],
            'snapshot': cp_2[1],
            'wafl_avail_bufs': cp_2[2],
            'dirty_blk_cnt': cp_2[3],
            'full_nv_log': cp_2[4],
            'b2b': cp_2[5],
            'flush_gen': cp_2[6],
            'sync_gen': cp_2[7],
            'def_b2b': cp_2[8],
            'con_ind_pin': cp_2[9],
            'low_mbuf_gen': cp_2[10],
            'low_datavec_gen': cp_2[11]
        }

        for item in cp_1:
            c1 = int(cp_1[item])
            c2 = int(cp_2[item])
            cp_delta[item] = c2 - c1

        for item in cp_delta:
            self.push(item + '_CP', 'system.system', cp_delta[item])
936890
def _collectAsArrow(self):
        
        with SCCallSiteSync(self._sc) as css:
            sock_info = self._jdf.collectAsArrowToPython()

        # Collect list of un-ordered batches where last element is a list of correct order indices
        results = list(_load_from_socket(sock_info, ArrowCollectSerializer()))
        batches = results[:-1]
        batch_order = results[-1]

        # Re-order the batch list using the correct order
        return [batches[i] for i in batch_order]
1269083
def distinct_frequencies(self):
        """"""

        c = self.distinct_counts()
        n = self.shape[1]
        return c / n
935440
public Counter<F> getFeatureCounter()
  {
    Counter<F> featureCounts = new ClassicCounter<F>();
    for (int i=0; i < this.size(); i++)
    {
      BasicDatum<L, F> datum = (BasicDatum<L, F>) getDatum(i);
      Set<F> featureSet   = new HashSet<F>(datum.asFeatures());
      for (F key : featureSet) {
        featureCounts.incrementCount(key, 1.0);
      }
    }
    return featureCounts;
  }
117577
def count_by_time(self):
        """"""
        out = np.empty((len(self.timesteps),), dtype=[('time', float), ('count', int)])
        for cursor,timestep in enumerate(self.timesteps):
            out[cursor] = (timestep,len([x for x in self.timeseries if x.time==timestep]))
        return out.view(np.recarray)
761026
private Double fetchInstancesOnlineRatio(ObjectId collectorItemId) {
    int totalInstances = 0, totalInstancesOnline = 0;
    Double instancesOnlineScore = null;

    List<EnvironmentStatus> statuses = environmentStatusRepository
      .findByCollectorItemId(collectorItemId);

    if (null == statuses || statuses.isEmpty()) {
      return null;
    }

    for (EnvironmentStatus environmentStatus : statuses) {
      totalInstances++;
      if (environmentStatus.isOnline()) {
        totalInstancesOnline++;
      }
    }
    instancesOnlineScore = ((totalInstancesOnline * 100) / (double) totalInstances);
    LOGGER.info("totalInstances " + totalInstances + " totalInstancesOnline " + totalInstancesOnline + " instancesOnlineScore " + instancesOnlineScore);

    return instancesOnlineScore;
  }
776512
@Override
    public void collectMetrics() {
        long nanosBefore = System.nanoTime();
        /*
         * Optimisation tip: no need to skip 'mbeanServer.queryNames()' if the ObjectName is not a pattern
         * (i.e. not '*' or '?' wildcard) because the mbeanserver internally performs the check.
         * Seen on com.sun.jmx.interceptor.DefaultMBeanServerInterceptor
         */
        Set<ObjectName> matchingObjectNames = embeddedJmxTrans.getMbeanServer().queryNames(this.objectName, null);
        logger.trace("Query {} returned {}", objectName, matchingObjectNames);

        for (ObjectName matchingObjectName : matchingObjectNames) {
            long epochInMillis = System.currentTimeMillis();
            try {
                AttributeList jmxAttributes = embeddedJmxTrans.getMbeanServer().getAttributes(matchingObjectName, this.attributeNames);
                logger.trace("Query {} returned {}", matchingObjectName, jmxAttributes);
                for (Attribute jmxAttribute : jmxAttributes.asList()) {
                    QueryAttribute queryAttribute = this.attributesByName.get(jmxAttribute.getName());
                    Object value = jmxAttribute.getValue();
                    int count = queryAttribute.collectMetrics(matchingObjectName, value, epochInMillis, this.queryResults);
                    collectedMetricsCount.addAndGet(count);
                }
            } catch (Exception e) {
                logger.warn("Exception processing query {}", this, e);
            }
        }
        collectionCount.incrementAndGet();
        long nanosAfter = System.nanoTime();
        collectionDurationInNanos.addAndGet(nanosAfter - nanosBefore);
    }
669116
public static int countUnique(Collection<?> collection) {
        HashSet<Object> set = new HashSet<>(collection);
        return set.size();
    }
1218986
def _collectAxisPoints(self):
        
        for l, (value, deltaName) in self.items():
            location = Location(l)
            name = location.isOnAxis()
            if name is not None and name is not False:
                if name not in self._axes:
                    self._axes[name] = []
                if l not in self._axes[name]:
                    self._axes[name].append(l)
        return self._axes
827805
def PointCollection(mode="raw", *args, **kwargs):
    

    if mode == "raw":
        return RawPointCollection(*args, **kwargs)
    return AggPointCollection(*args, **kwargs)
628914
private Metric collectCounter(String dropwizardName, Counter counter) {
    String metricName = DropWizardUtils.generateFullMetricName(dropwizardName, "counter");
    String metricDescription =
        DropWizardUtils.generateFullMetricDescription(dropwizardName, counter);

    MetricDescriptor metricDescriptor =
        MetricDescriptor.create(
            metricName,
            metricDescription,
            DEFAULT_UNIT,
            Type.GAUGE_INT64,
            Collections.<LabelKey>emptyList());
    TimeSeries timeSeries =
        TimeSeries.createWithOnePoint(
            Collections.<LabelValue>emptyList(),
            Point.create(Value.longValue(counter.getCount()), clock.now()),
            null);
    return Metric.createWithOneTimeSeries(metricDescriptor, timeSeries);
  }
1107119
def count(self, item):
        """"""
        try:
            return self.items.get(item, 0)
        except TypeError:
            return self.items.get(repr(item), 0)
1074609
def count(self):
        
        return (
            self
            .mapPartitions(lambda p: [sum(1 for _ in p)])
            .reduce(operator.add)
        )
784959
public SimpleFeatureCollection toFeatureCollection(
            List<MonitoringPoint> monitoringPointsList ) {

        // create the feature type
        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        // set the name
        b.setName("monitoringpoints");
        // add a geometry property
        b.add("the_geom", Point.class);
        // add some properties
        b.add("id", Integer.class);
        b.add("relatedid", Integer.class);
        b.add("pfaf", String.class);
        // build the type
        SimpleFeatureType type = b.buildFeatureType();
        // create the feature
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

        GeometryFactory gF = new GeometryFactory();
        /*
         * insert them in inverse order to get them out of the collection in the same order as the
         * list
         */
        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        for( int i = 0; i < monitoringPointsList.size(); i++ ) {
            MonitoringPoint mp = monitoringPointsList.get(monitoringPointsList.size() - i - 1);

            Object[] values = new Object[]{gF.createPoint(mp.getPosition()), mp.getID(),
                    mp.getRelatedID(), mp.getPfatstetterNumber().toString()};
            // add the values
            builder.addAll(values);
            // build the feature with provided ID
            SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + i);
            newCollection.add(feature);
        }

        return newCollection;
    }
1342961
def _count_values(self):
        """"""
        indices = {yi: [i] for i, yi in enumerate(self.y) if self.status[i]}

        return indices
293746
def objectcount(data, key):
    """"""
    objkey = key.upper()
    return len(data.dt[objkey])
1068299
def countByValue(self):
        
        def countPartition(iterator):
            counts = defaultdict(int)
            for obj in iterator:
                counts[obj] += 1
            yield counts

        def mergeMaps(m1, m2):
            for k, v in m2.items():
                m1[k] += v
            return m1
        return self.mapPartitions(countPartition).reduce(mergeMaps)