[Quantproject-developers] QuantProject/b4_Business/a0_Validation IValidator.cs,NONE,1.1 QuotesToBeVa
Brought to you by:
glauco_1
Update of /cvsroot/quantproject/QuantProject/b4_Business/a0_Validation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7168 Added Files: IValidator.cs QuotesToBeValidated.cs SospiciousDataRowEventArgs.cs ValidateDataTable.cs ValidationWarnings.cs Validator.cs Log Message: Moved from the QuantDownloader project to the QuantProject project --- NEW FILE: ValidationWarnings.cs --- /* QuantProject - Quantitative Finance Library BarComponent.cs Copyright (C) 2003 Glauco Siliprandi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; namespace QuantProject.Business.Validation { /// <summary> /// Types of warnings that can be arisen when quotes are validated /// </summary> public enum ValidationWarning { OpenHighLowCloseLogicalInconsistency, SuspiciousCloseToCloseRatio, SuspiciousRangeToRangeRatio } } --- NEW FILE: Validator.cs --- using System; using System.Data; using QuantProject.DataAccess; using QuantProject.DataAccess.Tables; namespace QuantProject.Business.Validation { /// <summary> /// Validates tickers and checks for valid tickers /// </summary> public class Validator { public Validator() { // // TODO: Add constructor logic here // } #region IsValid private static bool isValid_withoutNewBeguinningQuotes( string ticker , DataTable validatedTicker ) { bool returnValue = ( ( validatedTicker.Rows.Count > 0 ) && ( (string)validatedTicker.Rows[ 0 ][ ValidatedTickers.HashValue ] == ValidatedTickers.GetHashValue( ticker , (DateTime)validatedTicker.Rows[ 0 ][ ValidatedTickers.StartDate ] , (DateTime)validatedTicker.Rows[ 0 ][ ValidatedTickers.EndDate ] ) ) ); if ( returnValue ) // the validated period is st qui!!!! returnValue = returnValue; return returnValue; } /// <summary> /// Checks if the instrument is valid (since the first date to the last date in the quotes table) /// </summary> /// <param name="ticker">Instrument's ticker</param> /// <returns></returns> public static bool IsValid( string ticker ) { DataTable validatedTicker = SqlExecutor.GetDataTable( "select * from validatedTickers where vvTicker='" + ticker + "'" ); // if ( ( validatedTicker.Rows.Count > 0 ) && // ( (DateTime)validatedTicker.Rows[ 0 ][ ValidatedTickers.StartDate ] < // Quotes.GetStartDate( ticker ) ) ) // // new quotes have been added at the beguinning of the ticker quotes, since when it was validated // ValidatedTickers.RemoveValidation( ticker ); return isValid_withoutNewBeguinningQuotes( ticker , validatedTicker ); } #endregion } } --- NEW FILE: SospiciousDataRowEventArgs.cs --- using System; using System.Data; namespace QuantProject.Business.Validation { /// <summary> /// EventArgs for the SuspiciousDataRow event /// </summary> public class SuspiciousDataRowEventArgs : EventArgs { private DataRow dataRow; private ValidationWarning validationWarning; /// <summary> /// The suspicious DataRow /// </summary> public DataRow DataRow { get { return this.dataRow; } set { value = this.dataRow; } } /// <summary> /// The suspicious DataRow /// </summary> public ValidationWarning ValidationWarning { get { return this.validationWarning; } set { value = this.validationWarning; } } public SuspiciousDataRowEventArgs( DataRow dataRow ) { this.dataRow = dataRow; } public SuspiciousDataRowEventArgs( DataRow dataRow , ValidationWarning validationWarning ) { this.dataRow = dataRow; this.validationWarning = validationWarning; } } } --- NEW FILE: ValidateDataTable.cs --- using System; using System.Data; using System.Data.OleDb; using QuantProject.DataAccess; namespace QuantProject.Business.Validation { /// <summary> /// DataTable to be bound to the Validate form DataGrid. It will /// contain all data validation errors with descriptions and it will /// be used to fetch user input data fixing and to apply updates to the database. /// </summary> public class ValidateDataTable : DataTable { private string selectStatement; private OleDbCommandBuilder oleDbCommandBuilder; private OleDbDataAdapter oleDbDataAdapter; private DataTable tableOfTickersToBeValidated; public ValidateDataTable() { //<<<<<<< ValidateDataTable.cs // this.selectStatement = // "select * from quotes where 1=2"; // this.oleDbDataAdapter = // new OleDbDataAdapter( selectStatement , ConnectionProvider.OleDbConnection ); // this.oleDbCommandBuilder = new OleDbCommandBuilder( oleDbDataAdapter ); // this.oleDbDataAdapter.UpdateCommand = this.oleDbCommandBuilder.GetUpdateCommand(); // this.oleDbDataAdapter.Fill( this ); // this.Columns.Add( new DataColumn( "CloseToCloseHasBeenVisuallyValidated" , // System.Type.GetType( "System.Boolean" ) ) ); // // this.TableName = "quotes"; ////<<<<<<< ValidateDataTable.cs // this.Columns.Add( "ValidationWarning" , // ValidationWarning.OpenHighLowCloseLogicalInconsistency.GetType() ); //======= // //>>>>>>> 1.6 //======= initializeValidateDataTable(); //>>>>>>> 1.8 } public ValidateDataTable(DataTable tableOfTickers) { initializeValidateDataTable(); // specific code used by this constructor // the table member is used when the validation procedure // is called by the tickerViewer object this.tableOfTickersToBeValidated = tableOfTickers; } #region initializeValidateDataTable private void initializeValidateDataTable() { this.selectStatement = "select * from quotes where 1=2"; this.oleDbDataAdapter = new OleDbDataAdapter( selectStatement , ConnectionProvider.OleDbConnection ); this.oleDbCommandBuilder = new OleDbCommandBuilder( oleDbDataAdapter ); this.oleDbDataAdapter.UpdateCommand = this.oleDbCommandBuilder.GetUpdateCommand(); this.oleDbDataAdapter.Fill( this ); DataColumn dataColumn = new DataColumn( "CloseToCloseHasBeenVisuallyValidated" , System.Type.GetType( "System.Boolean" ) ); dataColumn.DefaultValue = false; this.Columns.Add( dataColumn ); this.TableName = "quotes"; //<<<<<<< ValidateDataTable.cs this.Columns.Add( "ValidationWarning" , ValidationWarning.OpenHighLowCloseLogicalInconsistency.GetType() ); //======= // //>>>>>>> 1.6 } #endregion /// <summary> /// Adds quotesRow to the ValidateDataTable /// </summary> /// <param name="quotesRow">Row of quotes to added</param> private void suspiciousDataRowEventHandler( Object sender , SuspiciousDataRowEventArgs eventArgs ) { DataRow quotesRow = eventArgs.DataRow; DataRow dataRow = this.NewRow(); foreach (DataColumn dataColumn in quotesRow.Table.Columns ) dataRow[ dataColumn.ColumnName ] = quotesRow[ dataColumn ]; dataRow[ "ValidationWarning" ] = eventArgs.ValidationWarning; this.Rows.Add( dataRow ); //this.Rows.Add( quotesRow ); } public void AddRows( string tickerIsLike , double suspiciousRatio ) { QuotesToBeValidated quotesToBeValidated = new QuotesToBeValidated( tickerIsLike ); quotesToBeValidated.SuspiciousRatio = suspiciousRatio; quotesToBeValidated.SuspiciousDataRow += new SuspiciousDataRowEventHandler( suspiciousDataRowEventHandler ); // new QuotesToBeValidated.SuspiciousDataRowEventHandler( suspiciousDataRowEventHandler ); quotesToBeValidated.Validate(); this.AcceptChanges(); } public void AddRows(double suspiciousRatio ) { QuotesToBeValidated quotesToBeValidated = new QuotesToBeValidated(this.tableOfTickersToBeValidated); quotesToBeValidated.SuspiciousRatio = suspiciousRatio; quotesToBeValidated.SuspiciousDataRow += new SuspiciousDataRowEventHandler( suspiciousDataRowEventHandler ); // new QuotesToBeValidated.SuspiciousDataRowEventHandler( suspiciousDataRowEventHandler ); quotesToBeValidated.Validate(); this.AcceptChanges(); } /// <summary> /// Commits the ValidateDataTable changes to the database /// </summary> public void Update() { try { this.oleDbDataAdapter.Update( this ); this.AcceptChanges(); } catch (Exception exception) { Console.WriteLine( exception.ToString() ); } } } } --- NEW FILE: QuotesToBeValidated.cs --- using System; using System.Data; using System.Data.OleDb; using QuantProject.DataAccess; using QuantProject.Business.Validation.Validators; namespace QuantProject.Business.Validation { /// <summary> /// Summary description for QuotesToBeValidated. /// </summary> public class QuotesToBeValidated : DataTable { private string selectStatement; private OleDbDataAdapter oleDbDataAdapter; private double suspiciousRatio; public double SuspiciousRatio { get { return this.suspiciousRatio; } set { this.suspiciousRatio = value; } } public QuotesToBeValidated( string tickerIsLike ) { // this.selectStatement = // "select * from quotes where quTicker like '" + tickerIsLike + "'"; this.selectStatement = "select * from quotes where quTicker = '" + tickerIsLike + "'"; this.oleDbDataAdapter = new OleDbDataAdapter( selectStatement , ConnectionProvider.OleDbConnection ); try { this.oleDbDataAdapter.Fill( this ); } catch (Exception exception) { Console.WriteLine( exception.ToString() ); } } public QuotesToBeValidated(DataTable tableOfTickersToBeValidated) { this.oleDbDataAdapter = new OleDbDataAdapter( "" , ConnectionProvider.OleDbConnection ); foreach(DataRow row in tableOfTickersToBeValidated.Rows) { this.oleDbDataAdapter.SelectCommand.CommandText = "select * from quotes where quTicker = '" + (string)row[0] + "'"; try { this.oleDbDataAdapter.Fill( this ); } catch (Exception exception) { Console.WriteLine( exception.ToString() ); } } } // public delegate void SuspiciousDataRowEventHandler( // Object sender , SuspiciousDataRowEventArgs eventArgs ); public event SuspiciousDataRowEventHandler SuspiciousDataRow; #region "Validate" private void suspiciousDataRowHandler( Object sender , SuspiciousDataRowEventArgs eventArgs ) { SuspiciousDataRow( this , eventArgs ); } public void Validate() { // QuantProject.Applications.Downloader.Validate.Validators.OHLCvalidator oHLCvalidator = // new QuantProject.Applications.Downloader.Validate.Validators.OHLCvalidator(); // oHLCvalidator.SuspiciousDataRow += // new SuspiciousDataRowEventHandler( suspiciousDataRowHandler ); // oHLCvalidator.Validate( this ); MultiValidator multiValidator = new MultiValidator(); multiValidator.SuspiciousRatio = this.suspiciousRatio; multiValidator.SuspiciousDataRow += new SuspiciousDataRowEventHandler( this.suspiciousDataRowHandler ); multiValidator.Validate( this ); } } #endregion } --- NEW FILE: IValidator.cs --- using System; using System.Data; namespace QuantProject.Business.Validation { public delegate void SuspiciousDataRowEventHandler( Object sender , SuspiciousDataRowEventArgs eventArgs ); /// <summary> /// Interface to be implemented by quotes validators /// </summary> public interface IValidator { event SuspiciousDataRowEventHandler SuspiciousDataRow; void Validate( DataTable dataTable ); } } |