本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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")
{
//.........这里部分代码省略.........