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;
        }