Exemplo n.º 1
0
        public static AQCSVTimeSeries Load(string csv)
        {
            AQCSVTimeSeries ret = new AQCSVTimeSeries();

            if (string.IsNullOrEmpty(csv))
            {
                return(ret);
            }
            ret.metaData = new AQCSVMetaData();
            using (StringReader reader = new StringReader(csv))
            {
                string line      = null;
                int    lineCount = 0;
                //meta header
                line = reader.ReadLine();
                ret.metaData.headers = CSVUtil.splitCCVLine(line);
                ret.metaData.columns = ret.metaData.headers.Length;
                lineCount++;

                //meta data
                line = reader.ReadLine();
                ret.metaData.datas = CSVUtil.splitCCVLine(line);
                int rangeCount = int.Parse(ret.metaData["NumRanges"]);
                ret.ranges = new AQCSVTable[rangeCount];
                lineCount++;

                for (int i = 0; i < rangeCount; i++)
                {
                    ret.ranges[i] = AQCSVTable.Load(csv, null, "NumPoints", ref lineCount);
                }
                reader.Close();
            }
            return(ret);
        }
Exemplo n.º 2
0
        public static AQCSVTable Load(string csv, string tblName, string countColumnName, ref int lineCount)
        {
            AQCSVTable ret = new AQCSVTable();

            ret.tblName = tblName;
            if (string.IsNullOrEmpty(csv))
            {
                return(ret);
            }
            ret.metaData = new AQCSVMetaData();
            ret.dataSet  = new AQCSVDataSet();
            using (StringReader reader = new StringReader(csv))
            {
                string          line       = null;
                int             curLineCnt = 0;
                int             dataNumber = 0;
                int             dataCount  = 0;
                int             state      = 0; //0, meta header, 1, meta data, 2 data header, 3, data
                List <string[]> dateItems  = new List <string[]>();
                while ((line = reader.ReadLine()) != null)
                {
                    curLineCnt++;
                    if (curLineCnt <= lineCount)
                    {
                        continue;
                    }
                    lineCount = curLineCnt;
                    if (line.Length > 0)
                    {
                        switch (state)
                        {
                        case 0:    //meta header
                        {
                            ret.metaData.headers = CSVUtil.splitCCVLine(line);
                            ret.metaData.columns = ret.metaData.headers.Length;
                            state = 1;
                            break;
                        }

                        case 1:    //meta data
                        {
                            ret.metaData.datas = CSVUtil.splitCCVLine(line);
                            if (!string.IsNullOrEmpty(countColumnName))
                            {
                                dataNumber = int.Parse(ret.metaData[countColumnName]);
                            }
                            state = 2;
                            break;
                        }

                        case 2:    //data header
                        {
                            ret.dataSet.headers = CSVUtil.splitCCVLine(line);
                            ret.dataSet.columns = ret.dataSet.headers.Length;
                            state = 3;
                            break;
                        }

                        case 3:    //data
                        {
                            string[] dataItem = CSVUtil.splitCCVLine(line);
                            dateItems.Add(dataItem);
                            dataCount++;
                            break;
                        }

                        default:
                            break;
                        }
                        if (dataNumber > 0 && dataCount == dataNumber) //move to next
                        {
                            lineCount++;
                            break;
                        }
                    }
                }
                reader.Close();
                ret.dataSet.datas  = dateItems.ToArray();
                ret.dataSet.length = ret.dataSet.datas.Length;
            }

            return(ret);
        }