00001 /****************************************************************************** 00002 * 00003 * This file is part of Cardio Curves. 00004 * Copyright (C) 2009 Jan Gunnar Andreassen 00005 * Copyright (C) 2009 Lars Magne Engedal 00006 * 00007 * Cardio Curves is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU Lesser General Public License as published 00009 * by the Free Software Foundation, either version 2.1 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * Cardio Cruves is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with Cardio Curves. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 * Developer contact: 00021 * (janislazzaroni at users.sourceforge.net) 00022 * (engedal at users.sourceforge.net ) 00023 ******************************************************************************/ 00024 00025 #include "datahandler.h" 00026 00027 DataHandler::DataHandler() 00028 { 00029 startStamp = QDateTime::currentDateTime(); 00030 detailStamp = startStamp; 00031 samplingRate = standardSamplingRate; 00032 samplesprLine = samplingRate * secondsprLine; 00033 initArrays(); 00034 } 00035 00036 DataHandler::DataHandler(int samplesprSecond) 00037 { 00038 startStamp = QDateTime::currentDateTime(); 00039 detailStamp = startStamp; 00040 samplingRate = samplesprSecond; 00041 samplesprLine = samplingRate * secondsprLine; 00042 initArrays(); 00043 } 00044 00045 DataHandler::DataHandler(const QDateTime &startingPoint, int samplesprSecond) 00046 { 00047 startStamp = startingPoint; 00048 detailStamp = startStamp; 00049 samplingRate = samplesprSecond; 00050 samplesprLine = samplingRate * secondsprLine; 00051 initArrays(); 00052 } 00053 00054 DataHandler::~DataHandler() 00055 { 00056 //nothing to cleanup atm, everything is static 00057 } 00058 00059 void DataHandler::initArrays() 00060 { 00061 yVectors.resize(numberofLines); 00062 xVector.resize(samplesprLine); 00063 00064 for(int i=0;i<numberofLines;i++) 00065 { 00066 yVectors[i].resize(samplesprLine); 00067 } 00068 00069 for (int i = 0; i < samplesprLine; i++) 00070 { 00071 xVector[i] = i / (double)samplingRate; 00072 } 00073 } 00074 00075 double *DataHandler::getLineSample(int line, int sample) 00076 { 00077 double *py = yVectors[line].data(); 00078 py += sample; 00079 00080 return py; 00081 } 00082 00083 QPoint DataHandler::getLineSampleBounds() const 00084 { 00085 return QPoint(0, getSamplesPrLine()); 00086 } 00087 00088 QPoint DataHandler::getDetailLineSampleBounds() const 00089 { 00090 return QPoint(0, getSamplesPrDetailLine()); 00091 } 00092 00093 void DataHandler::setSampleprSecond(int sprsec) 00094 { 00095 samplingRate = sprsec; 00096 samplesprLine = samplingRate * secondsprLine; 00097 initArrays(); 00098 } 00099 00100 QString DataHandler::getStartStampText() const 00101 { 00102 return QString(startStamp.toString(QString("yyyy-MM-dd hh:mm:ss"))); 00103 } 00104 00105 QString DataHandler::getStartStampText(int line, int sample) const 00106 { 00107 int sec = line * secondsprLine; 00108 sec += (sample / samplingRate); 00109 return QString( 00110 startStamp.addSecs(sec).toString(QString("yyyy-MM-dd hh:mm:ss"))); 00111 }