BOOL UpdateStockContainerByKData( CStockContainer &container, LPCTSTR lpszCode, CKData & kdata ) { container.Lock(); int id = 0; if( CKData::ktypeDay == kdata.GetKType() && container.GetStockInfo( lpszCode, NULL, &id ) ) { CStockInfo & info = container.ElementAt(id); if( kdata.GetSize() > (int)AfxGetProfile().GetCacheDays() ) { // 只使用AfxGetProfile().GetCacheDays()天的数据 CKData temp( kdata.GetKType() ); for( int i=kdata.GetSize()-AfxGetProfile().GetCacheDays(); i<kdata.GetSize(); i++ ) temp.Add( kdata.ElementAt(i) ); info.m_kdata.MergeKData( &temp ); } else info.m_kdata.MergeKData( &kdata ); // 指数涨跌家数 int nSize = info.m_kdata.GetSize(); if( nSize > 0 ) { info.m_dwAdvance = info.m_kdata.ElementAt(nSize-1).m_dwAdvance; info.m_dwDecline = info.m_kdata.ElementAt(nSize-1).m_dwDecline; } } container.UnLock(); return TRUE; }
int AfxRefreshStockContainerMinute( CStockContainer & container, LONG lStockType, int nSecondsToRead ) { container.Lock(); time_t tmTradeLatest = -1; int nCount = 0; for( int i=0; i<container.GetSize(); i++ ) { CStockInfo & info = container.ElementAt(i); if( info.GetType() != lStockType ) continue; CStock stock; stock.SetStockInfo( &info ); stock.SetDatabase( &AfxGetDB() ); AfxGetDB().LoadMinute( &stock ); info.m_minute.RemoveAll(); CMinute & minstock = stock.GetMinute(); if( -1 == tmTradeLatest && stock.GetMinute().GetSize() > 0 ) tmTradeLatest = CSPTime::GetTimeTradeLatest( minstock[0].m_time ); for( int i=0; i<minstock.GetSize(); i++ ) { if( -1 == nSecondsToRead || tmTradeLatest-minstock[i].m_time<nSecondsToRead ) info.m_minute.Add( minstock[i] ); } nCount ++; } container.UnLock(); return nCount; }
// update CStockContainer by Report data BOOL UpdateStockContainerByREPORT( CStockContainer &container, REPORT * pReport, BOOL bAddIfNotExist, REPORT * pReportLast ) { SP_ASSERT( pReport ); if( NULL == pReport ) return FALSE; REPORT reportLast; memset( &reportLast, 0, sizeof(reportLast) ); int id = 0; if( container.GetStockInfo( pReport->m_szCode, NULL, &id ) ) { container.Lock(); CStockInfo & info = container.ElementAt(id); reportLast = info.m_reportLatest; UpdateStockInfoByREPORT( info, pReport ); container.UnLock(); } else if( bAddIfNotExist && strlen(pReport->m_szCode)>0 ) { CStockInfo info; info.SetStockCode( pReport->m_dwMarket, pReport->m_szCode ); if( UpdateStockInfoByREPORT( info, pReport ) ) { container.Add( info ); } } if( pReportLast ) memcpy( pReportLast, &reportLast, sizeof(reportLast) ); return TRUE; }
BOOL CSListView::SetAverageItem( CGridCtrl &grid, CStockContainer & container, BOOL bRedraw ) { if( grid.GetColumnCount() <= 0 ) return FALSE; container.Lock(); // Get LPARAM CUIntArray anParams; anParams.SetSize( 0, grid.GetColumnCount() ); for( int nCol=0; nCol < grid.GetColumnCount(); nCol ++ ) { LPARAM lParam = grid.GetItemData( 0, nCol ); anParams.Add( lParam ); } // Set Average CStockInfo & infoAve = container.GetAverage( ); CStockInfo & infoWAve = container.GetWeightAverage( ); int iRowAve=0, iRowWAve=0; if( grid.GetRowCount() >= 3 && grid.GetItemData(grid.GetRowCount()-2,0) == (LPARAM)ID_STOCKCNTN_AVERAGE && grid.GetItemData(grid.GetRowCount()-1,0) == (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE ) { // get item id iRowAve = grid.GetRowCount()-2; iRowWAve = grid.GetRowCount()-1; } else { // Insert item iRowAve = grid.InsertRow( infoAve.GetStockName() ); grid.SetItemData( iRowAve, 0, (LPARAM)ID_STOCKCNTN_AVERAGE ); iRowWAve = grid.InsertRow( infoWAve.GetStockName() ); grid.SetItemData( iRowWAve, 0, (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE ); } // Set Average for( nCol=0; nCol<anParams.GetSize(); nCol++ ) { grid.SetItemText( iRowAve, nCol, AfxGetVariantDispString(anParams[nCol], infoAve, NULL) ); grid.SetItemBkColour( iRowAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); grid.SetItemFgColour( iRowAve, nCol, AfxGetVariantColor( anParams[nCol], infoAve ) ); } // Set Weight Average for( nCol=0; nCol<anParams.GetSize(); nCol++ ) { grid.SetItemText( iRowWAve, nCol, AfxGetVariantDispString(anParams[nCol], infoWAve, NULL) ); grid.SetItemBkColour( iRowWAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); grid.SetItemFgColour( iRowWAve, nCol, AfxGetVariantColor( anParams[nCol], infoWAve ) ); } // Set Param which is // SLH_MARKETVALUE, SLH_MARKETVALUEA, SLH_MARKETVALUEB and etc, and more than SLH_USERDEFINE_BEGIN for( nCol=0; nCol < anParams.GetSize(); nCol ++ ) { UINT lParam = anParams[nCol]; if( SLH_DIFF == lParam || SLH_DIFFPERCENT == lParam || SLH_SCOPE == lParam || SLH_DIFFPERCENT_MIN5 == lParam || SLH_PE == lParam || SLH_PMAININCOME == lParam || SLH_RATIO_PCASH == lParam || SLH_RATIO_CURRENCY == lParam || SLH_RATIO_CHANGEHAND == lParam || SLH_RATIO_VOLUME == lParam || SLH_RS == lParam || SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam || lParam >= SLH_USERDEFINE_BEGIN ) { double dc = 0., average = 0.; double wsum = 0.0001, waverage = 0., w = 0.; for( int iRow=1; iRow<grid.GetRowCount(); iRow++ ) { if( iRow == iRowAve || iRow == iRowWAve ) continue; int id = grid.GetItemData(iRow,0); if( id < 0 || id > container.GetSize() ) continue; CStockInfo & info = container.ElementAt(id); w = info.m_fShare_count_total; double dValue = 0.; if( !AfxGetVariantValue( lParam, info, &dValue, &container ) ) continue; average = (average * dc + dValue)/(dc+1); waverage = (waverage * wsum + dValue * w)/(wsum+w); dc += 1; wsum += w; } CString strText; if( SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam ) { strText.Format( "%u", (DWORD)average ); grid.SetItemText( iRowAve, nCol, strText ); grid.SetItemText( iRowWAve, nCol, "-" ); } else { strText.Format( "%.2f", average ); grid.SetItemText( iRowAve, nCol, strText ); strText.Format( "%.2f", waverage ); grid.SetItemText( iRowWAve, nCol, strText ); } } } container.UnLock(); if( bRedraw ) { grid.RedrawRow( iRowAve ); grid.RedrawRow( iRowWAve ); } return TRUE; }