/// <summary> /// Initialize the gym with the specified properties. /// </summary> /// <param name="log">Specifies the output log to use.</param> /// <param name="properties">Specifies the properties containing Gym specific initialization parameters.</param> /// <remarks> /// The DataGym uses the following initialization properties. /// /// 'DbSettings' - returns the database settings based on the QUERY_TYPE used. /// 'DbSchema' - returns the database schema. /// </remarks> public void Initialize(Log log, PropertySet properties) { m_log = log; m_random = new CryptoRandom(); m_db = new MyCaffeStreamDatabase(m_log); m_db.Initialize(QUERY_TYPE.GENERAL, properties.ToString()); m_db.Reset(); }
public void TestQuerySimpleDualDifferentEndAndReset() { PreTest.Init(); Log log = new Log("Test streaming database"); log.EnableTrace = true; IXStreamDatabase db = new MyCaffeStreamDatabase(log); try { string strSchema = "ConnectionCount=2;"; string strParam1 = "Connection=TestCon;Table=TestTbl;Field=TestField;EndIdx=10;"; string strParam2 = "Connection=TestCon;Table=TestTbl;Field=TestField;EndIdx=15;"; strParam1 = ParamPacker.Pack(strParam1); strParam2 = ParamPacker.Pack(strParam2); strSchema += "Connection0_CustomQueryName=Test1;"; strSchema += "Connection0_CustomQueryParam=" + strParam1 + ";"; strSchema += "Connection1_CustomQueryName=Test2;"; strSchema += "Connection1_CustomQueryParam=" + strParam2 + ";"; ((MyCaffeStreamDatabase)db).AddDirectQuery(new CustomQuery1()); ((MyCaffeStreamDatabase)db).AddDirectQuery(new CustomQuery2()); DateTime dt = DateTime.Today; string strSettings = "QueryCount=5;Start=" + dt.ToShortDateString() + ";TimeSpanInMs=60000;SegmentSize=1;MaxCount=10;"; db.Initialize(QUERY_TYPE.SYNCHRONIZED, strSchema + strSettings); int[] rgSize = db.QuerySize(); log.CHECK(rgSize != null, "The Query size should not be null."); log.CHECK_EQ(rgSize.Length, 3, "The query size should have 3 items."); log.CHECK_EQ(rgSize[0], 1, "The query size item 0 should be 1."); log.CHECK_EQ(rgSize[1], 3, "The query size item 1 should be 3 for three fields (q1:sync,data; q2:data)."); log.CHECK_EQ(rgSize[2], 5, "The query size item 2 should be 5 for the number of items queried."); SimpleDatum sd; int nDataIdx = 0; int nH = rgSize[1]; int nW = rgSize[2]; int nCount = nH * nW; for (int i = 0; i < 6; i++) { sd = db.Query(int.MaxValue); if (i == 0 || i == 1 || i == 3 || i == 4) { log.CHECK(sd != null, "The SD returned should not be null."); log.CHECK_EQ(sd.ItemCount, nCount, "There should be " + rgSize[1].ToString() + "x" + rgSize[2].ToString() + " items in the data."); log.CHECK_EQ(sd.Channels, rgSize[0], "The channels are not as expected."); log.CHECK_EQ(sd.Height, rgSize[1], "The height is not as expected."); log.CHECK_EQ(sd.Width, rgSize[2], "The width is not as expected."); for (int j = 0; j < nW; j++) { DateTime dt1 = Utility.ConvertTimeFromMinutes(sd.GetDataAtD(j)); log.CHECK(dt1 == dt, "The time sync is incorrect."); dt += TimeSpan.FromMinutes(1); double df1 = sd.GetDataAtD((nW * 1) + j); int nVal1 = (int)df1; log.CHECK_EQ(nVal1, nDataIdx, "The data value is incorrect."); double df2 = sd.GetDataAtD((nW * 2) + j); int nVal2 = (int)df2; log.CHECK_EQ(nVal2, nDataIdx, "The data value is incorrect."); nDataIdx++; } } else { log.CHECK(sd == null, "Since we are past the end, the sd should be null."); dt = DateTime.Today; nDataIdx = 0; db.Reset(0); } } } finally { db.Shutdown(); } }
/// <summary> /// Reset the state of the gym. /// </summary> /// <returns>A tuple containing state data, the reward, and the done state is returned.</returns> public Tuple <State, double, bool> Reset() { m_db.Reset(); return(Step(-1)); }
/// <summary> /// Reset the state of the gym. /// </summary> /// <param name="bGetLabel">Not used.</param> /// <returns>A tuple containing state data, the reward, and the done state is returned.</returns> public Tuple <State, double, bool> Reset(bool bGetLabel) { m_db.Reset(); return(Step(-1, bGetLabel)); }