Example #1
0
        private static List<DataStruct> ProcessPerMin(List<string[]> lstEntity)
        {
            List<DataStruct> QminList = new List<DataStruct>();
            try
            {
                int lstLen = lstEntity.Count;
                int tw = TimeWindow;
                string data;
                string time;
                int startIndex=0;
                //double price;
                //double volume;
                InputStr tInput = new InputStr();
                TimeProc timeProc = new TimeProc();
                DataStruct item;
                int lastTime= timeProc.time2int("9:15:00"); // 9:14:00
                string lastData = "";
                List<InputStr> list = new List<InputStr>();
                if (Mode == 1)
                {
                    list.Clear();
                    int index;
                    for (index = 0; index < lstLen; index++)
                    {
                        string[] ht = lstEntity[index];
                        tInput = new InputStr();
                        time = ht[1];
                        data = ht[0];
                        tInput.setTime(time);
                        tInput.setData(data);
                        tInput.setPrice(double.Parse(ht[2]));
                        tInput.setVolume(int.Parse(ht[3]));
                        int now = timeProc.time2int(time);

                        if (now-lastTime >=tw ) // collect a set in 1 minute
                        {
                            item = new DataStruct();
                            item.setNextMinIndex(index);
                            item.setStartMinIndex(startIndex);
                            ProcessList(list, ref item);
                            list.Clear();
                            QminList.Add(item);
                            startIndex = index;
                            while (lastTime + tw <= now)
                            {
                                lastTime += tw;
                                if (lastTime > 41400 && lastTime < 46800) // 41400 = 11:30:00
                                    lastTime = 46800;  // 46800 = 13:00:00
                            }
                        }
                        lastData = data;
                        list.Add(tInput);
                    }
                    // add the last minute
                    item = new DataStruct();
                    item.setNextMinIndex(index);
                    item.setStartMinIndex(startIndex);
                    ProcessList(list, ref item);
                    list.Clear();
                    QminList.Add(item);
                }
                else  // time window
                {
                    int index;
                    for (index = 0; index < lstLen;)
                    {
                        int t = 0;
                        while (index < lstLen)
                        {
                            time = lstEntity[index][1];
                            t = timeProc.time2int(time);
                            if (index < lstLen && t >= lastTime)
                                break;
                            index++;
                        }
                        while (t >= lastTime + tw)
                        {
                            lastTime++;
                            if (lastTime > 41400 && lastTime < 46800)
                                lastTime = 46800;
                            if (lastTime > timeProc.time2int("15:15:00"))
                                break;
                        }

                        list.Clear();
                        int si;
                        for (si = index; si < lstLen; si++)
                        {
                            time = lstEntity[si][1];
                            if (timeProc.time2int(time) < lastTime + tw)
                            {
                                string[] ht = lstEntity[si];
                                tInput = new InputStr();
                                time = ht[1];
                                data = ht[0];
                                tInput.setTime(time);
                                tInput.setData(data);
                                tInput.setPrice(double.Parse(ht[2]));
                                tInput.setVolume(int.Parse(ht[3]));
                                list.Add(tInput);
                            }
                            else
                            {
                                item = new DataStruct();
                                item.setNextMinIndex(si);
                                item.setStartMinIndex(index);
                                ProcessList(list, ref item);
                                QminList.Add(item);
                                list.Clear();
                                lastTime++;
                                break;
                            }
                        }
                        if (list.Count > 0) // the last list
                        {
                            item = new DataStruct();
                            item.setNextMinIndex(si);
                            item.setStartMinIndex(index);
                            ProcessList(list, ref item);
                            list.Clear();
                            QminList.Add(item);
                            lastTime++;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return QminList;
        }
Example #2
0
        private static void ProcessList(List<InputStr> List, ref DataStruct item)
        {
            item.setStartTime(List[0].getTime());
            item.setData(List[0].getData());
            item.setPiOpen(List[0].getPrice());
            int len = List.Count;
            item.setEndTime(List[len - 1].getTime());
            item.setPiEnd(List[len - 1].getPrice());
            double minPrice = 999999999;
            double maxPrice = 0;
            string maxPriceTime = "";
            int Qi=0;
            int MaxPriceTotal = 0;
            int MinPriceTotal = 0;

            TimeProc tp = new TimeProc();
            item.setQiTime(tp.getMinute(List[0].getTime()));

            for (int i = 0; i < len; i++ )
            {
                InputStr itr = List[i];
                Qi += itr.getVolume();
                if (itr.getPrice() > maxPrice)
                {
                    maxPrice = itr.getPrice();
                    maxPriceTime = itr.getTime();
                    MaxPriceTotal = Qi;
                }
                if (itr.getPrice() < minPrice)
                {
                    minPrice = itr.getPrice();
                    MinPriceTotal = Qi;
                }
            }

            item.setPiMax(maxPrice);
            item.setPiMin(minPrice);
            item.setPiTime(maxPriceTime);
            item.setQi(Qi);

            if (gzRadioMode==1 && item.getPiEnd()>item.getPiOpen() || gzRadioMode==2 && max(item.getPiEnd(),item.getPiMax())>=item.getPiOpen())
            {
                item.setType("��");
                item.setPiTotal(MaxPriceTotal);
            }
            else
            {
                item.setType("��");
                item.setPiTotal(MinPriceTotal);
            }
        }