public Statistic getStatistic(Statistic statistic) { for (Statistic s : statistics) { if (s.equals(statistic)) return s; } return null; }
public static void main(String[] args) throws Exception { int iterations; if (args.length > 0) { iterations = Integer.valueOf(args[0]); } else { iterations = 1000; } System.out.println("Program is running on " + iterations + " iterations"); BaseStrategy strategy1 = new ImmutableStrategy(); BaseStrategy strategy2 = new MutableStrategy(); Game immutableGame = new Game(iterations, strategy1); Game mutableGame = new Game(iterations, strategy2); Thread t1 = new Thread(immutableGame); Thread t2 = new Thread(mutableGame); t1.start(); t2.start(); t1.join(); t2.join(); Statistic immutableResult = immutableGame.getStatistic(); Statistic mutableResult = mutableGame.getStatistic(); System.out.println( "Immutable strategy success count: " + immutableResult.getSuccessTurnNums().size()); System.out.println( "Mutable strategy success count: " + mutableResult.getSuccessTurnNums().size()); }
/** @return mean of contained statistics */ public double getStatisticValue(int dim) { if (base <= 1.0) { return Math.log(statistic.getStatisticValue(dim)); } else { return Math.log(statistic.getStatisticValue(dim)) / Math.log(base); } }
// 计算导航坐标 void run_navigate(Data_Sensor ds, DrawView dv, Config cfg) { float[] data_ori_tans = ds.use_ori_trans(); float[] AbsCoodinate_filt; // 由旋转矩阵计算的绝对坐标系下加速度的坐标值 AbsCoodinate_filt = rotate_filt(ds, dv); // 取极大值和极小值,加负号去掉方向的影响 PeFin.FindPeak(-AbsCoodinate_filt[2]); // 存储X Y轴的值 PeFin_X.StoreValue(AbsCoodinate_filt[0]); PeFin_Y.StoreValue(AbsCoodinate_filt[1]); // 计算步长和步数,记步也是正确的 SDCal.CalcuStepDist(PeFin, cfg.STEP_PARAM); if (SDCal.isStep == true) { // 用大地坐标系下的加速度来确定方向 angleTrans = Orientation_With_acceleration.OrientWithTime( PeFin, SDCal, PeFin_X.fArray3, PeFin_Y.fArray3, cfg.SFM1_4, cfg.EFM1_4); // GeneralTool.saveToSDcard(angleTrans); dv.ori_acc = angleTrans; // 存储传感器方向和计算的方向和两个方向增量 dv.ori_increment = statistic.cal_sto_oriincre(angleTrans, data_ori_tans[0]); statistic.store_oriacc(angleTrans); statistic.store_orisen(data_ori_tans[0]); dv.mean_orisensor = statistic.mean_orisen(); dv.mean_oriacc = statistic.mean_oriacc(); /*GeneralTool.saveToSDcard(angleTrans,drawView.orientationA,"data_angel.txt"); GeneralTool.saveToSDcard(PeFin.Circle*PeFin.bufflength3 + SDCal.PreMinValueIndex, SDCal.PreMaxValueIndex < SDCal.PreMinValueIndex ? (PeFin.Circle*PeFin.bufflength3 + SDCal.PreMaxValueIndex):((PeFin.Circle-1)*PeFin.bufflength3 + SDCal.PreMaxValueIndex), "data_min_max_index.txt");*/ } }
public SimpleStatistic(Statistic statistic) { this( statistic.getCount(), statistic.getMin(), statistic.getMax(), statistic.getAverage(), statistic.getStandardDeviation()); }
/** * This method is called after every method execution * * @param staticPart * @param result */ @AfterReturning(pointcut = "firstPointcut() && secondPointcut()", returning = "result") public void logMethodExit(StaticPart staticPart, Object result) { if (!this.isBugEnabled()) { return; } Date endDate = new Date(); MessageDigest md = null; try { md = MessageDigest.getInstance("SHA"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } String key = new String(md.digest(staticPart.getSignature().toShortString().getBytes())); Statistic stat = new Statistic(); if (allStats.containsKey(key)) { stat = allStats.get(key); } long elapsedTime = getElapsedTime(stat.lastDate, endDate); if (stat.min > elapsedTime) { stat.min = elapsedTime; } if (stat.max < elapsedTime) { stat.max = elapsedTime; } stat.callCount++; stat.sum += elapsedTime; allStats.put(key, stat); String className = staticPart.getSignature().getDeclaringType().getCanonicalName(); String method = staticPart.getSignature().toShortString(); StringBuffer sb = new StringBuffer("OUT: Class: ") .append(className) .append(" Method: ") .append(method) .append(" result: ["); sb.append(result.toString()).append("] finished at ["); sb.append(formatDate(endDate)); sb.append("]"); sb.append("]\n elapsed time: ").append(elapsedTime).append("ms"); sb.append(" min time: ").append(stat.min).append("ms"); sb.append(" max time: ").append(stat.max).append("ms"); sb.append(" avg time: ").append(stat.sum / stat.callCount).append("ms"); sb.append(" Called ").append(stat.callCount).append(" times"); LOGGER.debug(sb.toString()); }
public String toString() { final StringBuilder sb = new StringBuilder(); for (final Statistic m : Statistic.values()) { sb.append(m.toString()); sb.append("="); sb.append(statsCurrent.getStatistic(m)); sb.append(", "); } if (sb.length() > 2) { sb.delete(sb.length() - 2, sb.length()); } return sb.toString(); }
private void resetDailyStats() { try { final Map<String, String> emailValues = new LinkedHashMap<>(); for (final Statistic statistic : Statistic.values()) { final String key = statistic.getLabel(PwmConstants.DEFAULT_LOCALE); final String value = statsDaily.getStatistic(statistic); emailValues.put(key, value); } AlertHandler.alertDailyStats(pwmApplication, emailValues); } catch (Exception e) { LOGGER.error("error while generating daily alert statistics: " + e.getMessage()); } currentDailyKey = new DailyKey(new Date()); statsDaily = new StatisticsBundle(); LOGGER.debug("reset daily statistics"); }
public int outputStatsToCsv( final OutputStream outputStream, final Locale locale, final boolean includeHeader) throws IOException { LOGGER.trace("beginning output stats to csv process"); final Date startTime = new Date(); final StatisticsManager statsManger = pwmApplication.getStatisticsManager(); final CSVPrinter csvPrinter = Helper.makeCsvPrinter(outputStream); if (includeHeader) { final List<String> headers = new ArrayList<>(); headers.add("KEY"); headers.add("YEAR"); headers.add("DAY"); for (Statistic stat : Statistic.values()) { headers.add(stat.getLabel(locale)); } csvPrinter.printRecord(headers); } int counter = 0; final Map<StatisticsManager.DailyKey, String> keys = statsManger.getAvailableKeys(PwmConstants.DEFAULT_LOCALE); for (final StatisticsManager.DailyKey loopKey : keys.keySet()) { counter++; final StatisticsBundle bundle = statsManger.getStatBundleForKey(loopKey.toString()); final List<String> lineOutput = new ArrayList<>(); lineOutput.add(loopKey.toString()); lineOutput.add(String.valueOf(loopKey.year)); lineOutput.add(String.valueOf(loopKey.day)); for (final Statistic stat : Statistic.values()) { lineOutput.add(bundle.getStatistic(stat)); } csvPrinter.printRecord(lineOutput); } csvPrinter.flush(); LOGGER.trace( "completed output stats to csv process; output " + counter + " records in " + TimeDuration.fromCurrent(startTime).asCompactString()); return counter; }
void cleanall() { super.cleanall(); // 统计数据清空 statistic.cleanalldata(); // PeakFinder清空 PeFin.cleanall(); PeFin_X.cleanall(); PeFin_Y.cleanall(); // StepDistCalculater清空 SDCal.cleanall(); angleTrans = 0; }
/** * This method is called before every method execution * * @param joinPoint */ @Before("firstPointcut() && secondPointcut()") public void logMethodEntry(JoinPoint joinPoint) { // If the bug is disabled, do not log anything if (!this.isBugEnabled()) { return; } Date date = new Date(); MessageDigest md = null; try { md = MessageDigest.getInstance("SHA"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } String key = new String(md.digest(joinPoint.getSignature().toShortString().getBytes())); Statistic stat = new Statistic(); if (allStats.containsKey(key)) { stat = allStats.get(key); } stat.lastDate = date; allStats.put(key, stat); String className = joinPoint.getSignature().getDeclaringType().getCanonicalName(); String method = joinPoint.getSignature().toShortString(); StringBuffer sb = new StringBuffer("IN: Class: ") .append(className) .append(" Method: ") .append(method) .append(" called with args: ["); for (Object o : joinPoint.getArgs()) { sb.append(o.toString()).append(", "); } sb.append("] at ["); sb.append(formatDate(date)); sb.append("]"); LOGGER.debug(sb.toString()); }
@Override protected void onCreate(Bundle savedinstancestate) { super.onCreate(savedinstancestate); setContentView(R.layout.activity_list); // names of columns history table datt = (String) getText(R.string.date); stepp = (String) getText(R.string.step); timm = (String) getText(R.string.time); // list for record results of customer listh = (ListView) findViewById(R.id.list_h); hist = new ArrayList<String>(); adapt = new ArrayAdapter<String>(this, R.layout.list_history, hist); listh.setAdapter(adapt); // create a new object DatabaseHandler DatabaseHandler basa = new DatabaseHandler(this); // get all results from database List<Statistic> stat = basa.getAllStatistics(); // write all results to list for (Statistic cn : stat) { hist.add( datt + " " + cn.getDate() + "\n" + stepp + " " + String.valueOf(cn.getStep()) + timm + " " + cn.getTime()); adapt.notifyDataSetChanged(); } }
public synchronized void failedExchange(Exchange exchange) { increment(); exchangesFailed.increment(); exchangesInflight.decrement(); if (ExchangeHelper.isRedelivered(exchange)) { redeliveries.increment(); } Boolean externalRedelivered = exchange.isExternalRedelivered(); if (externalRedelivered != null && externalRedelivered) { externalRedeliveries.increment(); } long now = new Date().getTime(); if (firstExchangeFailureTimestamp.getUpdateCount() == 0) { firstExchangeFailureTimestamp.updateValue(now); } lastExchangeFailureTimestamp.updateValue(now); if (firstExchangeFailureExchangeId == null) { firstExchangeFailureExchangeId = exchange.getExchangeId(); } lastExchangeFailureExchangeId = exchange.getExchangeId(); }
public synchronized void completedExchange(Exchange exchange, long time) { increment(); exchangesCompleted.increment(); exchangesInflight.decrement(); if (ExchangeHelper.isFailureHandled(exchange)) { failuresHandled.increment(); } Boolean externalRedelivered = exchange.isExternalRedelivered(); if (externalRedelivered != null && externalRedelivered) { externalRedeliveries.increment(); } minProcessingTime.updateValue(time); maxProcessingTime.updateValue(time); totalProcessingTime.updateValue(time); lastProcessingTime.updateValue(time); deltaProcessingTime.updateValue(time); long now = new Date().getTime(); if (firstExchangeCompletedTimestamp.getUpdateCount() == 0) { firstExchangeCompletedTimestamp.updateValue(now); } lastExchangeCompletedTimestamp.updateValue(now); if (firstExchangeCompletedExchangeId == null) { firstExchangeCompletedExchangeId = exchange.getExchangeId(); } lastExchangeCompletedExchangeId = exchange.getExchangeId(); // update mean long count = exchangesCompleted.getValue(); long mean = count > 0 ? totalProcessingTime.getValue() / count : 0; meanProcessingTime.updateValue(mean); }
public long getExchangesFailed() throws Exception { return exchangesFailed.getValue(); }
public Date getFirstExchangeFailureTimestamp() { long value = firstExchangeFailureTimestamp.getValue(); return value > 0 ? new Date(value) : null; }
public synchronized void processExchange(Exchange exchange) { exchangesInflight.increment(); }
public long getDeltaProcessingTime() throws Exception { return deltaProcessingTime.getValue(); }
public Date getLastExchangeCompletedTimestamp() { long value = lastExchangeCompletedTimestamp.getValue(); return value > 0 ? new Date(value) : null; }
public long getTotalProcessingTime() throws Exception { return totalProcessingTime.getValue(); }
public long getLastProcessingTime() throws Exception { return lastProcessingTime.getValue(); }
public long getExternalRedeliveries() throws Exception { return externalRedeliveries.getValue(); }
public long getMaxProcessingTime() throws Exception { return maxProcessingTime.getValue(); }
public long getRedeliveries() throws Exception { return redeliveries.getValue(); }
public long getFailuresHandled() throws Exception { return failuresHandled.getValue(); }
public int getDimension() { return statistic.getDimension(); }
public String dumpStatsAsXml(boolean fullStats) { StringBuilder sb = new StringBuilder(); sb.append("<stats "); sb.append(String.format("exchangesCompleted=\"%s\"", exchangesCompleted.getValue())); sb.append(String.format(" exchangesFailed=\"%s\"", exchangesFailed.getValue())); sb.append(String.format(" failuresHandled=\"%s\"", failuresHandled.getValue())); sb.append(String.format(" redeliveries=\"%s\"", redeliveries.getValue())); sb.append(String.format(" externalRedeliveries=\"%s\"", externalRedeliveries.getValue())); sb.append(String.format(" minProcessingTime=\"%s\"", minProcessingTime.getValue())); sb.append(String.format(" maxProcessingTime=\"%s\"", maxProcessingTime.getValue())); sb.append(String.format(" totalProcessingTime=\"%s\"", totalProcessingTime.getValue())); sb.append(String.format(" lastProcessingTime=\"%s\"", lastProcessingTime.getValue())); sb.append(String.format(" deltaProcessingTime=\"%s\"", deltaProcessingTime.getValue())); sb.append(String.format(" meanProcessingTime=\"%s\"", meanProcessingTime.getValue())); if (fullStats) { sb.append(String.format(" startTimestamp=\"%s\"", dateAsString(startTimestamp.getValue()))); sb.append(String.format(" resetTimestamp=\"%s\"", dateAsString(resetTimestamp.getValue()))); sb.append( String.format( " firstExchangeCompletedTimestamp=\"%s\"", dateAsString(firstExchangeCompletedTimestamp.getValue()))); sb.append( String.format( " firstExchangeCompletedExchangeId=\"%s\"", nullSafe(firstExchangeCompletedExchangeId))); sb.append( String.format( " firstExchangeFailureTimestamp=\"%s\"", dateAsString(firstExchangeFailureTimestamp.getValue()))); sb.append( String.format( " firstExchangeFailureExchangeId=\"%s\"", nullSafe(firstExchangeFailureExchangeId))); sb.append( String.format( " lastExchangeCompletedTimestamp=\"%s\"", dateAsString(lastExchangeCompletedTimestamp.getValue()))); sb.append( String.format( " lastExchangeCompletedExchangeId=\"%s\"", nullSafe(lastExchangeCompletedExchangeId))); sb.append( String.format( " lastExchangeFailureTimestamp=\"%s\"", dateAsString(lastExchangeFailureTimestamp.getValue()))); sb.append( String.format( " lastExchangeFailureExchangeId=\"%s\"", nullSafe(lastExchangeFailureExchangeId))); } sb.append("/>"); return sb.toString(); }
public long getExchangesCompleted() throws Exception { return exchangesCompleted.getValue(); }
@Override public synchronized void reset() { super.reset(); exchangesCompleted.reset(); exchangesFailed.reset(); exchangesInflight.reset(); failuresHandled.reset(); redeliveries.reset(); externalRedeliveries.reset(); minProcessingTime.reset(); maxProcessingTime.reset(); totalProcessingTime.reset(); lastProcessingTime.reset(); deltaProcessingTime.reset(); meanProcessingTime.reset(); firstExchangeCompletedTimestamp.reset(); firstExchangeCompletedExchangeId = null; firstExchangeFailureTimestamp.reset(); firstExchangeFailureExchangeId = null; lastExchangeCompletedTimestamp.reset(); lastExchangeCompletedExchangeId = null; lastExchangeFailureTimestamp.reset(); lastExchangeFailureExchangeId = null; }
public long getExchangesInflight() { return exchangesInflight.getValue(); }