mysql
Class HistorySql

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by mysql.AbstractSql
                  extended by mysql.HistorySql
All Implemented Interfaces:
Cloneable, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class HistorySql
extends AbstractSql

A class that allows static access to a database containing observational history of a target. It allows restoring history of a target on SCS restart as well as information retrieval for JStella. In the default setup, the table of this database is called 'done' and has the following structure:

 CREATE TABLE "done" (
    "objid" varchar(255),
    "object" varchar(255) UNIQUE,
    "start" timestamp without time zone NOT NULL,
    "duration" integer,
    "success" boolean,
    "merrit" real,
 
    Constraint "done_pkey" Primary Key ("start")
    );
 
    GRANT ALL on "done" to "postgres";
    GRANT ALL on "done" to "stella";
    GRANT SELECT on "done" to "guest";
 
In this setup, the columns have the following meanings: The idea of this class is to allow static access from various sides to the history without the need of producing individual db clients.


Nested Class Summary
static class HistorySql.GridFix
          Fixes wrong enries entered between 2008-10-17 15:28:30 and 2008-12-18 08:55:47, when the done table was writtn to early due to GRID timeline visibilities.
static class HistorySql.PilarPointing
          We add total pointing model offsets from Pilar save files to the history db.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static String DEFDATEFIELD
          The default target name field in the database
private static String DEFDURATIONFIELD
          The default target name field in the database
private static String DEFFIRSTALTFIELD
          The key to the first azimuth offset in the database.
private static String DEFFIRSTAZFIELD
          The key to the first azimuth offset in the database.
private static String DEFMERITFIELD
          The default target name field in the database
private static String DEFSUCCESSFIELD
          The default target name field in the database
private static String DEFTABLE
          The default table name.
private static String DEFTARGETNAMEFIELD
          The default target name field in the database
private static String DEFTELESCOPEFIELD
          The default target name field in the database
private static String DEFTOTALAZFIELD
          The key to the first azimuth offset in the database.
private static String DEFTOTALZFIELD
          The key to the first azimuth offset in the database.
private static String DEFUNIQUEFIELD
          The default target name field in the database
static String KEY_DATEFIELD
          The key to the target name in the database.
static String KEY_DURATIONFIELD
          The key to the target name in the database.
static String KEY_FIRSTALTFIELD
          The key to the first azimuth offset in the database.
static String KEY_FIRSTAZFIELD
          The key to the first azimuth offset in the database.
static String KEY_MERITFIELD
          The key to the target name in the database.
static String KEY_SUCCESSFIELD
          The key to the target name in the database.
static String KEY_TARGETNAMEFIELD
          The key to the target name in the database.
static String KEY_TELESCOPEFIELD
          The key to the target name in the database.
static String KEY_TOTALAZFIELD
          The key to the first azimuth offset in the database.
static String KEY_TOTALZFIELD
          The key to the first azimuth offset in the database.
static String KEY_UNIQUEFIELD
          The key to the target name in the database.
 
Fields inherited from class mysql.AbstractSql
KEY_TABLE
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
HistorySql(Map<String,String> prop)
          Constructs a new history database.
 
Method Summary
 boolean addFirstOffsets(String unique, Vector2D degoff)
          After a successful acquire, the first offset encountered is writtn to the database.
 boolean addHistoryPickToDatabase(String targetname, boolean success, Date start, long duration, String unique, double merit, String idtelescope)
          Adds a history entry to the database.
 boolean addHistoryPickToDatabase(TargetDefinition target, boolean success, Date start, long duration, String unique, double merit, String idtelescope)
          Adds a history entry to the database.
 boolean addTotalOffsets(String unique, Vector2D degoff)
          After a successful acquire, the total offset encountered is writtn to the database.
 HistoryAware.Pick getFirstFailure(String tel, String name)
          Returns the first succesful pick.
 HistoryAware.Pick getFirstSuccess(String tel, String name)
          Returns the first succesful pick.
 List<HistoryAware.Pick> getHistoryFromDatabase(String telescope, String name, int maxlen)
          Scans a database for the history.
 Map<String,List<HistoryAware.Pick>> getHistoryPicks(String idtel, Date from, Date to)
          Returns a list of HistoryAware.Picks of all targets that have been picked between the given dates.
 HistoryAware.Pick getLastFailure(String tel, String name)
          Returns the first succesful pick.
 HistoryAware.Pick getLastSuccess(String tel, String name)
          Returns the first succesful pick.
static HistoryAware.Pick getPickFromUnique(String uniq)
          Returns a single history pick from the db by specifying the unique TARGET id of the pick.
static HistoryAware.Pick getPickFromUnique(String uniq, String datekey, String durkey, String merkey, String suckey, String uniqkey, String targetkey)
          Returns a single history pick from the db by specifying the unique target id of the pick plus all field names.
private  HistoryAware.Pick getSinglePick(String tel, String name, boolean succ, char order)
           
 boolean removeHistoryPickFromDatabase(String unique)
          Removes a entry from the history db if the unique specifier is given.
private static HistoryAware.Pick retrievePick(ResultSet history, String datekey, String durationkey, String meritkey, String successkey, String uniquekey, String targetkey)
          Converts the current row in the result set into a history pick.
 boolean updateHistoryPick(String unique, boolean to)
          Updates the success flag of the pick with the given unique identifier.
 
Methods inherited from class mysql.AbstractSql
getPassword, getTable, getUserName, init, isEntry
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

KEY_TARGETNAMEFIELD

public static final String KEY_TARGETNAMEFIELD
The key to the target name in the database.

See Also:
Constant Field Values

KEY_UNIQUEFIELD

public static final String KEY_UNIQUEFIELD
The key to the target name in the database.

See Also:
Constant Field Values

KEY_DATEFIELD

public static final String KEY_DATEFIELD
The key to the target name in the database.

See Also:
Constant Field Values

KEY_DURATIONFIELD

public static final String KEY_DURATIONFIELD
The key to the target name in the database.

See Also:
Constant Field Values

KEY_SUCCESSFIELD

public static final String KEY_SUCCESSFIELD
The key to the target name in the database.

See Also:
Constant Field Values

KEY_MERITFIELD

public static final String KEY_MERITFIELD
The key to the target name in the database.

See Also:
Constant Field Values

KEY_TELESCOPEFIELD

public static final String KEY_TELESCOPEFIELD
The key to the target name in the database.

See Also:
Constant Field Values

KEY_FIRSTAZFIELD

public static final String KEY_FIRSTAZFIELD
The key to the first azimuth offset in the database.

See Also:
Constant Field Values

KEY_FIRSTALTFIELD

public static final String KEY_FIRSTALTFIELD
The key to the first azimuth offset in the database.

See Also:
Constant Field Values

KEY_TOTALAZFIELD

public static final String KEY_TOTALAZFIELD
The key to the first azimuth offset in the database.

See Also:
Constant Field Values

KEY_TOTALZFIELD

public static final String KEY_TOTALZFIELD
The key to the first azimuth offset in the database.

See Also:
Constant Field Values

DEFTABLE

private static final String DEFTABLE
The default table name.

See Also:
Constant Field Values

DEFTARGETNAMEFIELD

private static final String DEFTARGETNAMEFIELD
The default target name field in the database

See Also:
Constant Field Values

DEFUNIQUEFIELD

private static final String DEFUNIQUEFIELD
The default target name field in the database

See Also:
Constant Field Values

DEFDATEFIELD

private static final String DEFDATEFIELD
The default target name field in the database

See Also:
Constant Field Values

DEFDURATIONFIELD

private static final String DEFDURATIONFIELD
The default target name field in the database

See Also:
Constant Field Values

DEFSUCCESSFIELD

private static final String DEFSUCCESSFIELD
The default target name field in the database

See Also:
Constant Field Values

DEFMERITFIELD

private static final String DEFMERITFIELD
The default target name field in the database

See Also:
Constant Field Values

DEFTELESCOPEFIELD

private static final String DEFTELESCOPEFIELD
The default target name field in the database

See Also:
Constant Field Values

DEFFIRSTAZFIELD

private static final String DEFFIRSTAZFIELD
The key to the first azimuth offset in the database.

See Also:
Constant Field Values

DEFFIRSTALTFIELD

private static final String DEFFIRSTALTFIELD
The key to the first azimuth offset in the database.

See Also:
Constant Field Values

DEFTOTALAZFIELD

private static final String DEFTOTALAZFIELD
The key to the first azimuth offset in the database.

See Also:
Constant Field Values

DEFTOTALZFIELD

private static final String DEFTOTALZFIELD
The key to the first azimuth offset in the database.

See Also:
Constant Field Values
Constructor Detail

HistorySql

public HistorySql(Map<String,String> prop)
Constructs a new history database.

Method Detail

getPickFromUnique

public static HistoryAware.Pick getPickFromUnique(String uniq)
                                           throws SQLException,
                                                  ConnectException
Returns a single history pick from the db by specifying the unique TARGET id of the pick.

Parameters:
uniq - The unique target id, i.e. without exposure ID.
Throws:
SQLException
ConnectException

getPickFromUnique

public static HistoryAware.Pick getPickFromUnique(String uniq,
                                                  String datekey,
                                                  String durkey,
                                                  String merkey,
                                                  String suckey,
                                                  String uniqkey,
                                                  String targetkey)
                                           throws SQLException,
                                                  ConnectException
Returns a single history pick from the db by specifying the unique target id of the pick plus all field names.

Parameters:
uniq - The unique target id, i.e. without exposure ID.
datekey - The name of the date column.
durkey - The name of the duration column.
merkey - The name of the merit column.
suckey - The name of the successful column.
uniqkey - The name of the column holding the unique target ID.
Throws:
SQLException
ConnectException

removeHistoryPickFromDatabase

public final boolean removeHistoryPickFromDatabase(String unique)
Removes a entry from the history db if the unique specifier is given. This will always delete a single entry, as the unique field is truely unique. If for whatever reason more than a single entry match the delete query, it is not executed.

Returns:
True If a single pick was removed from the database.

addHistoryPickToDatabase

public final boolean addHistoryPickToDatabase(TargetDefinition target,
                                              boolean success,
                                              Date start,
                                              long duration,
                                              String unique,
                                              double merit,
                                              String idtelescope)
Adds a history entry to the database.


addHistoryPickToDatabase

public final boolean addHistoryPickToDatabase(String targetname,
                                              boolean success,
                                              Date start,
                                              long duration,
                                              String unique,
                                              double merit,
                                              String idtelescope)
Adds a history entry to the database.


updateHistoryPick

public final boolean updateHistoryPick(String unique,
                                       boolean to)
Updates the success flag of the pick with the given unique identifier. Used on rating targets.

Returns:
True, if the unique field was present.

getHistoryPicks

public Map<String,List<HistoryAware.Pick>> getHistoryPicks(String idtel,
                                                           Date from,
                                                           Date to)
Returns a list of HistoryAware.Picks of all targets that have been picked between the given dates.

Returns:
A mapping of target identifier to list of picks.

getFirstSuccess

public final HistoryAware.Pick getFirstSuccess(String tel,
                                               String name)
Returns the first succesful pick.


getFirstFailure

public final HistoryAware.Pick getFirstFailure(String tel,
                                               String name)
Returns the first succesful pick.


getLastSuccess

public final HistoryAware.Pick getLastSuccess(String tel,
                                              String name)
Returns the first succesful pick.


getLastFailure

public final HistoryAware.Pick getLastFailure(String tel,
                                              String name)
Returns the first succesful pick.


getSinglePick

private final HistoryAware.Pick getSinglePick(String tel,
                                              String name,
                                              boolean succ,
                                              char order)

getHistoryFromDatabase

public final List<HistoryAware.Pick> getHistoryFromDatabase(String telescope,
                                                            String name,
                                                            int maxlen)
Scans a database for the history.


addFirstOffsets

public boolean addFirstOffsets(String unique,
                               Vector2D degoff)
After a successful acquire, the first offset encountered is writtn to the database. As the entry must have a non-null date field, only updates are possible.
The recorded offsets should have a random distribution, with an RMS equal to the RMS of the pointing model. If tendencies are observed, this may call for a update of the pointing model.


addTotalOffsets

public boolean addTotalOffsets(String unique,
                               Vector2D degoff)
After a successful acquire, the total offset encountered is writtn to the database. This could be used to recalculate the pointing model.


retrievePick

private static HistoryAware.Pick retrievePick(ResultSet history,
                                              String datekey,
                                              String durationkey,
                                              String meritkey,
                                              String successkey,
                                              String uniquekey,
                                              String targetkey)
                                       throws SQLException
Converts the current row in the result set into a history pick. The resutl set must be pointing to a valid row.

Throws:
SQLException