Basic statistics
771276
def cli(ctx, monitor, full, stage):
    """"""
    if not ctx.bubble:
        msg = 'There is no bubble present, will not search stats'
        if monitor:
            ctx.say_yellow('Unknown - ' + msg, 0)
            raise SystemExit(3)
        else:
            ctx.say_yellow(msg)
        raise click.Abort()

    stats = {}
    stats_found = False
    flowing_full = False
    flowing_decrease = False
    flowing_increase = False
    errors = False

    loader = bubble_lod_load(ctx, 'stats', stage)
    lod_gen = _find_lod_gen(ctx, loader)
    if lod_gen:
        last_stats = {}
        ctx.say('lod_gen', stuff=lod_gen)
        for stats_data in lod_gen:
            last_stats = stats_data
        if last_stats:
            ctx.say('found last_stats:', stuff=last_stats, verbosity=10)

    try:
        ctx.say('trying:last stats:', stuff=last_stats, verbosity=10)
        if last_stats:
            l = last_stats
            stats['pull_err'] = k0(l, 'pulled_stat_error_count')
            stats['pull_total'] = k0(l, 'pulled_stat_total_count')

            stats['trans_err'] = k0(l, 'transformed_stat_error_count')
            stats['trans_total'] = k0(l, 'transformed_stat_total_count')

            stats['push_err'] = k0(l, 'pushed_stat_error_count')
            stats['push_total'] = k0(l, 'pushed_stat_total_count')
            stats_found = True
        else:
            stats_found = False

        ctx.say('stats:', stuff=stats, verbosity=10)

        if stats_found and stats['pull_err'] > 0 or \
                stats['trans_err'] > 0 or \
                stats['push_err'] > 0:
            errors = True
        if stats_found and stats['pull_total'] == stats['trans_total'] and \
                stats['trans_total'] == stats['push_total']:
            flowing_full = True
        if stats_found and stats['pull_total'] >= stats['trans_total'] >= stats['push_total']:
            flowing_decrease = True
        if stats_found and stats['pull_total'] <= stats['trans_total'] <= stats['push_total']:
            flowing_increase = True
    except KeyError as stat_key_error:
        errors = True
        ctx.gbc.cry('cannot create status from last stats', stuff=stat_key_error)

    if full:
        ctx.say_yellow('Stats full')
        ctx.say_yellow('Full flow:' + str(flowing_full))
        ctx.say_yellow('Flowing decrease:' + str(flowing_decrease))
        ctx.say_yellow('Flowing increase:' + str(flowing_increase))
        ctx.say_yellow('Errors:' + str(errors))
        ctx.say_yellow('totals:')
        ctx.say_yellow(pf(stats, indent=8))

    if monitor == 'nagios' or full:

        """
        for Numeric Value Service Status Status Description, please see:
        https://nagios-plugins.org/doc/guidelines.html#AEN78
        0 OK The plugin was able to check the service and
          it appeared to be functioning properly
        1 Warning The plugin was able to check the service,
          but it appeared to be above some "warning" threshold or did not appear to be working properly
        2 Critical The plugin detected that either the service was not running or
          it was above some "critical" threshold
        3 Unknown Invalid command line arguments were supplied to the plugin or
          low-level failures internal to the plugin (such as unable to fork, or open a tcp socket)
          that prevent it from performing the specified operation. Higher-level errors (such as name resolution errors,
          socket timeouts, etc) are outside of the control of plugins and
          should generally NOT be reported as UNKNOWN states.

        http://nagios.sourceforge.net/docs/3_0/perfdata.html
        http://nagios.sourceforge.net/docs/3_0/pluginapi.html
        """
        if stats_found:
            templ_nagios = 'pull: %d %d transform: %d  %d push: %d %d '
            res_nagios = templ_nagios % (stats['pull_total'],
                                         stats['pull_err'],
                                         stats['trans_total'],
                                         stats['trans_err'],
                                         stats['push_total'],
                                         stats['push_err']
                                         )
        else:
            res_nagios = 'Cannot find or read stats'

        if not stats_found:
            print('Unknown - ' + res_nagios)
            raise SystemExit(3)
            # return

        if not errors and flowing_full:
            print('Ok - ' + res_nagios)
            return

        # magister and databyte with amount
        if not errors and flowing_decrease:
            print('Ok - ' + res_nagios)
            return

        if not errors and not flowing_full:
            print('Warning - ' + res_nagios)
            raise SystemExit(1)
            # return

        if errors:
            print('Critical - ' + res_nagios)
            raise SystemExit(2)
            # return
    return False
441504
def main():
    """"""
    # Load study, population, associations, and GoDag. Run GOEA.
    obj = GoeaCliFnc(GoeaCliArgs().args)
    # Reduce results to significant results (pval<value)
    results_specified = obj.get_results()
    # Print results in a flat list
    obj.prt_results(results_specified)
2955
function Stats(dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atim_msec, mtim_msec, ctim_msec, birthtim_msec, path) {
        /* jshint maxparams: 4 */
        if (arguments.length === 1 && typeof arguments[0] === 'object') {
            return Stats.create(arguments[0]);
        }
        if (!Stats.is(this)) {
            return new Stats(dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atim_msec, mtim_msec, ctim_msec,
                birthtim_msec, path);
        }

        var entry = path;
        this.getEntry = function () {
            return entry;
        };

        /* ID of device containing file */
        this.dev = dev;
        /* inode number */
        this.mode = mode;
        /* protection */
        this.nlink = nlink;
        /* number of hard links */
        this.uid = uid;
        /* user ID of owner */
        this.gid = gid;
        /* group ID of owner */
        this.rdev = rdev;
        /* device ID (if special file) */
        this.blksize = blksize;
        /* total size, in bytes */
        this.ino = ino;
        /* blocksize for file system I/O */
        this.size = size;
        /* number of 512B blocks allocated */
        this.blocks = blocks;
        /* time of last access */
        this.atime = new Date(atim_msec);
        /* time of last modification */
        this.mtime = new Date(mtim_msec);
        /* time of last status change */
        this.ctime = new Date(ctim_msec);
        this.birthtime = new Date(birthtim_msec);
    }
129242
def plot_basic_hist(samples, file_type, **plot_args):
    

    sumy = sum([int(samples[sample]['data'][x][0])
                for sample in samples
                for x in samples[sample]['data']])

    cutoff = sumy * 0.999
    all_x = set()
    for item in sorted(chain(*[samples[sample]['data'].items()
                                for sample in samples])):
        all_x.add(item[0])
        cutoff -= item[1][0]
        if cutoff < 0:
            xmax = item[0]
            break
    else:
        xmax = max(all_x)

    data = {
        sample: {
            x: samples[sample]['data'][x][0] if x in samples[sample]['data'] else 0
            for x in all_x
        }
        for sample in samples
    }

    plot_params = {
            'id': 'bbmap-' + file_type + '_plot',
            'title': 'BBTools: ' + plot_args['plot_title'],
            'xmax': xmax
    }
    plot_params.update(plot_args['plot_params'])
    plot = linegraph.plot(
        data,
        plot_params
    )

    return plot
102918
def tree_statistics(tree):
    
    all_elements = tree.findall('//')
    tag_counter = defaultdict(int)
    for element in all_elements:
        tag_counter[element.tag] += 1
    for (tag, counts) in tag_counter.items():
        print "{0}: {1}".format(tag, counts)
1287797
def statistics_row(cat)
      [cat, hits(cat), display_value(sum(cat)), display_value(mean(cat)), display_value(stddev(cat)),
       display_value(min(cat)), display_value(max(cat)),
       display_value(percentile_interval(cat, 95).begin) + '-' + display_value(percentile_interval(cat, 95).end)]
    end
810574
def stats(self):
        ''''''
        data = Counter()
        for name, value, aggregated in self.raw:
            if aggregated:
                data['%s.max' % name] = max(data['%s.max' % name], value)
                data['%s.total' % name] += value
            else:
                data[name] = value

        return sorted(data.items())
831699
def _naive_concordance_summary_statistics(event_times, predicted_event_times, event_observed):
    
    num_pairs = 0.0
    num_correct = 0.0
    num_tied = 0.0

    for a, time_a in enumerate(event_times):
        pred_a = predicted_event_times[a]
        event_a = event_observed[a]
        # Don't want to double count
        for b in range(a + 1, len(event_times)):
            time_b = event_times[b]
            pred_b = predicted_event_times[b]
            event_b = event_observed[b]

            if _valid_comparison(time_a, time_b, event_a, event_b):
                num_pairs += 1.0
                crct, ties = _concordance_value(time_a, time_b, pred_a, pred_b, event_a, event_b)
                num_correct += crct
                num_tied += ties

    return (num_correct, num_tied, num_pairs)
975605
def summary(self):
        
        df = pd.DataFrame(index=self.params_.index)
        df["coef"] = self.params_
        df["se(coef)"] = self.standard_errors_
        df["lower 95% bound"] = self.confidence_intervals_["lower 95% bound"]
        df["upper 95% bound"] = self.confidence_intervals_["upper 95% bound"]
        return df
527754
def summary(self):
        
        ci = 1 - self.alpha
        lower_upper_bounds = self._compute_confidence_bounds_of_parameters()
        df = pd.DataFrame(index=self._fitted_parameter_names)
        df["coef"] = self._fitted_parameters_
        df["se(coef)"] = self._compute_standard_errors().loc["se"]
        df["lower %g" % ci] = lower_upper_bounds["lower-bound"]
        df["upper %g" % ci] = lower_upper_bounds["upper-bound"]
        df["p"] = self._compute_p_values()
        with np.errstate(invalid="ignore", divide="ignore"):
            df["-log2(p)"] = -np.log2(df["p"])
        return df
287906
def plot(self,init=None):
		""""""

		if not init:
			init=self
			init.plotstats={}
			init.unitfeats=self._getFeatValDict()

			sels=[]
			for k,v in sorted(init.unitfeats.items()):
				for kk,vv in v.items():
					sels.append((k,kk))

			conditions={'x':[],'y':[]}
			targets={'x':[],'y':[]}
			pkey={'x':[],'y':[]}

			print str(0)+"\t[no condition]"
			for selnum in range(len(sels)):
				print str(selnum+1)+"\t"+str(sels[selnum][0])+" = "+str(sels[selnum][1])
			print

			stepnum=0
			for a in sorted(conditions.keys()):
				stepnum+=1
				sel=raw_input(">> [step "+str(stepnum)+"/4] ["+a+" coord] [conditions of population] please type in the number (or numbers separated by commas)\n\tof the conditions determining the total population from which the percentage of the sample is taken:\n").strip()
				for x in sel.split(","):
					try:
						conditions[a].append(sels[int(x)-1])
						pkey[a]+=["of_"+str(sels[int(x)-1][0])+"_is_"+str(sels[int(x)-1][1])]
					except:
						pass

				stepnum+=1
				sel=raw_input(">> [step "+str(stepnum)+"/4] ["+a+" coord] [conditions of sample] please type in the number (or numbers separated by commas)\n\tof the conditions determining the sample:\n").strip()
				for x in sel.split(","):
					try:
						targets[a].append(sels[int(x)-1])
						pkey[a]+=[str(sels[int(x)-1][0])+"_is_"+str(sels[int(x)-1][1])]
					except:
						pass


			# print ">> POPULATION:"
			# print conditions
			#
			# print ">> SAMPLE:"
			# print targets

			init.population=conditions
			init.sample=targets

			init.pkey="X_"+"-".join(pkey['x'])+"."+"Y_"+"-".join(pkey['y'])
			print ">> plotting: "+ init.pkey


		if not hasattr(self,'bestParses'):
			for child in self.children:
				child.plot(init)
		else:
			posdict={}
			minparselen = min([len(parse.positions) for parse in self.bestParses()])
			maxparselen = max([len(parse.positions) for parse in self.bestParses()])
			#if not hasattr(self,'minparselen'): return None
			for posnum in range(maxparselen):
				posdict[posnum]={'x':[],'y':[]}
				for parse in self.bestParses():
					try:
						posfeats=parse.positions[posnum].posfeats()
					except IndexError:
						# there is no position number `posnum` in this parse `parse`
						continue

					for a in ['x','y']:
						conds=init.population[a]
						targs=init.sample[a]

						condsHold=True
						if len(conds):
							for cond in conds:
								condK=cond[0]
								condV=cond[1]

								try:
									if posfeats[condK]==condV:
										continue
								except:
									condsHold=False
									break
								condsHold=False
								break

						if condsHold:
							targsHold=True
							for targ in targs:
								targK=targ[0]
								targV=targ[1]

								try:
									if posfeats[targK]==targV:
										continue
								except:
									targsHold=False
									break
								targsHold=False
								break

							if targsHold:
								posdict[posnum][a].append(1)
							else:
								posdict[posnum][a].append(0)

			for a in ['x','y']:
				if not posdict[posnum][a]:
					print "<< not enough data: position number ("+str(posnum)+") empty on dimension ["+str(a)+"]"
					return None

			init.plotstats[self.getName()]=posdict
			if (self!=init): return None

		totalstrs=[]
		totaltsvs=[]
		for textname,posdict in sorted(init.plotstats.items()):

			tsv="posnum\tnumobs\tx_mean\ty_mean\tx_std\ty_std\n"
			xs=[]
			ys=[]
			for posnum,xydict in posdict.items():
				x_avg,x_std=mean_stdev(xydict['x'])
				y_avg,y_std=mean_stdev(xydict['y'])

				assert len(xydict['x'])==len(xydict['y'])

				xs.append(x_avg)
				ys.append(y_avg)
				tsv+="\t".join(str(bb) for bb in [(posnum+1),len(xydict['x']),x_avg,y_avg,x_std,y_std])+"\n"


			ccmsg=""
			cc=None
			p=None
			try:
				from statlib import stats
				(cc,p)=stats.pearsonr(xs,ys)

				aa=makeminlength("    correlation coefficient: ",int(being.linelen/1.4))+str(cc)
				bb=makeminlength("    p-value: ",int(being.linelen/1.4))+str(p)

				tsv+=aa.strip().replace(":",":\t")+"\n"
				tsv+=bb.strip().replace(":",":\t")+"\n"

				for l in tsv.split("\n"):
					totaltsvs.append(textname+"_"+l)

				ccmsg+=aa+"\n"+bb+"\n"

			except:
				pass

			writeToFile(textname,init.pkey,tsv,extension="tsv")
			totaltsvs.append(tsv)

			"""
			try:
				strtowrite=self.makeBubbleChart(posdict,".".join([textname,init.pkey]),(cc,p))
				totalstrs+=[strtowrite]
				writeToFile(textname,init.pkey,self._getBubbleHeader()+strtowrite+self._getBubbleFooter(),extension="htm")
			except:
				pass
			"""

			if ccmsg:
				print ccmsg

		if not self.classname()=="Corpus": return None

		"""
		writeToFile(self.getName(),
			init.pkey,
			self._getBubbleHeader()+"\n<br/><br/><br/><br/><br/><br/><br/><br/>\n".join(totalstrs)+self._getBubbleFooter(),
			iscorpus=True,
			extension="htm")
		"""

		writeToFile(self.getName(),init.pkey,"\n\n\n\n".join(totaltsvs),iscorpus=True,extension="tsv")
1312455
def _sd_of_runs(stats, mean, key='runs'):
    

    num_runs = len(stats[key])
    first = stats[key][0]

    standard_deviation = {}
    for stat_key in first:
        # Skip non numberic attributes
        if isinstance(first[stat_key], numbers.Number):
            standard_deviation[stat_key] = math.sqrt(
                sum((run[stat_key] - mean[stat_key])**2
                    for run in stats[key]) / float(num_runs))

    return standard_deviation
703964
protected void computeStatistics(T input, int innerWidth, int innerHeight) {
		original.init(blockWidth,blockHeight,thresholdFromLocalBlocks);

		int statPixelStride = stats.getImageType().getNumBands();

		int indexStats = 0;
		for (int y = 0; y < innerHeight; y += blockHeight) {
			for (int x = 0; x < innerWidth; x += blockWidth, indexStats += statPixelStride) {
				original.computeBlockStatistics(x,y,blockWidth,blockHeight,indexStats,input,stats);
			}
			// handle the case where the image's width isn't evenly divisible by the block's width
			if( innerWidth != input.width ) {
				original.computeBlockStatistics(innerWidth,y,input.width-innerWidth,blockHeight,indexStats,input,stats);
				indexStats += statPixelStride;
			}
		}
		// handle the case where the image's height isn't evenly divisible by the block's height
		if( innerHeight != input.height ) {
			int y = innerHeight;
			int blockHeight = input.height-innerHeight;
			for (int x = 0; x < innerWidth; x += blockWidth, indexStats += statPixelStride) {
				original.computeBlockStatistics(x,y,blockWidth,blockHeight,indexStats,input,stats);
			}
			if( innerWidth != input.width ) {
				original.computeBlockStatistics(innerWidth,y,input.width-innerWidth,blockHeight,indexStats,input,stats);
			}
		}
	}
1196637
def stats(self):
        
        printDebug("Classes.....: %d" % len(self.all_classes))
        printDebug("Properties..: %d" % len(self.all_properties))
852545
def _update_general_statistics(a_float, dist):
    
    if not dist.count:
        dist.count = 1
        dist.maximum = a_float
        dist.minimum = a_float
        dist.mean = a_float
        dist.sumOfSquaredDeviation = 0
    else:
        old_count = dist.count
        old_mean = dist.mean
        new_mean = ((old_count * old_mean) + a_float) / (old_count + 1)
        delta_sum_squares = (a_float - old_mean) * (a_float - new_mean)
        dist.count += 1
        dist.mean = new_mean
        dist.maximum = max(a_float, dist.maximum)
        dist.minimum = min(a_float, dist.minimum)
        dist.sumOfSquaredDeviation += delta_sum_squares
430783
function printStats() {
  _.each(statsTracker, function(vals, stat) {
    var numStats = vals.length;
    var total = _.reduce(vals, function(memo, num) {
      return memo + num;
    }, 0);
    var avg = parseFloat(total / numStats).toFixed(4) + 'ms';
    var printableTotal = parseFloat(total).toFixed(4) + 'ms';
    logger.log(stat + ': ' + avg + ' (' + printableTotal + ' / ' + numStats + ')');
  });
  statsTracker = {};
}
1225705
def basic_stats(self):
        """"""
        comment_score = sum(comment.score for comment in self.comments)
        if self.comments:
            comment_duration = (self.comments[-1].created_utc -
                                self.comments[0].created_utc)
            comment_rate = self._rate(len(self.comments), comment_duration)
        else:
            comment_rate = 0

        submission_duration = self.max_date - self.min_date
        submission_rate = self._rate(len(self.submissions),
                                     submission_duration)
        submission_score = sum(sub.score for sub in self.submissions.values())

        values = [('Total', len(self.submissions), len(self.comments)),
                  ('Rate (per day)', '{:.2f}'.format(submission_rate),
                   '{:.2f}'.format(comment_rate)),
                  ('Unique Redditors', len(self.submitters),
                   len(self.commenters)),
                  ('Combined Score', submission_score, comment_score)]

        retval = 'Period: {:.2f} days\n\n'.format(submission_duration / 86400.)
        retval += '||Submissions|Comments|\n:-:|--:|--:\n'
        for quad in values:
            retval += '__{}__|{}|{}\n'.format(*quad)
        return retval + '\n'