/// <summary> /// Calculates the date/time of a record based on its index. Return a date of 1990/01/01 00:00:00 if something is wrong /// </summary> /// <param name="idx"></param> /// <returns></returns> public LCAUnixTime getDTFromIDX(int idx) { if (startUnix != null) { LCAUnixTime retUnix = new LCAUnixTime(startUnix.AsUnixTime); if ((idx >= 0) && (idx <= values.Count())) { if (dataInterval > 0) { try { int numMins = (idx * dataInterval); retUnix.addMinutes(numMins); } catch (Exception e) { retUnix = null; } } } return(retUnix); } else { return(null); } }
public void createFiveMinFromOneMin(LCAUnixTime fiveSUnix, LCAUnixTime fiveEUnix, long pointID, bool isInternal) { double[] fiveData; List <double> oneData = new List <double>(); long oneCount; long fiveCount; long fivePos = 0; int onePos = 0; fiveSUnix.setToNearestInterval(5, 0); fiveEUnix.setToNearestInterval(5, 0); oneCount = ((fiveEUnix.AsUnixTime - fiveSUnix.AsUnixTime) / 60) + 1; fiveCount = (((fiveEUnix.AsUnixTime - fiveSUnix.AsUnixTime) / 60) / 5) + 1; fiveData = new double[fiveCount]; oneData = readDataFromFlatFile(FlatFileTypeEnum.FF_ONEMIN, pointID, isInternal, fiveSUnix.AsDateTime, oneCount, false); if (oneData.Count != null) { for (int i = 0; i < 5; i++) { fiveData[fivePos] += oneData[onePos]; onePos++; } fivePos++; } writeFlatFile(FlatFileTypeEnum.FF_FIVEMIN, pointID, isInternal, fiveSUnix.AsDateTime, fiveData.ToList <double>(), false); }
public List <IntervalData> readHourlyDataFromFF(FlatFileTypeEnum interval, long pointID, bool isInternal, double multiplier, DateTime sDateTime, DateTime eDateTime) { int curPos, numDays, intPerDay, intPerHour = 0; double sum; List <double> intData = new List <double>(); List <IntervalData> data = new List <IntervalData>(); LCAUnixTime curUnix = new LCAUnixTime(sDateTime); TimeSpan ts = (eDateTime.Date - sDateTime.Date); numDays = ts.Days + 1; switch (interval) { case FlatFileTypeEnum.FF_ONEMIN: curUnix = new LCAUnixTime(new DateTime(sDateTime.Year, sDateTime.Month, sDateTime.Day, 0, 1, 0)); intPerHour = 60; intPerDay = 24 * 60; break; case FlatFileTypeEnum.FF_FIVEMIN: curUnix = new LCAUnixTime(new DateTime(sDateTime.Year, sDateTime.Month, sDateTime.Day, 0, 5, 0)); intPerHour = 12; intPerDay = 24 * 12; break; case FlatFileTypeEnum.FF_TENSEC: intPerHour = 360; curUnix = new LCAUnixTime(new DateTime(sDateTime.Year, sDateTime.Month, sDateTime.Day, 0, 0, 10)); intPerDay = 24 * 360; break; default: intPerDay = -1; numDays = -1; break; } for (int i = 0; i < numDays; i++) { // Read the interval data curPos = 0; intData = readDataFromFlatFile(interval, pointID, isInternal, curUnix.AsDateTime, intPerDay, false); // sum up the hours for (int j = 1; j <= 24; j++) { sum = 0; int hour = j; if (hour == 24) { hour = 0; } LCAUnixTime hourUnix = new LCAUnixTime(new DateTime(curUnix.AsDateTime.Year, curUnix.AsDateTime.Month, curUnix.AsDateTime.Day, hour, 0, 0)); for (int k = 0; k < intPerHour; k++) { if (intData[curPos] != -1) { sum += intData[curPos]; } curPos++; } sum *= multiplier; data.Add(new IntervalData(sum, hourUnix)); } curUnix.addHours(24); } return(data); }
public List <double> readDataFromFlatFile(string fileName, LCAUnixTime sUnix, LCAUnixTime eUnix) { try { FlatFileTypeEnum interval = FlatFileTypeEnum.FF_ONEMIN; long pointID = 1; double count = 1; bool isRaw = false; bool done = false; string temp = ""; int pos = 0; string fileNamePortion; string tempDate; string thisChar; bool isInternal = false; fileNamePortion = fileName.Substring(fileName.LastIndexOf("\\")).ToUpper(); if (fileNamePortion.Contains("ONE MINUTE")) { interval = FlatFileTypeEnum.FF_ONEMIN; } else if (fileNamePortion.Contains("FIVE MINUTE")) { interval = FlatFileTypeEnum.FF_FIVEMIN; } else if (fileNamePortion.Contains("TEN SECOND")) { interval = FlatFileTypeEnum.FF_TENSEC; } if (fileNamePortion.Contains("ONE MINUTE RAW")) { isRaw = true; } if (fileNamePortion.Contains("INTERNAL")) { isInternal = true; } pos = 7; while (!done) { thisChar = fileNamePortion.Substring(pos, 1); try { int.Parse(thisChar); temp += thisChar; } catch { done = true; } pos++; if (pos > fileNamePortion.Length) { done = true; } } try { pointID = int.Parse(temp); } catch { } long seconds = eUnix.AsUnixTime - sUnix.AsUnixTime; switch (interval) { case FlatFileTypeEnum.FF_ONEMIN: count = seconds / 60; break; case FlatFileTypeEnum.FF_FIVEMIN: count = seconds / 300; break; case FlatFileTypeEnum.FF_TENSEC: count = seconds / 10; break; } count++; return(readDataFromFlatFile(interval, pointID, isInternal, sUnix.AsDateTime, count, isRaw, fileName)); } catch (Exception e) { return(new List <double>()); } }
public IntervalData(double val, LCAUnixTime unix) { value = val; recordUnix = unix; }
public bool writeFlatFile(string fileName, LCAUnixTime sUnix, List <double> data) { try { FlatFileTypeEnum interval = FlatFileTypeEnum.FF_ONEMIN; long pointID = 1; double count = 1; bool isRaw = false; bool done = false; string temp = ""; int pos = 0; string fileNamePortion; string tempDate; string thisChar; bool isInternal = false; fileNamePortion = fileName.Substring(fileName.LastIndexOf("\\")).ToUpper(); if (fileNamePortion.Contains("ONE MINUTE")) { interval = FlatFileTypeEnum.FF_ONEMIN; } else if (fileNamePortion.Contains("FIVE MINUTE")) { interval = FlatFileTypeEnum.FF_FIVEMIN; } else if (fileNamePortion.Contains("TEN SECOND")) { interval = FlatFileTypeEnum.FF_TENSEC; } if (fileNamePortion.Contains("ONE MINUTE RAW")) { isRaw = true; } if (fileNamePortion.Contains("INTERNAL")) { isInternal = true; } pos = 7; while (!done) { thisChar = fileNamePortion.Substring(pos, 1); try { int.Parse(thisChar); temp += thisChar; } catch { done = true; } pos++; if (pos > fileNamePortion.Length) { done = true; } } try { pointID = int.Parse(temp); } catch { } return(writeFlatFile(interval, pointID, isInternal, sUnix.AsDateTime, data, isRaw)); } catch (Exception e) { return(false); } }