Esempio n. 1
0
 private static double getPrevNMin(ref List<DataStruct> Qlist, ref List<string[]> lstEntity, int index)
 {
     TimeProc tproc = new TimeProc();
     double m = 999999999;
     int c = Prev;
     int startTime = tproc.time2int(lstEntity[Qlist[index].getStartMinIndex()][1]);
     for (int i = Qlist[index].getStartMinIndex(); i >= 0 && (startTime - tproc.time2int(lstEntity[i][1]) < c); i--)
         if (double.Parse(lstEntity[i][2]) < m)
             m = double.Parse(lstEntity[i][2]);
     return m;
 }
Esempio n. 2
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;
        }
Esempio n. 3
0
 private static double getNextNMin(ref List<DataStruct> Qlist, ref List<string[]> lstEntity, int index)
 {
     TimeProc tproc = new TimeProc();
     int len = lstEntity.Count;
     double m = 999999999;
     int c = Next;
     int startTime = tproc.time2int(lstEntity[Qlist[index].getNextMinIndex()][1]);
     for (int i = Qlist[index].getNextMinIndex(); i < len && (tproc.time2int(lstEntity[i][1]) - startTime < c); i++)
         if (double.Parse(lstEntity[i][2]) < m)
             m = double.Parse(lstEntity[i][2]);
     return m;
 }