Пример #1
0
        /// <summary>
        /// Agrregate a data table to hourly,daily data...
        /// </summary>
        /// <param name="priceTbl">source data to be aggregated </param>
        /// <param name="cultureCode"></param>
        /// <param name="isDailyPrice">
        ///  Volume can be accumulated real-time or at the end of the day.
        ///  - If data is collected in realtime,
        ///  updateVolume table is used to culmulated the volume for each day and that will need some more resources.
        ///  - If data is collected at the end of the day, the voulume alredy is the total volume and updateVolume table
        ///  should not be used to save resources.
        /// </param>
        /// <param name="onAggregateDataFunc">function that was triggered after each agrregation</param>
        public static void AggregatePriceData(databases.baseDS.priceDataDataTable priceTbl, CultureInfo cultureInfo,
                                              OnAggregateData onAggregateDataFunc)
        {
            databases.baseDS.priceDataSumDataTable priceSumDataTbl = new databases.baseDS.priceDataSumDataTable();
            AgrregateInfo myAgrregateStat = new AgrregateInfo();

            myAgrregateStat.maxCount = priceTbl.Count;

            decimal changeVolume;
            int     lastYear = int.MinValue;

            for (int idx = 0; idx < priceTbl.Count; idx++)
            {
                myAgrregateStat.count = idx;
                if (onAggregateDataFunc != null)
                {
                    onAggregateDataFunc(myAgrregateStat);
                }
                if (myAgrregateStat.cancel)
                {
                    priceSumDataTbl.Clear();
                    break;
                }
                Application.DoEvents();

                changeVolume = priceTbl[idx].volume;
                foreach (AppTypes.TimeScale timeScale in AppTypes.myTimeScales)
                {
                    if (timeScale.Type == AppTypes.TimeScaleTypes.RealTime)
                    {
                        continue;
                    }
                    AggregatePriceData(priceTbl[idx], changeVolume, timeScale, cultureInfo, priceSumDataTbl);
                }
                //Update and clear cache to speed up the performance
                if (lastYear != priceTbl[idx].onDate.Year)
                {
                    databases.DbAccess.UpdateData(priceSumDataTbl);
                    priceSumDataTbl.Clear();
                    lastYear = priceTbl[idx].onDate.Year;
                }
                //databases.DbAccess.UpdateData(priceDataRow);
            }
            databases.DbAccess.UpdateData(priceSumDataTbl);
            priceSumDataTbl.Dispose();
        }
Пример #2
0
 public static databases.baseDS.priceDataSumRow FindAndCache(databases.baseDS.priceDataSumDataTable tbl, string stockCode, string timeScale, DateTime onDate)
 {
     databases.baseDS.priceDataSumRow row = tbl.FindBytypestockCodeonDate(timeScale, stockCode, onDate);
     if (row != null)
     {
         return(row);
     }
     databases.baseDSTableAdapters.priceDataSumTA dataTA = new databases.baseDSTableAdapters.priceDataSumTA();
     dataTA.ClearBeforeFill = false;
     dataTA.Fill(tbl, stockCode, timeScale, onDate, onDate);
     row = tbl.FindBytypestockCodeonDate(timeScale, stockCode, onDate);
     if (row != null)
     {
         return(row);
     }
     return(null);
 }
Пример #3
0
        /// <summary>
        /// Agrregate a data row to hourly,daily data...
        /// </summary>
        /// <param name="priceRow"> source data arregated to [toSumTbl] </param>
        /// <param name="changeVolume"> volume qty changed and is cumulated to total volume </param>
        /// <param name="timeScale"> aggregate to hour,day,week... data </param>
        /// <param name="cultureInfo"> culture info that need to caculate the start of the week param>
        /// <param name="toSumTbl"> destination table</param>
        public static void AggregatePriceData(databases.baseDS.priceDataRow priceRow, decimal changeVolume, AppTypes.TimeScale timeScale,
                                              CultureInfo cultureInfo, databases.baseDS.priceDataSumDataTable toSumTbl)
        {
            DateTime dataDate = AggregateDateTime(timeScale, priceRow.onDate, cultureInfo);

            databases.baseDS.priceDataSumRow priceDataSumRow;
            priceDataSumRow = AppLibs.FindAndCache(toSumTbl, priceRow.stockCode, timeScale.Code, dataDate);
            if (priceDataSumRow == null)
            {
                priceDataSumRow = toSumTbl.NewpriceDataSumRow();
                databases.AppLibs.InitData(priceDataSumRow);
                priceDataSumRow.type       = timeScale.Code;
                priceDataSumRow.stockCode  = priceRow.stockCode;
                priceDataSumRow.onDate     = dataDate;
                priceDataSumRow.openPrice  = priceRow.openPrice;
                priceDataSumRow.closePrice = priceRow.closePrice;

                object lastPriceObj = lastClosePrices.Find(timeScale.Code + priceRow.stockCode);
                if (lastPriceObj != null)
                {
                    priceDataSumRow.openPrice = (decimal)lastPriceObj;
                }
                else
                {
                    priceDataSumRow.openPrice = priceDataSumRow.closePrice;
                }
                toSumTbl.AddpriceDataSumRow(priceDataSumRow);
            }
            priceDataSumRow.closePrice = priceRow.closePrice;
            lastClosePrices.Add(timeScale.Code + priceRow.stockCode, priceRow.closePrice);

            if (priceDataSumRow.highPrice < priceRow.highPrice)
            {
                priceDataSumRow.highPrice = priceRow.highPrice;
            }
            if (priceDataSumRow.lowPrice > priceRow.lowPrice)
            {
                priceDataSumRow.lowPrice = priceRow.lowPrice;
            }
            priceDataSumRow.volume += changeVolume;
        }
Пример #4
0
        /// <summary>
        /// Agrregate a data table to hourly,daily data...
        /// </summary>
        /// <param name="priceTbl">source data to be aggregated </param>
        /// <param name="cultureCode"></param>
        /// <param name="isDailyPrice">
        ///  Volume can be accumulated real-time or at the end of the day. 
        ///  - If data is collected in realtime, 
        ///  updateVolume table is used to culmulated the volume for each day and that will need some more resources.
        ///  - If data is collected at the end of the day, the voulume alredy is the total volume and updateVolume table 
        ///  should not be used to save resources.
        /// </param>
        /// <param name="onAggregateDataFunc">function that was triggered after each agrregation</param>
        public static void AggregatePriceData(databases.baseDS.priceDataDataTable priceTbl, CultureInfo cultureInfo,
                                                  OnAggregateData onAggregateDataFunc)
            {
                databases.baseDS.priceDataSumDataTable priceSumDataTbl = new databases.baseDS.priceDataSumDataTable();
                AgrregateInfo myAgrregateStat = new AgrregateInfo();
                myAgrregateStat.maxCount = priceTbl.Count;

                decimal changeVolume;
                int lastYear = int.MinValue;
                for (int idx = 0; idx < priceTbl.Count; idx++)
                {
                    myAgrregateStat.count = idx;
                    if (onAggregateDataFunc != null) onAggregateDataFunc(myAgrregateStat);
                    if (myAgrregateStat.cancel)
                    {
                        priceSumDataTbl.Clear();
                        break;
                    }
                    Application.DoEvents();

                    changeVolume = priceTbl[idx].volume;
                    foreach (AppTypes.TimeScale timeScale in AppTypes.myTimeScales)
                    {
                        if (timeScale.Type == AppTypes.TimeScaleTypes.RealTime) continue;
                        AggregatePriceData(priceTbl[idx], changeVolume, timeScale, cultureInfo, priceSumDataTbl);
                    }
                    //Update and clear cache to speed up the performance
                    if (lastYear != priceTbl[idx].onDate.Year)
                    {
                        databases.DbAccess.UpdateData(priceSumDataTbl);
                        priceSumDataTbl.Clear();
                        lastYear = priceTbl[idx].onDate.Year;
                    }
                    //databases.DbAccess.UpdateData(priceDataRow);
                }
                databases.DbAccess.UpdateData(priceSumDataTbl);
                priceSumDataTbl.Dispose();
            }