Android Open Source - L5RHelper Histogram






From Project

Back to project page L5RHelper.

License

The source code is released under:

Copyright (c) 2010 Robert Uhl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Sof...

If you think the Android project L5RHelper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.uhl.calc;
/*  w  ww. j ava  2 s .c  o m*/
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;

import android.content.Context;
import android.database.Cursor;

import com.uhl.db.DBHelper;

public class Histogram {

  private int[] histogram;
  private static final int SCALING_FACTOR = 10000;

  public Histogram(byte[] data) {
    LoadHistogram(data);
  }

  public Histogram(Roll roll, Context ctx) {
    DBHelper db = new DBHelper(ctx);
    Cursor cursor = db.getHistogram(roll);
    LoadHistogram(cursor.getBlob(0));
    db.close();
    cursor.close();
  }

  private void LoadHistogram(byte[] data) {
    int[] result = new int[0];
    ByteArrayInputStream bIn = new ByteArrayInputStream(data);
    ObjectInputStream in;
    try {
      in = new ObjectInputStream(bIn);
      result = (int[]) in.readObject();
    } catch (Exception e) {
      e.printStackTrace();
    }
    this.histogram = result;
  }

  public int getHighestTN(int confidence) {
    int result = 0;
    int targetValue = (Histogram.SCALING_FACTOR - confidence
        * (Histogram.SCALING_FACTOR / 100));
    if (this.histogram.length == 0)
      return result;
    int accum = 0;
    while (targetValue > accum) {
      result++;
      accum += this.histogram[result];
    }
    return result;
  }

  public double[] getRangeRaises(int range, int tn) {
    double[] result = new double[1+range*2];
    if (this.histogram.length == 0)
      return null;
    int count = 0;
    int accum = 0;
    int tnval = 0;
    while (count < result.length) {      
      accum += this.histogram[tnval];
      while(tnval >= (count*5+(tn-range*5))){
        result[count] = 100.0-((double)accum)/(double)Histogram.SCALING_FACTOR*100.0;
        count++;
      }      
      tnval++;    
    }
    return result;
    
  }
}




Java Source Code List

com.uhl.CasterRollCalculateActivity.java
com.uhl.EditCharacterActivity.java
com.uhl.EditTemplateActivity.java
com.uhl.HomeActivity.java
com.uhl.L5RUtilites.java
com.uhl.LoadProfileView.java
com.uhl.ManageTemplateView.java
com.uhl.MeleeRollCalculateActivity.java
com.uhl.ProfileOverviewActivity.java
com.uhl.calc.Histogram.java
com.uhl.calc.Raises.java
com.uhl.calc.Roll.java
com.uhl.db.DBHelper.java
com.uhl.db.DBServiceLocator.java
com.uhl.db.DefaultViews.java
com.uhl.db.IDBHelper.java
com.uhl.db.Profile.java
com.uhl.db.Record.java
com.uhl.db.Template.java