当前位置: 首页>>代码示例>>C#>>正文


C# CsvReader.Reverse方法代码示例

本文整理汇总了C#中CsvReader.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.Reverse方法的具体用法?C# CsvReader.Reverse怎么用?C# CsvReader.Reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvReader的用法示例。


在下文中一共展示了CsvReader.Reverse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadCsv

        /// <summary>
        /// 分析某一天的数据
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static DailyData ReadCsv(string fileName,bool isDownload)
        {
            DailyData data = new DailyData();
            data.entryList = new List<EntryData>();

            FileInfo fi = new FileInfo(fileName);

            string fName = fi.Name;
            //data.stock = StockUtil.RetrieveStock(fName);
            string date = StockUtil.RetrieveDate(fName);
            data.Date = DateTime.Parse(date);

            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(
                                   new StreamReader(fileName), true))
            {
                int index = 0;

                int fieldCount = csv.FieldCount;

                string[] headers = csv.GetFieldHeaders();

                decimal current;
                //颠倒记录
                IEnumerable<string[]> hi= csv.Reverse<string[]>();
                //foreach(String[]  a in hi)
                //{
                //    Console.WriteLine(a[0]);
                //}
                //for(int i=0;i<hi.;i++)
                //{
                //    Console.WriteLine(csv[i,0]);
                //}
                //while (csv.ReadNextRecord())
                //{
                //Console.WriteLine(hi.Count<string[]>());
                    try
                    {
                        foreach (String[] record in hi)
                        {
                            EntryData dd = new EntryData();

                            current = Decimal.Parse(record[1].Replace("\0", ""));

                            if (index == 0)
                            {
                                data.ClosePrice = current;
                                data.HighestPrice = current;
                                data.LowestPrice = current;
                            }

                            if (data.HighestPrice < current)
                            {
                                data.HighestPrice = current;
                                data.TimeWhenHighest = DateTime.Parse(date + " " + record[0]);
                            }
                            if (data.LowestPrice > current)
                            {
                                data.LowestPrice = current;
                                data.TimeWhenLowest = DateTime.Parse(date + " " + record[0]);
                            }

                            dd.time = DateTime.Parse(date + " " + record[0]);
                            dd.price = current;
                            dd.change = Decimal.Parse(record[2]);
                            dd.share = decimal.Parse(record[3]);
                            dd.money = decimal.Parse(record[4]);
                            dd.type = record[5];

                            data.entryList.Add(dd);
                            data.OpenPrice = current;
                            index++;
                        }
                    }
                    catch
                    {
                        ///TODO 吞掉异常
                        ///
                        StockLog.Log.Info("Can't parse at line " + index + "  " + fileName);
                    }
                //}

                //LOG.Info(fileName+" "+fieldCount + " " + index);
            }

            return data;
        }
开发者ID:pooooren,项目名称:StockAnalyzer,代码行数:92,代码来源:Csv.cs

示例2: ReadCsvByReaderOld

        public static List<BasicData> ReadCsvByReaderOld(string sid, string date, TextReader stream, decimal[] bigs, DateTime lastupdate)
        {
            int index = 0;

            List<BasicData> list = new List<BasicData>();
            BasicData[] array = new BasicData[bigs.Length];

            if (date.Length != 10) throw new Exception("time format is wrong -" + date);
            string time = date;
            DateTime t = new DateTime(Int32.Parse(time.Substring(0, 4)), Int32.Parse(time.Substring(5, 2)), Int32.Parse(time.Substring(8, 2)));

            //处理过了就忽略
            if (t < lastupdate.AddDays(1)) return null;

            for (int j = 0; j < bigs.Length; j++)
            {
                array[j] = new BasicData();
                array[j].big = (int)bigs[j];
                array[j].time = t;
                array[j].sid = sid;
                array[j].c_type = "d";
            }

            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(stream, true))
            {  //颠倒记录
                IEnumerable<string[]> hi = csv.Reverse<string[]>();

                decimal current;

                decimal open = 0, close = 0, high = 0, low = 0;

                foreach (String[] record in hi)
                {
                    string price_str = record[1];
                    string share_str = record[3];
                    string type_str = record[5];
                    try
                    {

                        Decimal price = Decimal.Parse(price_str.IndexOf("\0") > 0 ? price_str.Remove(price_str.IndexOf("\0")) : price_str);
                        Double share = Double.Parse(share_str.IndexOf("\0") > 0 ? share_str.Remove(share_str.IndexOf("\0")) : share_str);

                        //count close,open,low,high
                        current = price;
                        if (index == 0)
                        {
                            open = current;
                            high = current;
                            low = current;
                        }
                        if (high < current) high = current;
                        if (low > current) low = current;
                        close = current;
                        index++;

                        for (int k = 0; k < bigs.Length; k++)
                        {

                            int fieldCount = csv.FieldCount;
                            string[] headers = csv.GetFieldHeaders();

                            array[k].open = open;
                            array[k].close = close;
                            array[k].high = high;
                            array[k].low = low;
                            array[k].totalshare += share;
                            array[k].totalmoney += Decimal.Multiply(price, (Decimal)share);

                            if (Int32.Parse(share_str) >= bigs[k])
                            {

                                if (type_str == "S")
                                {
                                    array[k].sellshare += share;
                                    array[k].sellmoney += Decimal.Multiply(price, (Decimal)share);
                                }
                                if (type_str == "B")
                                {
                                    array[k].buyshare += share;
                                    array[k].buymoney += Decimal.Multiply(price, (Decimal)share);
                                }
                            }
                        }
                    }
                    catch
                    {
                        StockLog.Log.Error(sid + "_" + date + " import fail");
                    }
                }
            }
            for (int j = 0; j < bigs.Length; j++)
            {
                list.Add(array[j]);
            }
            return list;
        }
开发者ID:pooooren,项目名称:StockAnalyzer,代码行数:97,代码来源:ImportRawData.cs

示例3: ParseListFromCsvFile

        public static List<string> ParseListFromCsvFile(string csvFile)
        {
            List<string> list = new List<string>();
            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(new StreamReader(csvFile), true))
            {  //颠倒记录
                IEnumerable<string[]> hi = csv.Reverse<string[]>();

                foreach (String[] record in hi)
                {
                    string sid = record[1];

                    list.Add(sid);
                }
            }

            return list;
        }
开发者ID:pooooren,项目名称:StockAnalyzer,代码行数:18,代码来源:StockUtil.cs

示例4: ReadCsvByReader

        /// <summary>
        /// 保存大单的具体情况
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="date"></param>
        /// <param name="stream"></param>
        /// <param name="bigs"></param>
        /// <param name="lastupdate"></param>
        /// <returns></returns>
        public static List<BasicData> ReadCsvByReader(string sid, string date, TextReader stream, decimal[] bigs, DateTime lastupdate)
        {
            int index = 0;

            //bigs = null;
            //bigs = new decimal[1];
            //bigs[0] = 1000M;
            List<BasicData> list = new List<BasicData>();
            BasicData[] array = new BasicData[bigs.Length];

            if (date.Length != 10) throw new Exception("time format is wrong -" + date);
            string time = date;
            DateTime t = new DateTime(Int32.Parse(time.Substring(0, 4)), Int32.Parse(time.Substring(5, 2)), Int32.Parse(time.Substring(8, 2)));

            //处理过了就忽略
            if (t < lastupdate.AddDays(1)) return null;

            Dictionary<decimal, string> temp = new Dictionary<decimal, string>();

            for (int j = 0; j < bigs.Length; j++)
            {
                array[j] = new BasicData();
                array[j].big = (int)bigs[j];
                array[j].time = t;
                array[j].sid = sid;
                array[j].c_type = "d";
                temp[bigs[j]] = "";
            }

            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(stream, true))
            {  //颠倒记录
                IEnumerable<string[]> hi = csv.Reverse<string[]>();

                decimal current;

                decimal open = 0, close = 0, high = 0, low = 0;

                foreach (String[] record in hi)
                {

                    string price_str = record[1];
                    string change_str = record[2];
                    string share_str = record[3];
                    string type_str = record[5];
                    string time_str = record[0];
                    try
                    {

                        Decimal price = Decimal.Parse(price_str.IndexOf("\0") > 0 ? price_str.Remove(price_str.IndexOf("\0")) : price_str);
                        Double share = Double.Parse(share_str.IndexOf("\0") > 0 ? share_str.Remove(share_str.IndexOf("\0")) : share_str);

                        //count close,open,low,high
                        current = price;
                        if (index == 0)
                        {
                            open = current;
                            high = current;
                            low = current;
                        }
                        if (high < current) high = current;
                        if (low > current) low = current;
                        close = current;
                        index++;

                        for (int k = 0; k < bigs.Length; k++)
                        {

                            int fieldCount = csv.FieldCount;
                            string[] headers = csv.GetFieldHeaders();

                            array[k].open = open;
                            array[k].close = close;
                            array[k].high = high;
                            array[k].low = low;
                            array[k].totalshare += share;
                            array[k].totalmoney += Decimal.Multiply(price, (Decimal)share);

                            if (Int32.Parse(share_str) >= bigs[k])
                            {
                                //15位编码编码,
                                //第1位买单1卖单0
                                //后3位股数(百手)
                                //后3位时间数(相对于9:25的分钟数)
                                //后4位位股价(1正0负,后三位是相对开盘的万分比
                                //后4位,股价变化(1正0负,后3位是万分比)
                                //Console.WriteLine(time_str + ": " + share + " " + type_str);

                                string code = "";
                                if (type_str == "S")
                                {
//.........这里部分代码省略.........
开发者ID:pooooren,项目名称:StockAnalyzer,代码行数:101,代码来源:ImportRawData.cs


注:本文中的CsvReader.Reverse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。