SpikeStream Library
0.2
|
00001 //SpikeStream includes 00002 #include "AnalysisDao.h" 00003 #include "GlobalVariables.h" 00004 #include "SpikeStreamDBException.h" 00005 #include "Util.h" 00006 #include "XMLParameterParser.h" 00007 using namespace spikestream; 00008 00009 //Qt includes 00010 #include <QDebug> 00011 00012 00014 AnalysisDao::AnalysisDao(const DBInfo& dbInfo) : AbstractDao(dbInfo){ 00015 } 00016 00017 00019 AnalysisDao::AnalysisDao(){ 00020 } 00021 00022 00024 AnalysisDao::~AnalysisDao(){ 00025 } 00026 00027 00028 /*----------------------------------------------------------*/ 00029 /*----- PUBLIC METHODS -----*/ 00030 /*----------------------------------------------------------*/ 00031 00033 void AnalysisDao::addAnalysis(AnalysisInfo& analysisInfo){ 00034 QString tmpQStr = "INSERT INTO Analyses (NetworkID, ArchiveID, StartTime, Description, Parameters, AnalysisTypeID) VALUES ("; 00035 tmpQStr += QString::number(analysisInfo.getNetworkID()) + ", "; 00036 tmpQStr += QString::number(analysisInfo.getArchiveID()) + ", "; 00037 tmpQStr += QString::number(analysisInfo.getStartDateTime().toTime_t()) + ", "; 00038 tmpQStr += "'" + analysisInfo.getDescription() + "', "; 00039 tmpQStr += "'" + analysisInfo.getParameterXML() + "', "; 00040 tmpQStr += QString::number(analysisInfo.getAnalyisType()) + ")"; 00041 QSqlQuery query = getQuery(tmpQStr); 00042 executeQuery(query); 00043 00044 //Check id is correct and add to network info if it is 00045 int lastInsertID = query.lastInsertId().toInt(); 00046 if(lastInsertID >= START_ANALYSIS_ID) 00047 analysisInfo.setID(lastInsertID); 00048 else 00049 throw SpikeStreamDBException("Insert ID for Analyses is invalid: " + QString::number(lastInsertID)); 00050 } 00051 00052 00054 void AnalysisDao::deleteAnalysis(unsigned int analysisID){ 00055 executeQuery("DELETE FROM Analyses WHERE AnalysisID = " + QString::number(analysisID)); 00056 } 00057 00058 00060 void AnalysisDao::deleteAllAnalyses(){ 00061 executeQuery("DELETE FROM Analyses"); 00062 } 00063 00064 00066 QList<AnalysisInfo> AnalysisDao::getAnalysesInfo(unsigned int networkID, unsigned int archiveID, unsigned int analysisType){ 00067 QString queryStr = "SELECT AnalysisID, StartTime, Description, Parameters, AnalysisTypeID FROM Analyses "; 00068 queryStr += "WHERE NetworkID=" + QString::number(networkID) + " AND ArchiveID=" + QString::number(archiveID); 00069 queryStr += " AND AnalysisTypeID=" + QString::number(analysisType); 00070 00071 QSqlQuery query = getQuery(queryStr); 00072 executeQuery(query); 00073 QList<AnalysisInfo> tmpList; 00074 for(int i=0; i<query.size(); ++i){ 00075 query.next(); 00076 00077 //Extract the parameters 00078 XMLParameterParser parser; 00079 QHash<QString, double> paramMap = parser.getParameterMap(query.value(3).toString()); 00080 00081 //Create the analysis info and add it to the list 00082 tmpList.append( 00083 AnalysisInfo( 00084 Util::getUInt(query.value(0).toString()),//AnalysisID 00085 networkID, 00086 archiveID, 00087 QDateTime::fromTime_t(Util::getUInt(query.value(1).toString())),//Date time 00088 query.value(2).toString(),//Description 00089 paramMap,//Parameter map 00090 Util::getUInt(query.value(4).toString())//Analysis type 00091 ) 00092 ); 00093 } 00094 return tmpList; 00095 } 00096 00097 00098 00101 bool AnalysisDao::networkHasAnalyses(unsigned networkID){ 00102 QSqlQuery query = getQuery("SELECT COUNT(*) FROM Analyses WHERE NetworkID=" + QString::number(networkID)); 00103 executeQuery(query); 00104 query.next(); 00105 if(query.value(0).toUInt() == 0) 00106 return false; 00107 return true; 00108 } 00109 00110 00111 00113 void AnalysisDao::updateDescription(unsigned int analysisID, const QString& newDescription){ 00114 executeQuery("UPDATE Analyses SET Description='" + newDescription + "' WHERE AnalysisID=" + QString::number(analysisID)); 00115 } 00116 00117