Commit 2e10210a authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

introduced historical view

parent e8a7accf
......@@ -13,32 +13,23 @@ AlarmHistoryTree::AlarmHistoryTree(QWidget *parent) : QTreeView(parent)
{
db = QSqlDatabase::addDatabase("QMYSQL");
QStringList args = qApp->arguments();
QString dbHost = "log";
if(args.contains("--log-database-host") && args.size() > args.indexOf("--log-database-host"))
{
QString dbHost = "fcslog-replica-01";
if(args.contains("--log-database-host") && args.size() > args.indexOf("--log-database-host")) {
dbHost = args.at(args.indexOf("--log-database-host") + 1);
//qDebug()<<"Database host: "<<dbHost;
}
db.setHostName(dbHost);
db.setDatabaseName("alarm");
db.setUserName("alarm-client");
db.setPassword("");
if (!db.open())
{
db.setDatabaseName("hdbpp");
db.setUserName("hdbppro");
db.setPassword("hdbppro");
if (!db.open()) {
QString sqlErr = db.lastError().text();
QMessageBox::critical(0, "Error", QString("Can't establish connection with db \"alarm\" on host log:\n%1").arg(sqlErr));
}
model = new MySqlModel();
model->setHeaderData(0, Qt::Horizontal, "Timestamp");
setModel(model);
}
/*
void AlarmHistoryTree::updateView(QString &s)
{
}
*/
void AlarmHistoryTree::applyFilter(AlarmFilter f)
{
int i, j;
......@@ -95,22 +86,14 @@ void AlarmHistoryTree::applyFilter(AlarmFilter f)
}
void AlarmHistoryTree::removeFilter()
{
void AlarmHistoryTree::removeFilter() {
int i;
QModelIndex root = rootIndex();
for(i = 0; i < model->rowCount(); i++)
{
for(i = 0; i < model->rowCount(); i++) {
if(isRowHidden(i, root))
setRowHidden(i, root, false);
}
_filter_enabled = false;
// headerItem()->setIcon(ACK, QIcon(ICON_PATH + ""));
// headerItem()->setIcon(LEVEL, QIcon(ICON_PATH + ""));
// headerItem()->setIcon(STATUS, QIcon(ICON_PATH + ""));
// headerItem()->setIcon(GROUP, QIcon(ICON_PATH + ""));
}
void AlarmHistoryTree::executeQuery(QString &q)
......
......@@ -149,6 +149,14 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
//connect(ui->pBTestSoundOff, SIGNAL(clicked()), this, SLOT(stopSound()));
/* sound: beep on new alarm */
connect(ui->treeWidgetAlarms, SIGNAL(newAlarmDetected()), this, SLOT(beep()));
// database
ui->dateStart->setDate(QDate::currentDate());
ui->dateStop->setDate(QDate::currentDate());
ui->timeStart->setTime(QTime::currentTime());
ui->timeStop->setTime(QTime::currentTime());
connect(ui->pBApplyHistory, SIGNAL(clicked()), this, SLOT(queryDB()));
connect(ui->comboPeriod, SIGNAL(currentIndexChanged(int)), this, SLOT(enableFrameHistoryInterval(int)));
}
Alarm::~Alarm() {
......@@ -308,6 +316,8 @@ void Alarm::onItemDoubleClicked(const QModelIndex &mi) {
}
void Alarm::tabChanged(int t) {
if(t == 2)
queryDB();
if(t > 1) {
ui->pBAckAll->setHidden(true);
ui->pBConfHistory->setHidden(false);
......@@ -344,3 +354,62 @@ void Alarm::closeEvent(QCloseEvent *e)
e->ignore();
}
void Alarm::queryDB()
{
QDateTime startSearch;
QDateTime now = QDateTime::currentDateTime();
QString query;
QDateTime dts, dte;
switch(ui->comboPeriod->currentIndex()) {
case 0:
startSearch = now.addDays(-1);
break;
case 1:
startSearch = now.addDays(-7);
break;
case 2:
startSearch = now.addMonths(-1);
break;
case 3:
dts.setDate(ui->dateStart->date());
dts.setTime(ui->timeStart->time());
dte.setDate(ui->dateStop->date());
dte.setTime(ui->timeStop->time());
break;
}
if(startSearch.isValid()) {
query = QString("SELECT asd.data_time,ac.att_name, "
"COALESCE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(asd.value_r,'0','NORMAL'),'1','ALARM UNACK'),'2','ALARM ACKED'),'3','RETURNED NORMAL'),'4','SHELVED'),'6','DISABLED'),aed.error_desc) as value_r "
"FROM att_scalar_devenum_ro asd "
"JOIN att_conf ac ON asd.att_conf_id=ac.att_conf_id "
"LEFT OUTER JOIN att_error_desc aed ON aed.att_error_desc_id=asd.att_error_desc_id "
"WHERE ac.att_name in (SELECT att_name FROM att_conf WHERE att_name LIKE '%alarm/test/0/%' OR att_name LIKE '%alarm/fermi/test/%') "
"AND asd.data_time > '%1' ORDER BY asd.data_time DESC;").arg(startSearch.toString("yyyy-MM-dd hh:mm:ss.zzz"));
}
else if(dts.isValid() && dte.isValid() && dts < dte) {
query = QString("SELECT asd.data_time,ac.att_name, "
"COALESCE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(asd.value_r,'0','NORMAL'),'1','ALARM UNACK'),'2','ALARM ACKED'),'3','RETURNED NORMAL'),'4','SHELVED'),'6','DISABLED'),aed.error_desc) as value_r "
"FROM att_scalar_devenum_ro asd "
"JOIN att_conf ac ON asd.att_conf_id=ac.att_conf_id "
"LEFT OUTER JOIN att_error_desc aed ON aed.att_error_desc_id=asd.att_error_desc_id "
"WHERE ac.att_name in (SELECT att_name FROM att_conf WHERE att_name LIKE '%alarm/test/0/%' OR att_name LIKE '%alarm/fermi/test/%') "
"AND asd.data_time > '%1' AND asd.data_time < '%2' ORDER BY asd.data_time DESC;").arg(dts.toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(dte.toString("yyyy-MM-dd hh:mm:ss.zzz"));
}
else if(dts.isValid() && dte.isValid() && dts >= dte)
QMessageBox::information(this, "Invalid date / time range", "Stop date/time is ahead of start date/time");
if(query.length() > 0)
ui->twHistory->executeQuery(query);
printf("executing query \"%s\"\n", qstoc(query));
if(ui->cBDynamic->isChecked()) {
applyFilter();
}
}
void Alarm::enableFrameHistoryInterval(int i) {
ui->widgetHistoryConf->setEnabled(i == 3);
}
......@@ -53,6 +53,7 @@ public:
public slots:
void queryDB();
protected slots:
void refresh(const CuData &da);
void onDevList(const CuData& da);
......@@ -79,6 +80,8 @@ protected slots:
protected:
void closeEvent(QCloseEvent *);
private slots:
void enableFrameHistoryInterval(int i);
private:
void insertItem(const QStringList &s, int index);
void tangoStringListCommand(const QString &device_name, const QStringList &names, const char *cmdname);
......
......@@ -73,6 +73,178 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>History</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="AlarmHistoryTree" name="twHistory"/>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Configure History Parameters</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="_2">
<property name="leftMargin">
<number>7</number>
</property>
<property name="topMargin">
<number>7</number>
</property>
<property name="rightMargin">
<number>7</number>
</property>
<property name="bottomMargin">
<number>7</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>191</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboPeriod">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<item>
<property name="text">
<string>Last Day</string>
</property>
</item>
<item>
<property name="text">
<string>Last Week</string>
</property>
</item>
<item>
<property name="text">
<string>Last Month</string>
</property>
</item>
<item>
<property name="text">
<string>Interval</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<widget class="QWidget" name="widgetHistoryConf" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="2">
<widget class="QTimeEdit" name="timeStart"/>
</item>
<item row="0" column="1">
<widget class="QDateEdit" name="dateStart">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="currentSection">
<enum>QDateTimeEdit::MonthSection</enum>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDateEdit" name="dateStop">
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>To:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QTimeEdit" name="timeStop"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>From:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="pBApplyHistory">
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabTest">
<attribute name="title">
<string>Test</string>
......@@ -513,6 +685,11 @@
<extends>QListView</extends>
<header>alarminfow.h</header>
</customwidget>
<customwidget>
<class>AlarmHistoryTree</class>
<extends>QTreeView</extends>
<header>AlarmHistoryTree.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
......@@ -32,15 +32,15 @@ MySqlModel::MySqlModel(QObject *parent) : QSqlQueryModel(parent)
QVariant MySqlModel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlQueryModel::data(index, role);
if (value.isValid() && role == Qt::DisplayRole) {
if (index.column() == 0)
{
QDateTime data;
double v = value.toDouble();
data.setTime_t((int) v);
data = data.addMSecs(1000 *(v - (int) v));
return data.toString("d MMM yyyy hh:mm:ss.zzz");
}
}
// if (value.isValid() && role == Qt::DisplayRole) {
// if (index.column() == 0)
// {
// QDateTime data;
// double v = value.toDouble();
// data.setTime_t((int) v);
// data = data.addMSecs(1000 *(v - (int) v));
// return data.toString("d MMM yyyy hh:mm:ss.zzz");
// }
// }
return value;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment