public bool CheckExistanceOfTimeSeries(int variableID, int siteID, DateTime start, DateTime end) { string slctcmd = "select ValueID from " + Configuration.DataValuesTableName + " where VariableID =" + variableID + " and SiteID=" + siteID + " and " + DBFieldFormater.FormatDateTime("DateTimeUTC", start, end, mDbase.DBKind); return(mDbase.Exists(slctcmd)); }
public void SaveTimeSeries(DataCube <double> ts, int variableID, int siteID) { DateTime start = ts.DateTimes.Min(); DateTime end = ts.DateTimes.Max(); string delcmd = "delete from " + Configuration.DataValuesTableName + " where VariableID =" + variableID + " and SiteID=" + siteID + " and " + DBFieldFormater.FormatDateTime("DateTimeUTC", start, end, mDbase.DBKind); if (mDbase.CreateNonQueryCommand(delcmd)) { int i = 0; foreach (DateTime t in ts.DateTimes) { string insertcmd = ""; if (mDbase.DBKind == DBkind.Access2003 || mDbase.DBKind == DBkind.Access2007) { insertcmd = "insert into " + Configuration.DataValuesTableName + " (DataValue,DateTimeUTC,SiteID,VariableID) values(" + ts[0, i, 0] + ",'" + t + "'," + siteID + "," + variableID + ")"; } else { insertcmd = "insert into " + Configuration.DataValuesTableName + " (DataValue,DateTimeUTC,SiteID,VariableID) values(" + ts[0, i, 0] + "," + t + "," + siteID + "," + variableID + ")"; } mDbase.CreateNonQueryCommand(insertcmd); if (SavingTimeSeries != null) { SavingTimeSeries(this, new ProgressEvent(i)); } i++; } } }
public bool DeleteTimeSeries(DateTime start, DateTime end, int variableID, int siteID) { string delcmd = "delete from " + Configuration.DataValuesTableName + " where VariableID =" + variableID + " and SiteID=" + siteID + " and " + DBFieldFormater.FormatDateTime("DateTimeUTC", start, end, mDbase.DBKind); return(mDbase.CreateNonQueryCommand(delcmd)); }
public DataCube <double> GetTransformedTimeSeries(ITimeSeriesQueryCriteria qc, double multiplier) { DataCube <double> ts = null; if (qc != null) { string sql = "select * from " + Configuration.DataValuesTableName + " where VariableID =" + qc.VariableID + " and SiteID=" + qc.SiteID + " and " + DBFieldFormater.FormatDateTime("DateTimeUTC", qc.Start, qc.End, mDbase.DBKind); DataTable dt = mDbase.QueryDataTable(sql); if (dt != null) { double[] dv = dt.AsEnumerable().Select(row => row.Field <double>("DataValue")).ToArray(); DateTime[] dtime = dt.AsEnumerable().Select(row => row.Field <DateTime>("DateTimeUTC")).ToArray(); ts = new DataCube <double>(dv, dtime); Variable variable = GetVariableInfo(qc.VariableID); DataRepairer dr = new DataRepairer(variable.NoDataValue); dr.Repair(ts, multiplier); } } return(ts); }
public DataTable GetDataValues(ITimeSeriesQueryCriteria qc) { string sql = ""; if (qc != null) { if (qc.Start == DateTime.MinValue || qc.End == DateTime.MinValue) { sql = "select ValueID,DateTimeUTC,DataValue from " + Configuration.DataValuesTableName + " where VariableID =" + qc.VariableID + " and SiteID=" + qc.SiteID; } else { sql = "select ValueID,DateTimeUTC,DataValue from " + Configuration.DataValuesTableName + " where VariableID =" + qc.VariableID + " and SiteID=" + qc.SiteID + " and " + DBFieldFormater.FormatDateTime("DateTimeUTC", qc.Start, qc.End, mDbase.DBKind); } return(mDbase.QueryDataTable(sql)); } else { return(null); } }