<commit_before>#include "mainwindow.h"
#include "ui_mainwindow.h"
#ifdef Q_WS_QWS
#include "alphanumpad.h"
#include "numpad.h"
#include "timepopup.h"
#endif

const QString trendsTPACDirectory ="/local/flash/data/customtrend";
const QString trendsPCDirectory ="C:/sandbox/plotter/trunk/SimplePlotter/trends";

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // build on target
#ifdef Q_WS_QWS
  QMainWindow::showFullScreen();
  QWSServer::setCursorVisible( false );
#endif



    QValidator *validatorDeltaLine = new QIntValidator(1, 10000, this);
    ui->deltaLineEdit->setValidator (validatorDeltaLine);

    QString IpRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
    QRegExp IpRegex ("^" + IpRange
                     + "(\\." + IpRange + ")"
                     + "(\\." + IpRange + ")"
                     + "(\\." + IpRange + ")$");
    QRegExpValidator *ipValidator = new QRegExpValidator(IpRegex, this);

    ui->ipLineEdit->setValidator (ipValidator);

    ui->ipLineEdit->setText ("192.168.5.165");

    ui->getValuesPushButton->setEnabled (false);

    //on_radioDay_toggled(true);

    mectPtr=new mectComm();


    ui->radioDay->setChecked (true);
    ui->deltaLineEdit->setText ("200");


    pb=new QProgressBar(ui->customPlot);
    pb->setVisible (false);

#ifdef Q_WS_QWS
  ui->fromDateTimeEdit->setCalendarPopup (true);
  ui->toDateTimeEdit->setCalendarPopup (true);
#endif


    qCustomPlotSetUp();

    connect(mectPtr,SIGNAL(variablesReady()),this,SLOT(fillList()));
    connect(mectPtr,SIGNAL(dataReady()),this,SLOT(getValue()));
    connect(mectPtr,SIGNAL(errorSignal(QString)),this,SLOT(errorManager(QString)));
    connect(ui->customPlot, SIGNAL(legendClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)),
             this, SLOT(legendClick(QCPLegend*,QCPAbstractLegendItem*)));


}

MainWindow::~MainWindow()
{
    delete ui;
    //delete mectPtr;

}

void MainWindow::on_getVarPushButton_clicked()
{
    if(!ui->ipLineEdit->text ().isEmpty ())  {

        ui->varListWidget->clear ();

        ui->getValuesPushButton->setEnabled (false);

        if(mectPtr->openConnection (ui->ipLineEdit->text ())){

            if(mectPtr->requestVariableList (ui->ipLineEdit->text ())){

                ui->getVarPushButton->setEnabled (false);
                ui->ipLineEdit->setEnabled (false);

            }
        }
    }else{
         QMessageBox::critical (this," Error ","There is no IP ");
    }
}

void MainWindow::on_getTrendPushButton_clicked()
{
    if(!ui->ipLineEdit->text ().isEmpty ())  {

        ui->varListWidget->clear ();
        trendList.clear();

#ifdef Q_WS_QWS
        QDir trendsDirectory(trendsTPACDirectory);
#else
        QDir trendsDirectory(trendsPCDirectory);
#endif
        if(trendsDirectory.exists()){

            trendList=trendsDirectory.entryList(QStringList() << "*.csv" << "*.CSV",QDir::Files);
            fillTrendList();

        }else{

            QMessageBox::critical (this," Error ","Directory doesn't exist: "+ trendsDirectory.path());
        }
    }else{
        QMessageBox::critical (this," Error ","There is no IP ");
    }
}

void MainWindow::fillTrendList()
{
    ui->getVarPushButton->setEnabled (true);
    ui->ipLineEdit->setEnabled (true);

    if( trendList.count () ){

        trendList.sort ();
        trendList.removeDuplicates ();

        ui->varListWidget->addItems (trendList);
        ui->varListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
        for(int i = 0; i < ui->varListWidget->count(); ++i)  {
            QListWidgetItem* item = 0;
            item = ui->varListWidget->item(i);
           //item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
            //item->setCheckState(Qt::Unchecked);
        }

    ui->getValuesPushButton->setEnabled (true);
    ui->getValuesPushButton->setText("Plot Trend");
    }else{

        QMessageBox::critical (this," Trend List ","No Trends on target");
    }
}

void MainWindow::fillList()
{
    ui->getVarPushButton->setEnabled (true);
    ui->ipLineEdit->setEnabled (true);

    QStringList varList;

    mectPtr->getVariableList (varList);


    if( varList.count () ){

        varList.sort ();
        varList.removeDuplicates ();

        ui->varListWidget->addItems (varList);
        ui->varListWidget->setSelectionMode(QAbstractItemView::NoSelection);

        for(int i = 0; i < ui->varListWidget->count(); ++i)  {
            QListWidgetItem* item = 0;
            item = ui->varListWidget->item(i);

            item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
            item->setCheckState(Qt::Unchecked);
        }

    ui->getValuesPushButton->setEnabled (true);
    ui->getValuesPushButton->setText("Plot Values");
    }else{

        QMessageBox::critical (this," Variable List ","No Logged variables on target");
    }
}


void MainWindow::on_getValuesPushButton_clicked()
{
    ui->getValuesPushButton->setEnabled(false);

    if(ui->getValuesPushButton->text()=="Plot Values") {
        if(ui->varListWidget->count() > 0){
            QList <QListWidgetItem*> items;

            variableList.clear ();

            for(int i=0;i<ui->varListWidget->count ();i++){

                items.append (ui->varListWidget->item (i));
            }

            for(int i=0;i<items.count();i++){

                if (items.at(i)->checkState() == Qt::Checked){
                    variableList.append (items.at (i)->text ());
                }
            }

            progressBar(0);
            if (! mectPtr->requestValueList (ui->ipLineEdit->text (),ui->fromDateTimeEdit->dateTime (),ui->toDateTimeEdit->dateTime ()
                                             ,ui->deltaLineEdit->text (),variableList)) {
                progressBar(100);
                ui->getValuesPushButton->setEnabled(true);
            }
        }
        else {
            ui->getValuesPushButton->setEnabled(true);
        }
    }

    else if(ui->getValuesPushButton->text()=="Plot Trend"){

        if(ui->varListWidget->count() >0){
            QList <QListWidgetItem*> items;
            QString itemTrendText;

            for(int i=0;i<ui->varListWidget->count ();i++){

                items.append (ui->varListWidget->item (i));
            }

            for(int i=0;i<items.count();i++){

                if (items.at(i)->isSelected()){
                    itemTrendText=items.at (i)->text ();
                    break;
                }
            }
            if(!itemTrendText.isEmpty()){
#ifdef Q_WS_QWS
                QString filePath("/local/flash/data/customtrend/");
#else
                QString filePath("C:/sandbox/plotter/trunk/SimplePlotter/trends/");
#endif

                QFile file(filePath+itemTrendText);
                if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
                    QMessageBox::critical (this," Trends List ","Can't Open the file: "+itemTrendText);
                    ui->getValuesPushButton->setEnabled(true);
                    return;
                }

                QStringList trendData;
                QString tmp;
                variableList.clear();
                QTextStream in(&file);
                int trendIndex=0;
                while (!in.atEnd()) {
                    QString line = in.readLine();
                    if(trendIndex!=0){
                        trendData=line.split(";",QString::SkipEmptyParts);
                        tmp=trendData.at(1);
                        tmp.replace(" ","");
                        trendData.replace(1,tmp);
                       // tmp=trendData.at(2);
                       // trendData.replace(2,"#"+tmp);
                        variableList.append(tmp);
                    }
                    trendIndex++;
             }
            if(!variableList.isEmpty()){
                progressBar(0);<commit_msg>AnyTPAC/SimplePlotter: fix path names<commit_after>#include "mainwindow.h"
#include "ui_mainwindow.h"
#ifdef Q_WS_QWS
#include "alphanumpad.h"
#include "numpad.h"
#include "timepopup.h"
#endif

#ifdef Q_WS_QWS
const QString trendsPath ="/local/data/customtrend/";
#else
const QString trendsPath ="C:/sandbox/plotter/trunk/SimplePlotter/trends/";
#endif

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // build on target
#ifdef Q_WS_QWS
  QMainWindow::showFullScreen();
  QWSServer::setCursorVisible( false );
#endif



    QValidator *validatorDeltaLine = new QIntValidator(1, 10000, this);
    ui->deltaLineEdit->setValidator (validatorDeltaLine);

    QString IpRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
    QRegExp IpRegex ("^" + IpRange
                     + "(\\." + IpRange + ")"
                     + "(\\." + IpRange + ")"
                     + "(\\." + IpRange + ")$");
    QRegExpValidator *ipValidator = new QRegExpValidator(IpRegex, this);

    ui->ipLineEdit->setValidator (ipValidator);

    ui->ipLineEdit->setText ("192.168.5.45");

    ui->getValuesPushButton->setEnabled (false);

    //on_radioDay_toggled(true);

    mectPtr=new mectComm();


    ui->radioDay->setChecked (true);
    ui->deltaLineEdit->setText ("200");


    pb=new QProgressBar(ui->customPlot);
    pb->setVisible (false);

#ifdef Q_WS_QWS
  ui->fromDateTimeEdit->setCalendarPopup (true);
  ui->toDateTimeEdit->setCalendarPopup (true);
#endif


    qCustomPlotSetUp();

    connect(mectPtr,SIGNAL(variablesReady()),this,SLOT(fillList()));
    connect(mectPtr,SIGNAL(dataReady()),this,SLOT(getValue()));
    connect(mectPtr,SIGNAL(errorSignal(QString)),this,SLOT(errorManager(QString)));
    connect(ui->customPlot, SIGNAL(legendClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)),
             this, SLOT(legendClick(QCPLegend*,QCPAbstractLegendItem*)));


}

MainWindow::~MainWindow()
{
    delete ui;
    //delete mectPtr;

}

void MainWindow::on_getVarPushButton_clicked()
{
    if(!ui->ipLineEdit->text ().isEmpty ())  {

        ui->varListWidget->clear ();

        ui->getValuesPushButton->setEnabled (false);

        if(mectPtr->openConnection (ui->ipLineEdit->text ())){

            if(mectPtr->requestVariableList (ui->ipLineEdit->text ())){

                ui->getVarPushButton->setEnabled (false);
                ui->ipLineEdit->setEnabled (false);

            }
        }
    }else{
         QMessageBox::critical (this," Error ","There is no IP ");
    }
}

void MainWindow::on_getTrendPushButton_clicked()
{
    if(!ui->ipLineEdit->text ().isEmpty ())  {

        ui->varListWidget->clear ();
        trendList.clear();


        QDir trendsDirectory(trendsPath);

        if(trendsDirectory.exists()){

            trendList=trendsDirectory.entryList(QStringList() << "*.csv" << "*.CSV",QDir::Files);
            fillTrendList();

        }else{

            QMessageBox::critical (this," Error ","Directory doesn't exist: "+ trendsDirectory.path());
        }
    }else{
        QMessageBox::critical (this," Error ","There is no IP ");
    }
}

void MainWindow::fillTrendList()
{
    ui->getVarPushButton->setEnabled (true);
    ui->ipLineEdit->setEnabled (true);

    if( trendList.count () ){

        trendList.sort ();
        trendList.removeDuplicates ();

        ui->varListWidget->addItems (trendList);
        ui->varListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
        for(int i = 0; i < ui->varListWidget->count(); ++i)  {
            QListWidgetItem* item = 0;
            item = ui->varListWidget->item(i);
           //item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
            //item->setCheckState(Qt::Unchecked);
        }

    ui->getValuesPushButton->setEnabled (true);
    ui->getValuesPushButton->setText("Plot Trend");
    }else{

        QMessageBox::critical (this," Trend List ","No Trends on target");
    }
}

void MainWindow::fillList()
{
    ui->getVarPushButton->setEnabled (true);
    ui->ipLineEdit->setEnabled (true);

    QStringList varList;

    mectPtr->getVariableList (varList);


    if( varList.count () ){

        varList.sort ();
        varList.removeDuplicates ();

        ui->varListWidget->addItems (varList);
        ui->varListWidget->setSelectionMode(QAbstractItemView::NoSelection);

        for(int i = 0; i < ui->varListWidget->count(); ++i)  {
            QListWidgetItem* item = 0;
            item = ui->varListWidget->item(i);

            item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
            item->setCheckState(Qt::Unchecked);
        }

    ui->getValuesPushButton->setEnabled (true);
    ui->getValuesPushButton->setText("Plot Values");
    }else{

        QMessageBox::critical (this," Variable List ","No Logged variables on target");
    }
}


void MainWindow::on_getValuesPushButton_clicked()
{
    ui->getValuesPushButton->setEnabled(false);

    if(ui->getValuesPushButton->text()=="Plot Values") {
        if(ui->varListWidget->count() > 0){
            QList <QListWidgetItem*> items;

            variableList.clear ();

            for(int i=0;i<ui->varListWidget->count ();i++){

                items.append (ui->varListWidget->item (i));
            }

            for(int i=0;i<items.count();i++){

                if (items.at(i)->checkState() == Qt::Checked){
                    variableList.append (items.at (i)->text ());
                }
            }

            progressBar(0);
            if (! mectPtr->requestValueList (ui->ipLineEdit->text (),ui->fromDateTimeEdit->dateTime (),ui->toDateTimeEdit->dateTime ()
                                             ,ui->deltaLineEdit->text (),variableList)) {
                progressBar(100);
                ui->getValuesPushButton->setEnabled(true);
            }
        }
        else {
            ui->getValuesPushButton->setEnabled(true);
        }
    }

    else if(ui->getValuesPushButton->text()=="Plot Trend"){

        if(ui->varListWidget->count() >0){
            QList <QListWidgetItem*> items;
            QString itemTrendText;

            for(int i=0;i<ui->varListWidget->count ();i++){

                items.append (ui->varListWidget->item (i));
            }

            for(int i=0;i<items.count();i++){

                if (items.at(i)->isSelected()){
                    itemTrendText=items.at (i)->text ();
                    break;
                }
            }
            if(!itemTrendText.isEmpty()){
                QFile file(trendsPath+itemTrendText);

                if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
                    QMessageBox::critical (this," Trends List ","Can't Open the file: "+itemTrendText);
                    ui->getValuesPushButton->setEnabled(true);
                    return;
                }

                QStringList trendData;
                QString tmp;
                variableList.clear();
                QTextStream in(&file);
                int trendIndex=0;
                while (!in.atEnd()) {
                    QString line = in.readLine();
                    if(trendIndex!=0){
                        trendData=line.split(";",QString::SkipEmptyParts);
                        tmp=trendData.at(1);
                        tmp.replace(" ","");
                        trendData.replace(1,tmp);
                       // tmp=trendData.at(2);
                       // trendData.replace(2,"#"+tmp);
                        variableList.append(tmp);
                    }
                    trendIndex++;
             }
            if(!variableList.isEmpty()){
                progressBar(0);
{'fraction_non_alphanumeric': 0.153387220939184, 'fraction_numerical': 0.006992558378239672, 'mean_word_length': 2.2416302765647744, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 243, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4023537', 'n_tokens_mistral': 4930, 'n_tokens_neox': 4640, 'n_words': 688}