Skip to content

Commit

Permalink
Merge pull request #413 from squaregoldfish/master
Browse files Browse the repository at this point in the history
Alpha 1.01
  • Loading branch information
squaregoldfish authored Mar 27, 2017
2 parents 2239b71 + 8916730 commit b1859fb
Show file tree
Hide file tree
Showing 15 changed files with 584 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static List<CalibrationCoefficients> initCalibrationCoefficients(Instrume
*
* @param coefficients The list of {@code CalibrationCoefficients} objects to be searched.
* @param code The {@code SensorCode} for the desired sensor.
* @return The {@code CalibrationCoefficients} object for the supplied {@code SensorCode}, or {@code null} if no matching object can be found.
* @return The {@code CalibrationCoefficients} object for the supplied {@code SensorCode}, or {@code null} if no matching coefficients can be found.
*/
public static CalibrationCoefficients findSensorCoefficients(List<CalibrationCoefficients> coefficients, SensorCode code) {
CalibrationCoefficients result = null;
Expand Down
2 changes: 1 addition & 1 deletion WebApp/src/uk/ac/exeter/QuinCe/data/ExportConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public List<ExportOption> getOptions() {
* </p>
*
* <p>
* This method will throw an (@link ArrayIndexOutOfBoundsException} if the specified index is outside the range
* This method will throw an {@link ArrayIndexOutOfBoundsException} if the specified index is outside the range
* of the list of export options.
* </p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public class DataReductionDB {

/**
* Statement to remove all data reduction data for a given data file
* @see #clearDataReductionData(Connection, long)
*/
private static final String CLEAR_DATA_REDUCTION_STATEMENT = "DELETE FROM data_reduction WHERE data_file_id = ?";

/**
* Statement to store a data reduction calculation result in the database for a given row in a given data file
* @see #storeRow(Connection, long, int, boolean, int, double, double, double, double, double, double, double, double, double, double, double, double, double)
*/
private static final String STORE_ROW_STATEMENT = "INSERT INTO data_reduction ("
+ "data_file_id, row, co2_type, mean_intake_temp, mean_salinity, mean_eqt, delta_temperature, mean_eqp, "
Expand All @@ -37,6 +39,7 @@ public class DataReductionDB {

/**
* Statement to update a data reduction calculation result for a given row in a given data file
* @see #storeRow(Connection, long, int, boolean, int, double, double, double, double, double, double, double, double, double, double, double, double, double)
*/
private static final String UPDATE_ROW_STATEMENT = "UPDATE data_reduction SET "
+ "mean_intake_temp = ?, mean_salinity = ?, mean_eqt = ?, delta_temperature = ?, mean_eqp = ?, "
Expand All @@ -46,6 +49,7 @@ public class DataReductionDB {

/**
* Query to retrieve the data reduction result for a given row in a given data file
* @see #rowExists(Connection, long, int)
*/
private static final String FIND_ROW_STATEMENT = "SELECT COUNT(*) FROM data_reduction WHERE data_file_id = ? AND row = ?";

Expand All @@ -54,6 +58,7 @@ public class DataReductionDB {
* @param dataSource A data source
* @param fileId The database ID of the data file
* @throws DatabaseException If a database error occurs
* @see #clearDataReductionData(Connection, long)
*/
public static void clearDataReductionData(DataSource dataSource, long fileId) throws DatabaseException {
Connection conn = null;
Expand All @@ -73,6 +78,7 @@ public static void clearDataReductionData(DataSource dataSource, long fileId) th
* @param conn A database connection
* @param fileId The database ID of the data file
* @throws DatabaseException If a database error occurs
* @see #CLEAR_DATA_REDUCTION_STATEMENT
*/
public static void clearDataReductionData(Connection conn, long fileId) throws DatabaseException {

Expand Down Expand Up @@ -118,6 +124,8 @@ public static void clearDataReductionData(Connection conn, long fileId) throws D
* @param fco2 The fugacity of CO<sub>2</sub> at the sea surface temperature (the final result of the calculation)
* @throws DatabaseException If a database error occurs
* @throws MissingParamException If any of the parameters are missing
* @see #STORE_ROW_STATEMENT
* @see #UPDATE_ROW_STATEMENT
*/
public static void storeRow(Connection conn, long fileId, int row, boolean overwrite,
int co2Type, double meanIntakeTemp, double meanSalinity, double meanEqt, double deltaTemperature, double meanEqp,
Expand Down Expand Up @@ -191,6 +199,7 @@ public static void storeRow(Connection conn, long fileId, int row, boolean overw
* @param row The row number
* @return {@code true} if a result has been stored for this row; {@code false} otherwise
* @throws DatabaseException If a database error occurs
* @see #FIND_ROW_STATEMENT
*/
private static boolean rowExists(Connection conn, long fileId, int row) throws DatabaseException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ public class CalibrationDB {

/**
* Statement for creating a sensor calibration parent record
* @see #addCalibration(DataSource, long, Date, List)
*/
private static final String CREATE_CALIBRATION_STATEMENT = "INSERT INTO sensor_calibration ("
+ "instrument_id, calibration_date) VALUES (?, ?)";

/**
* Statement for creating the coefficients record for a specific sensor within
* a calibration
* @see #addCalibration(DataSource, long, Date, List)
* @see #updateCalibration(DataSource, long, Date, List)
*/
private static final String CREATE_COEFFICIENTS_STATEMENT = "INSERT INTO calibration_coefficients ("
+ "calibration_id, sensor, intercept, x, x2, x3, x4, x5) "
Expand All @@ -49,50 +52,62 @@ public class CalibrationDB {
/**
* Statement for retrieving the list of calibrations for a given instrument.
* The list is ordered by descending date.
* @see #getCalibrationList(DataSource, long)
*/
private static final String GET_CALIBRATION_LIST_QUERY = "SELECT id, calibration_date FROM "
+ "sensor_calibration WHERE instrument_id = ? ORDER BY calibration_date DESC";

/**
* Statement for retrieving the calibration stub details for a given calibration
* @see #getCalibrationStub(DataSource, long)
*/
private static final String GET_CALIBRATION_STUB_QUERY = "SELECT id, instrument_id, calibration_date FROM "
+ "sensor_calibration WHERE id = ?";

/**
* Statement for retrieving the calibration coefficients for a given calibration
* @see #getCalibrationCoefficients(DataSource, CalibrationStub)
*/
private static final String GET_COEFFICIENTS_QUERY = "SELECT sensor, intercept, x, x2, x3, x4, x5 FROM "
+ "calibration_coefficients WHERE calibration_id = ? ORDER BY sensor ASC";

/**
* Statement to change the date for a given calibration
* @see #updateCalibration(DataSource, long, Date, List)
*/
private static final String UPDATE_CALIBRATION_STATEMENT = "UPDATE sensor_calibration SET calibration_date = ? WHERE id = ?";

/**
* Statement to remove all calibration coefficients for a given calibration.
* This is used prior to adding the revised coefficients.
* @see #deleteCalibration(DataSource, long)
* @see #updateCalibration(DataSource, long, Date, List)
*/
private static final String REMOVE_COEFFICIENTS_STATEMENT = "DELETE FROM calibration_coefficients WHERE calibration_id = ?";

/**
* Statement for finding a calibration record with a given ID
* @see #calibrationExists(Connection, long)
*/
private static final String FIND_CALIBRATION_QUERY = "SELECT id FROM sensor_calibration WHERE id = ?";

/**
* Statement for removing a calibration record.
* @see #deleteCalibration(DataSource, long)
*/
private static final String REMOVE_CALIBRATION_STATEMENT = "DELETE FROM sensor_calibration WHERE id = ?";

/**
* Statement to find calibration dates between two given dates
* @see #getCalibrationDatesBetween(DataSource, long, Calendar, Calendar)
* @see #getCalibrationsForFile(DataSource, long, Calendar, Calendar)
*/
private static final String GET_CALIBRATIONS_BETWEEN_QUERY = "SELECT id, calibration_date FROM sensor_calibration WHERE instrument_id = ? AND calibration_date > ? AND calibration_date <= ? ORDER BY calibration_date ASC";

/**
* Statement to find the latest calibration date before a given date
* @see #getCalibrationDateBefore(DataSource, long, Calendar)
* @see #getCalibrationsForFile(DataSource, long, Calendar, Calendar)
*/
private static final String GET_CALIBRATION_BEFORE_QUERY = "SELECT id, calibration_date FROM sensor_calibration WHERE instrument_id = ? AND calibration_date <= ? ORDER BY calibration_date DESC LIMIT 1";

Expand All @@ -104,6 +119,8 @@ public class CalibrationDB {
* @param coefficients The calibration coefficients for each of the instrument's sensors
* @throws MissingParamException If any of the parameters are missing
* @throws DatabaseException If an error occurs while creating the database records
* @see #CREATE_CALIBRATION_STATEMENT
* @see #CREATE_COEFFICIENTS_STATEMENT
*/
public static void addCalibration(DataSource dataSource, long instrumentID, Date calibrationDate, List<CalibrationCoefficients> coefficients) throws MissingParamException, DatabaseException {

Expand Down Expand Up @@ -178,6 +195,7 @@ public static void addCalibration(DataSource dataSource, long instrumentID, Date
* @throws MissingParamException If any of the parameters are missing
* @throws DatabaseException If an error occurs while retrieving the list
* @see CalibrationStub
* @see #GET_CALIBRATION_LIST_QUERY
*/
public static List<CalibrationStub> getCalibrationList(DataSource dataSource, long instrumentID) throws MissingParamException, DatabaseException {
MissingParam.checkMissing(dataSource, "dataSource");
Expand Down Expand Up @@ -220,7 +238,7 @@ public static List<CalibrationStub> getCalibrationList(DataSource dataSource, lo
* @throws MissingParamException If any of the parameters are missing
* @throws DatabaseException If an error occurs while retrieving the stub
* @throws RecordNotFoundException If the calibration ID does not exist in the database
* @see CalibrationStub
* @see #GET_CALIBRATION_STUB_QUERY
*/
public static CalibrationStub getCalibrationStub(DataSource dataSource, long calibrationID) throws MissingParamException, DatabaseException, RecordNotFoundException {

Expand Down Expand Up @@ -266,7 +284,7 @@ public static CalibrationStub getCalibrationStub(DataSource dataSource, long cal
* @throws MissingParamException If any of the parameters are {@code null}
* @throws RecordNotFoundException If the specified calibration does not exist in the database
* @throws DatabaseException If a database error occurs
* @see CalibrationStub
* @see #GET_COEFFICIENTS_QUERY
*/
public static List<CalibrationCoefficients> getCalibrationCoefficients(DataSource dataSource, CalibrationStub calibration) throws MissingParamException, RecordNotFoundException, DatabaseException {

Expand Down Expand Up @@ -325,6 +343,9 @@ public static List<CalibrationCoefficients> getCalibrationCoefficients(DataSourc
* @throws MissingParamException If any of the required parameters are missing
* @throws DatabaseException If a database error occurs
* @throws RecordNotFoundException If the specified calibration database ID does not exist
* @see #UPDATE_CALIBRATION_STATEMENT
* @see #REMOVE_COEFFICIENTS_STATEMENT
* @see #CREATE_COEFFICIENTS_STATEMENT
*/
public static void updateCalibration(DataSource dataSource, long calibrationID, Date calibrationDate, List<CalibrationCoefficients> coefficients) throws MissingParamException, DatabaseException, RecordNotFoundException {

Expand Down Expand Up @@ -397,6 +418,7 @@ public static void updateCalibration(DataSource dataSource, long calibrationID,
* @return {@code true} if the calibration exists; {@code false} if it does not.
* @throws MissingParamException If any of the parameters are missing
* @throws DatabaseException If an error occurs while searching the database
* @see #FIND_CALIBRATION_QUERY
*/
private static boolean calibrationExists(Connection conn, long calibrationID) throws MissingParamException, DatabaseException {

Expand Down Expand Up @@ -432,6 +454,8 @@ private static boolean calibrationExists(Connection conn, long calibrationID) th
* @param calibrationID The calibration ID
* @throws MissingParamException If any of the parameters are missing
* @throws DatabaseException If a database error occurs
* @see #REMOVE_COEFFICIENTS_STATEMENT
* @see #REMOVE_CALIBRATION_STATEMENT
*/
public static void deleteCalibration(DataSource dataSource, long calibrationID) throws MissingParamException, DatabaseException {

Expand Down Expand Up @@ -476,6 +500,7 @@ public static void deleteCalibration(DataSource dataSource, long calibrationID)
* @return A list of calibration dates
* @throws MissingParamException If any of the parameters are missing
* @throws DatabaseException If an error occurs while retrieving the dates
* @see #GET_CALIBRATIONS_BETWEEN_QUERY
*/
public static List<Calendar> getCalibrationDatesBetween(DataSource dataSource, long instrumentID, Calendar firstDate, Calendar lastDate) throws MissingParamException, DatabaseException {

Expand Down Expand Up @@ -522,6 +547,7 @@ public static List<Calendar> getCalibrationDatesBetween(DataSource dataSource, l
* @return The last calibration date before the given date. If there is no date, returns null.
* @throws MissingParamException If any of the parameters are missing
* @throws DatabaseException If an error occurs while retrieving the date.
* @see #GET_CALIBRATION_BEFORE_QUERY
*/
public static Calendar getCalibrationDateBefore(DataSource dataSource, long instrumentID, Calendar date) throws MissingParamException, DatabaseException {
MissingParam.checkMissing(dataSource, "dataSource");
Expand Down Expand Up @@ -558,11 +584,11 @@ public static Calendar getCalibrationDateBefore(DataSource dataSource, long inst
/**
* <p>Return the list of instrument calibrations that encompass a given data file, provided as the first and last record
* dates in that file. The calibrations returned include all those that happened during the file's duration, as well as
* the calibration immeditately preceding the file's first record, as that will be the calibration in place for the first
* the calibration immediately preceding the file's first record, as that will be the calibration in place for the first
* record(s).</p>
*
* <p>The calibrations are returned as {@link CalibrationStub} objects, which contain the basic details
* of the calibration, but notthe calibration coefficients for the instrument's sensors.
* of the calibration, but not the calibration coefficients for the instrument's sensors.
* These can be retrieved using the {@link #getCalibrationCoefficients(DataSource, CalibrationStub)} method.</p>
*
* @param dataSource A data source
Expand All @@ -573,7 +599,8 @@ public static Calendar getCalibrationDateBefore(DataSource dataSource, long inst
* @throws MissingParamException If any of the parameters are missing
* @throws DatabaseException If a database error occurs
* @throws InstrumentException If there is no calibration preceding the start of the data file
* @see CalibrationStub
* @see #GET_CALIBRATIONS_BETWEEN_QUERY
* @see #GET_CALIBRATION_BEFORE_QUERY
*/
public static List<CalibrationStub> getCalibrationsForFile(DataSource dataSource, long instrumentId, Calendar startDate, Calendar endDate) throws MissingParamException, DatabaseException, InstrumentException {

Expand Down
Loading

0 comments on commit b1859fb

Please sign in to comment.