Android Open Source - field-data-app Biological Sample






From Project

Back to project page field-data-app.

License

The source code is released under:

MIT License

If you think the Android project field-data-app 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 nz.cri.gns.springs.db;
/*from  ww  w .java2  s.c  o  m*/
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import nz.cri.gns.springs.util.Util;
import android.util.Log;

import com.j256.ormlite.dao.CloseableIterator;
import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
 * Measurements of samples collected from geothermal features.
 * @author duncanw
 */
@DatabaseTable
public class BiologicalSample extends PersistentObject {

  private static final long serialVersionUID = -7201406858581042942L;

  @DatabaseField(foreign = true)
  private Survey survey;
  
  @DatabaseField private Integer sampleNumber;
  @DatabaseField private Double temperature;
  @DatabaseField private Double pH;
  @DatabaseField private Double orp;
  @DatabaseField private Double conductivity;
  @DatabaseField private Double dO;
  @DatabaseField private Double turbidity;
  @DatabaseField private Double dnaVolume;
  @DatabaseField private Double ferrousIronAbs;
  @DatabaseField private Double gasVolume;  
  @DatabaseField private String comments;
  @DatabaseField private Boolean soilCollected;
  @DatabaseField private Boolean waterColumnCollected;
  @DatabaseField private Double tds;
  @DatabaseField private Boolean settledAt4C;
  
  public Survey getSurvey() {
    return survey;
  }
  public void setSurvey(Survey survey) {
    this.survey = survey;
  }
  public Integer getSampleNumber() {
    return sampleNumber;
  }
  public void setSampleNumber(Integer sampleNumber) {
    this.sampleNumber = sampleNumber;
  }
  public Double getTemperature() {
    return temperature;
  }
  public void setTemperature(Double temperature) {
    this.temperature = temperature;
  }
  public Double getPh() {
    return pH;
  }
  public void setPh(Double pH) {
    this.pH = pH;
  }
  public Double getOrp() {
    return orp;
  }
  public void setOrp(Double orp) {
    this.orp = orp;
  }
  public Double getConductivity() {
    return conductivity;
  }
  public void setConductivity(Double conductivity) {
    this.conductivity = conductivity;
  }
  public Double getDo() {
    return dO;
  }
  public void setDo(Double dO) {
    this.dO = dO;
  }
  public Double getTurbidity() {
    return turbidity;
  }
  public void setTurbidity(Double turbidity) {
    this.turbidity = turbidity;
  }
  public Double getDnaVolume() {
    return dnaVolume;
  }
  public void setDnaVolume(Double dnaVolume) {
    this.dnaVolume = dnaVolume;
  }
  public Double getFerrousIronAbs() {
    return ferrousIronAbs;
  }
  public void setFerrousIronAbs(Double ferrousIronAbs) {
    this.ferrousIronAbs = ferrousIronAbs;
  }
  public Double getGasVolume() {
    return gasVolume;
  }
  public void setGasVolume(Double gasVolume) {
    this.gasVolume = gasVolume;
  }
  public String getComments() {
    return comments;
  }
  public void setComments(String comments) {
    this.comments = comments;
  }  

  public Boolean getSoilCollected() {
    return soilCollected;
  }
  public void setSoilCollected(Boolean soilCollected) {
    this.soilCollected = soilCollected;
  }
  public Boolean getWaterColumnCollected() {
    return waterColumnCollected;
  }
  public void setWaterColumnCollected(Boolean waterColumnCollected) {
    this.waterColumnCollected = waterColumnCollected;
  }
  public Double getTds() {
    return tds;
  }
  public void setTds(Double tds) {
    this.tds = tds;
  }
  public Boolean getSettledAt4C() {
    return settledAt4C;
  }
  public void setSettledAt4C(Boolean settledAt4C) {
    this.settledAt4C = settledAt4C;
  }
  /**
   * @return a tab separated string of this BiologicalSample's values. Empty strings are used
   *         for null values, numeric values are rounded to 4 decimal places.
   */
  public String toTsvString() {
    
    String comms = (comments != null) ? comments.replace("\n", " ") : null;
    return Util.join("\t", getFormattedSampleNumber(),
        Util.format(temperature), Util.format(pH), Util.format(orp),
        Util.format(conductivity), Util.format(dO),
        Util.format(turbidity), Util.format(dnaVolume),
        Util.format(ferrousIronAbs), Util.format(gasVolume),
        comms,
        Util.format(tds),
        soilCollected, waterColumnCollected, settledAt4C);
  }
  
  public static String tsvStringColumns() {
    return Util.join("\t", "SampleNumber", "SampleTemperature", "pH", "OxidationReductionPotential",
        "Conductivity", "DissolvedOxygen", "Turbidity", "DnaVolume", "FerrousIronAbs", "GasVolume", "Comments", 
        "TotalDissolvedSolids", "SoilCollected", "WaterColumnCollected", "SettledAt4oC");    
  }
  
  /**
   * @return this BiologicalSample's sample number, e.g "P1.0023"
   */
  public String getFormattedSampleNumber() {
    return formatSampleNumber(getSampleNumber());
  }
  
  /**
   * @param sampleNumber
   * @return the given number in padded to four digits with leading zeros and prefixed with "P1.".
   *         e.g 23 converts to "P1.0023".
   */
  public static String formatSampleNumber(Integer sampleNumber) {
    return "P1." + String.format("%04d", sampleNumber);
  }
  
  /**
   * @param dbHelper
   * @return the highest sample number of any BiologicalSample in the database.
   */
  public static Integer getMaxSampleNumber(SpringsDbHelper dbHelper) {
    RuntimeExceptionDao<BiologicalSample, Long> dao = dbHelper.getBiologicalSampleDao();
    try {
      return (int)dao.queryRawValue("select max(sampleNumber) from BiologicalSample");
    } catch (Exception e) {
      Log.e(BiologicalSample.class.getSimpleName(), "Error retrieving max sampleNumber", e);
      return 0;
    }
  }

  public static class CurrentSample {
    
    public Long sampleId;
    public Integer sampleNumber;
    public String featureName;
    public Long surveyDate;
    public Long featureId;
    public Long surveyId;
  }
  
  /**
   * @param dbHelper
   * @return the details of all BiologicalSamples with status NEW or UPDATED.
   */
  public static List<CurrentSample> getCurrentSamples(SpringsDbHelper dbHelper) {
    RuntimeExceptionDao<BiologicalSample, Long> dao = dbHelper.getBiologicalSampleDao();
    String query = 
        "select samp.id, samp.sampleNumber, feat.featureName, surv.surveyDate, feat.id, surv.id " + 
        "from BiologicalSample samp " +
        "left join Survey surv on samp.survey_id = surv.id " + 
          "left join Feature feat on surv.feature_id = feat.id " +
        "where samp.status in (?, ?)";
    
    DataType[] columnTypes = {DataType.LONG, DataType.INTEGER, DataType.STRING, DataType.LONG, DataType.LONG, DataType.LONG};
    
    GenericRawResults<Object[]> results = dao.queryRaw(query, columnTypes, Status.NEW.name(), Status.UPDATED.name());
    try {
      List<Object[]> rows = results.getResults();
      List<CurrentSample> sampleList = new ArrayList<CurrentSample>(rows.size());
      for (Object[] row : rows) {
        CurrentSample sample = new CurrentSample();
        sample.sampleId = (Long)row[0];
        sample.sampleNumber = (Integer)row[1];
        sample.featureName = (String)row[2];
        sample.surveyDate = (Long)row[3];
        sample.featureId = (Long)row[4];
        sample.surveyId = (Long)row[5];
        sampleList.add(sample);
      }
      
      return sampleList;
      
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
  
  public static List<BiologicalSample> getAll(SpringsDbHelper dbHelper) {
    
    RuntimeExceptionDao<BiologicalSample, Long> dao = dbHelper.getBiologicalSampleDao();
    List<BiologicalSample> sampleList = new LinkedList<BiologicalSample>();
    CloseableIterator<BiologicalSample> iterator = dao.closeableIterator();
    try {
        while (iterator.hasNext()) {
          sampleList.add(iterator.next());
        }
    } finally {
        try {
        iterator.close();
      } catch (SQLException e) {
        throw new RuntimeException(e);
      }
    }
    
    return sampleList;
  }  
}




Java Source Code List

nz.cri.gns.springs.GpsLocation.java
nz.cri.gns.springs.SpringsApplication.java
nz.cri.gns.springs.activity.BioSampleActivity.java
nz.cri.gns.springs.activity.EditBiologicalSamplesActivity.java
nz.cri.gns.springs.activity.MainMenuActivity.java
nz.cri.gns.springs.activity.ManageBioSamplesActivity.java
nz.cri.gns.springs.activity.SettingsActivity.java
nz.cri.gns.springs.db.BiologicalSampleTest.java
nz.cri.gns.springs.db.BiologicalSample.java
nz.cri.gns.springs.db.ChecklistItem.java
nz.cri.gns.springs.db.Configuration.java
nz.cri.gns.springs.db.FeatureTest.java
nz.cri.gns.springs.db.Feature.java
nz.cri.gns.springs.db.PersistentObject.java
nz.cri.gns.springs.db.SpringsDbHelper.java
nz.cri.gns.springs.db.SurveyImage.java
nz.cri.gns.springs.db.SurveyTest.java
nz.cri.gns.springs.db.Survey.java
nz.cri.gns.springs.fragments.AppearanceFragment.java
nz.cri.gns.springs.fragments.BioSampleActivityFragment.java
nz.cri.gns.springs.fragments.BioSampleFragment.java
nz.cri.gns.springs.fragments.ChooseImageFragment.java
nz.cri.gns.springs.fragments.ExportSamplesFragment.java
nz.cri.gns.springs.fragments.FeatureIdFragment.java
nz.cri.gns.springs.fragments.ImageColourPickerFragment.java
nz.cri.gns.springs.fragments.ImageFragment.java
nz.cri.gns.springs.fragments.SpringsDialogFragment.java
nz.cri.gns.springs.fragments.SpringsFragment.java
nz.cri.gns.springs.util.CustomExceptionHandler.java
nz.cri.gns.springs.util.DataStatistics.java
nz.cri.gns.springs.util.DateTimePickerDialog.java
nz.cri.gns.springs.util.UiUtil.java
nz.cri.gns.springs.util.Util.java