[Quantproject-developers] QuantProject/b3_Data/DataProviders/Bars/Caching DailyBarCache.cs, 1.5, 1
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2008-12-31 02:29:52
|
Update of /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv13492/b3_Data/DataProviders/Bars/Caching Modified Files: DailyBarCache.cs Log Message: Bug fixed: in the previous revision it could have happened that a bar was thrown out as a missing one, although it was in the database Index: DailyBarCache.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b3_Data/DataProviders/Bars/Caching/DailyBarCache.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DailyBarCache.cs 30 Dec 2008 00:11:44 -0000 1.5 --- DailyBarCache.cs 31 Dec 2008 02:29:44 -0000 1.6 *************** *** 54,57 **** --- 54,59 ---- // List<DateTime> dateTimesForCleaningUp_barsMissingInTheDatabase; // List<string> tickersForCleaningUp_barsMissingInTheDatabase; + + // private bool hasTheCacheBeenCleanedUpInThePreviousUpdateActually; *************** *** 65,70 **** this.roughNumberOfItemsToBeCachedWithASingleQuery = 100; ! int maxNumberOfItemsIn_barOpenValues = 100000; int numberOfItemsToBeRemovedFrom_barOpenValues_whenCacheIsCleanedUp = maxNumberOfItemsIn_barOpenValues / 2; --- 67,75 ---- this.roughNumberOfItemsToBeCachedWithASingleQuery = 100; + + // this.hasTheCacheBeenCleanedUpInThePreviousUpdateActually = false; ! // int maxNumberOfItemsIn_barOpenValues = 100000; ! int maxNumberOfItemsIn_barOpenValues = 1000; int numberOfItemsToBeRemovedFrom_barOpenValues_whenCacheIsCleanedUp = maxNumberOfItemsIn_barOpenValues / 2; *************** *** 73,83 **** maxNumberOfItemsIn_barOpenValues , numberOfItemsToBeRemovedFrom_barOpenValues_whenCacheIsCleanedUp ); // this.barOpenValues = new Dictionary< DateTime , Dictionary< string , double > >(); // this.numberOfBarsIn_barOpenValues = 0; ! int maxNumberOfItemsIn_barsMissingInTheDatabase = 100000; int numberOfItemsToBeRemovedFrom_barsMissingInTheDatabase_whenCacheIsCleanedUp = ! maxNumberOfItemsIn_barOpenValues / 2; this.barsMissingInTheDatabase = new BarCacheData( --- 78,91 ---- maxNumberOfItemsIn_barOpenValues , numberOfItemsToBeRemovedFrom_barOpenValues_whenCacheIsCleanedUp ); + // this.barOpenValues.CleaningUp += + // new CleaningUpEventHandler( this.cleaningUpEventHandler ); // this.barOpenValues = new Dictionary< DateTime , Dictionary< string , double > >(); // this.numberOfBarsIn_barOpenValues = 0; ! // int maxNumberOfItemsIn_barsMissingInTheDatabase = 100000; ! int maxNumberOfItemsIn_barsMissingInTheDatabase = 1000; int numberOfItemsToBeRemovedFrom_barsMissingInTheDatabase_whenCacheIsCleanedUp = ! maxNumberOfItemsIn_barsMissingInTheDatabase / 2; this.barsMissingInTheDatabase = new BarCacheData( *************** *** 87,90 **** --- 95,112 ---- } + // private void cleaningUpEventHandler( object sender ) + // { + // if ( this.hasTheCacheBeenCleanedUpInThePreviousUpdateActually ) + // throw new Exception( + // "The cache has reached its size limit twice while doing a single " + + // "this.update_barOpenValues() method. It should never happen, it looks like " + + // "the cache max size is too small" ); + // else + // // the cache has reached its limit size while doing + // // the this.update_barOpenValues_actually() method, and it's not the second + // // time in a row (a second chance will be given) + // this.hasTheCacheBeenCleanedUpInThePreviousUpdateActually = true; + // } + #region checkParameters *************** *** 185,189 **** #region update_barOpenValues ! private void addBarOpenValue( string ticker, DateTime dateTime , History barOpenValuesFromDatabase ) { --- 207,214 ---- #region update_barOpenValues ! #region update_barOpenValues_actually ! ! #region update_barOpenValues_addBarForCurrent_dateTimeIndex ! private void update_barOpenValues_addBarFor_currentDateTime( string ticker, DateTime dateTime , History barOpenValuesFromDatabase ) { *************** *** 193,202 **** ticker , dateTime , barOpenValue ); } private void update_barOpenValues( string ticker, History barOpenValuesFromDatabase ) { ! foreach ( DateTime dateTime in barOpenValuesFromDatabase.TimeLine ) ! this.addBarOpenValue( ticker , dateTime , barOpenValuesFromDatabase ); } #endregion update_barOpenValues --- 218,274 ---- ticker , dateTime , barOpenValue ); } + private void update_barOpenValues_addBarForCurrent_dateTimeIndex( + string ticker , int dateTimeIndex , History barOpenValuesFromDatabase ) + { + DateTime currentDateTime = + (DateTime)barOpenValuesFromDatabase.GetKey( dateTimeIndex ); + this.update_barOpenValues_addBarFor_currentDateTime( + ticker , currentDateTime , barOpenValuesFromDatabase ); + } + #endregion update_barOpenValues_addBarForCurrent_dateTimeIndex + + private void update_barOpenValues_actually( + string ticker, History barOpenValuesFromDatabase ) + { + for ( int dateTimeIndex = barOpenValuesFromDatabase.Count - 1 ; + dateTimeIndex >=0 ; dateTimeIndex-- ) + // we use a descending order because we want to be sure that + // the first date time of the History will be in the cache, + // at the end of the cycle; + // we don't want the first date time to be removed by the cache, + // and that could happen if dateTime(s) were added after the first one + // in the History; + // notice that the bar requested by the GetMarketValue() that lead to + // this point, if present in the database, is the first date time in + // the History, so we absolutely want it to be in the cache, + // when this method is done; the first date time in the History is the + // last one to be inserted into the cache, because we don't want to run the risk + // that the cache is cleaned up after it has been inserted + this.update_barOpenValues_addBarForCurrent_dateTimeIndex( + ticker , dateTimeIndex , barOpenValuesFromDatabase ); + // foreach ( DateTime dateTime in barOpenValuesFromDatabase.TimeLine ) + // this.addBarOpenValue( ticker , dateTime , barOpenValuesFromDatabase ); + } + #endregion update_barOpenValues_actually + // private void updateAgainIfCacheHasBeenCleanedUpInThePreviousUpdate( + // string ticker, History barOpenValuesFromDatabase ) + // { + // if ( this.hasTheCacheBeenCleanedUpInThePreviousUpdateActually ) + // // executing this.update_barOpenValues_actually() the cache has reached + // // its size limit and then it has removed some items; + // // we want to be sure that barOpenValuesFromDatabase are not removed by that event + // // thus we add them again + // { + // this.update_barOpenValues_actually( ticker , barOpenValuesFromDatabase ); + // this.hasTheCacheBeenCleanedUpInThePreviousUpdateActually = false; + // } + // } private void update_barOpenValues( string ticker, History barOpenValuesFromDatabase ) { ! this.update_barOpenValues_actually( ticker , barOpenValuesFromDatabase ); ! // this.updateAgainIfCacheHasBeenCleanedUpInThePreviousUpdate( ! // ticker , barOpenValuesFromDatabase ); } #endregion update_barOpenValues *************** *** 395,399 **** try { ! this.GetMarketValue( ticker , dateTime ); } catch ( MissingBarException missingBarException ) --- 467,471 ---- try { ! this.GetMarketValue( ticker , dateTime ); } catch ( MissingBarException missingBarException ) |