private void WriteSqlRecord(StreamWriter sw, DayFileRecord rec) { if (rec.Format == 'Q' && !m_keepQuality) { return; } string timeStr = rec.TimeString.Trim(); if (timeStr.Length < 3) { timeStr = "00:" + timeStr; } if (timeStr.Length == 4) { timeStr = timeStr.Substring(0, 2) + ":" + timeStr.Substring(2);// +rec.Tzone; } //INSERT INTO daily_amf_id(datetime, value, flag) values('2030-08-1 00:00:00', 998877,'') string t = m_datetime.ToString("yyyy-MM-d") + " " + timeStr + ","; for (int i = 0; i < rec.Npairs; i++) { string table_name = "instant_" + rec.Site.ToLower().Trim() + "_" + rec.Pcodes[i].ToLower().Trim(); string sql = "Insert into " + table_name + "(datetime, value, flag) values('" + t + "'," + rec.Values[i] + ",'" + FlagFromQuality(rec.Quality[i]) + "');"; sw.WriteLine(sql); } }
private void WriteCsvRecord(StreamWriter sw, DayFileRecord rec) { string str = BuildRecordPrefix(ref rec); for (int i = 0; i < rec.Npairs; i++) { sw.WriteLine(str + "," + rec.Pcodes[i].Trim() + "," + rec.Values[i] + "," + rec.Quality[i]); } }
private string BuildRecordPrefix(ref DayFileRecord rec) { string timeStr = BuildTimeString(ref rec); string str = m_datetime.ToShortDateString() + " " + timeStr + " ," + rec.Id + "," + rec.Format + "," + rec.Site.Trim() + "," + rec.TimeString + "," + rec.Rmode + "," + rec.Ttype + "," + rec.Tzone + "," + rec.Ctype; return(str); }
/// <summary> /// Just print essential /// </summary> /// <param name="sw"></param> /// <param name="rec"></param> private void AddDataTableRow(DataTable tbl, DayFileRecord rec) { for (int i = 0; i < rec.Npairs; i++) { var row = tbl.NewRow(); row[0] = rec.t; row[1] = rec.Site.Trim().ToLower(); row[2] = rec.Pcodes[i].Trim().ToLower(); row[3] = rec.Values[i]; row[4] = FlagFromQuality(rec.Quality[i]); tbl.Rows.Add(row); } }
private static string BuildTimeString(ref DayFileRecord rec) { if (rec.TimeString == null) { return(""); } string timeStr = rec.TimeString.Trim(); if (timeStr.Length < 3) { timeStr = "00:" + timeStr; } if (timeStr.Length == 4) { timeStr = timeStr.Substring(0, 2) + ":" + timeStr.Substring(2); } return(timeStr); }
private DayFileRecord ReadRecordV1(BinaryReader br) { DayFileRecord r = new DayFileRecord(); try { r.Valid = true; byte[] buff = new byte[23]; r.Site = "null"; int count = br.Read(buff, 0, 2); if (count <= 0) { r.Valid = false; if (br.BaseStream.Position == br.BaseStream.Length) { return(r); } } r.Id = BitConverter.ToInt16(buff, 0);// 64 r.Format = br.ReadChar(); r.Site = new string(br.ReadChars(8)); if (r.Site == null) { r.Site = "null"; r.Valid = false; } r.TimeString = new string(br.ReadChars(4)); string timeStr = BuildTimeString(ref r); string str = m_datetime.ToShortDateString() + " " + timeStr; if (!DateTime.TryParse(str, out r.t)) { Console.WriteLine(" invalid date " + str); r.t = DateTime.MinValue; r.Valid = false; } r.Rmode = br.ReadChar(); //if (r.Rmode != 'R' && r.Rmode != 'S') //{ // // r.Valid = false; // //Console.WriteLine("bad Rmode = '"+r.Rmode+"'"); // 'B' //} r.Ttype = br.ReadChar(); r.Tzone = br.ReadSByte(); r.Ctype = br.ReadChar(); byte[] unused = br.ReadBytes(2); r.Npairs = br.ReadSByte(); if (r.Npairs <= 0) { return(r); } sbyte[] quality; string[] pCodes = ReadPcodes(br, r.Npairs, out quality); float[] values = ReadValues(br, r.Npairs); r.Pcodes = pCodes; r.Values = values; r.Quality = quality; //r.Valid = true; } catch (EndOfStreamException e) { r.Valid = false; Console.WriteLine(e.Message); // throw e; } return(r); }
private DayFileRecord ReadRecordV2(BinaryReader br) { DayFileRecord r = new DayFileRecord(); try { while (br.PeekChar() == '\n') { char c = br.ReadChar(); Console.Write(" '\n' "); } r.Valid = true; byte[] buff = new byte[22]; r.Site = "null"; int count = br.Read(buff, 0, 22); if (count != 22) { Console.WriteLine("Error: Record did not have 22 byte header"); r.Valid = false; if (br.BaseStream.Position == br.BaseStream.Length) { return(r); } } r.Id = BitConverter.ToInt16(buff, 0);// 64 (reads two bytes) r.Format = Convert.ToChar(buff[2]); r.Site = Encoding.ASCII.GetString(buff, 3, 8); if (r.Site == null) { r.Site = "null"; r.Valid = false; } r.TimeString = Encoding.ASCII.GetString(buff, 11, 4); if (r.TimeString == "2400") { r.TimeString = "2359"; } string timeStr = BuildTimeString(ref r); string str = m_datetime.ToShortDateString() + " " + timeStr; if (!DateTime.TryParse(str, out r.t)) { Console.WriteLine(" invalid date " + str); r.t = DateTime.MinValue; r.Valid = false; } r.Rmode = Convert.ToChar(buff[15]); //if (r.Rmode != 'R' && r.Rmode != 'S') //{ // // r.Valid = false; // //Console.WriteLine("bad Rmode = '"+r.Rmode+"'"); // 'B' //} r.Ttype = Convert.ToChar(buff[16]); r.Tzone = (int)(sbyte)buff[17]; r.Ctype = Convert.ToChar(buff[18]); //byte[] unused = br.ReadBytes(2); r.Npairs = (int)(sbyte)buff[21]; if (r.Npairs <= 0) { return(r); } byte[] buff2 = new byte[r.Npairs]; sbyte[] quality; string[] pCodes = ReadPcodes(br, r.Npairs, out quality); float[] values = ReadValues(br, r.Npairs); r.Pcodes = pCodes; r.Values = values; r.Quality = quality; //r.Valid = true; } catch (EndOfStreamException e) { r.Valid = false; Console.WriteLine(e.Message); // throw e; } return(r); }