Example #1
0
Action::Action(QObject *parent)
    : QProcess(parent)
    , m_failed(false)
    , m_firstProcess(NULL)
    , m_currentLine(-1)
{
    setProcessChannelMode(QProcess::SeparateChannels);
    connect( this, SIGNAL(error(QProcess::ProcessError)),
             SLOT(actionError(QProcess::ProcessError)) );
    connect( this, SIGNAL(started()),
             SLOT(actionStarted()) );
    connect( this, SIGNAL(finished(int,QProcess::ExitStatus)),
             SLOT(actionFinished()) );
    connect( this, SIGNAL(readyReadStandardError()),
             SLOT(actionErrorOutput()) );

    connect( this, SIGNAL(readyReadStandardOutput()),
             this, SLOT(actionOutput()) );

    quintptr id = actionId(this);
    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    env.insert("COPYQ_ACTION_ID", QString::number(id));
    setProcessEnvironment(env);
    setProperty("COPYQ_ACTION_ID", id);

    const QMutexLocker lock(&actionsLock);
    actions.append(this);
}
Example #2
0
Action::Action(const Commands &cmd,
               const QByteArray &input, const QString &outputItemFormat,
               const QString &itemSeparator,
               const QString &outputTabName, const QModelIndex &index)
    : QProcess()
    , m_input(input)
    , m_sep(index.isValid() ? QString() : itemSeparator)
    , m_cmds(cmd)
    , m_tab(outputTabName)
    , m_outputFormat(outputItemFormat != "text/plain" ? outputItemFormat : QString())
    , m_index(index)
    , m_errstr()
    , m_lastOutput()
    , m_failed(false)
    , m_firstProcess(NULL)
{
    setProcessChannelMode(QProcess::SeparateChannels);
    connect( this, SIGNAL(error(QProcess::ProcessError)),
             SLOT(actionError(QProcess::ProcessError)) );
    connect( this, SIGNAL(started()),
             SLOT(actionStarted()) );
    connect( this, SIGNAL(finished(int,QProcess::ExitStatus)),
             SLOT(actionFinished()) );
    connect( this, SIGNAL(readyReadStandardError()),
             SLOT(actionErrorOutput()) );

    if ( !outputItemFormat.isEmpty() ) {
        connect( this, SIGNAL(readyReadStandardOutput()),
                 SLOT(actionOutput()) );
    }
}
/*
 * 获得最新的功率数据
*/
datatype DataProcessor::getLastPower()
{
    if(realTimeDataBuffer.isEmpty())
    {
        emit actionError();
        return 0.0;
    }
    return realTimeDataBuffer.first().eps;
}
/*
 * 调节函数开始
*/
void DataProcessor::regulatorAction()
{
    if(realTimeDataBuffer.isEmpty())
    {
        emit actionError();
        return;
    }
    regulator->sendThershold((int)ProporitonLimit,MinPowerDataPoint,realTimeDataBuffer.at(0));
}
/*
 * 设置限位比例
*/
void DataProcessor::setProportion(float proportion)
{
    if(proportion>0&&proportion<1)
    {
        ProporitonLimit = proportion;
    }
    else
    {
        emit actionError();
    }
}
void DataProcessor::testCount()
{
    PowerAfterTest = realTimeDataBuffer.first().eps;
    if(PowerBeforeTest != 0.0)
    {
        SavingRate = (PowerBeforeTest - PowerAfterTest) / PowerBeforeTest;
        emit sendTestResult(PowerBeforeTest,PowerAfterTest,SavingRate);
    }
    else
    {
        SavingRate = 0.0;
        emit actionError();
    }
    regulator->startHardware();

}
/*
*timeLength:计算时间 单位:second
*如果计算时间内的要求数据少于 realdtimedatabuffer 则使用当前记录数据
*/
datatype DataProcessor::getMinPower(int timeLength)
{
    datatype tempminpower = 0.0;
    int   counttime = 0;//计数个数
    int   counter   = 0;//计数

    if(realTimeDataBuffer.isEmpty())//保证有数据
    {
        emit actionError();
        return 0.0;
    }
    counttime = (timeLength>realTimeDataBuffer.size()?realTimeDataBuffer.size():timeLength);//选取取合理的数据个数
    tempminpower = realTimeDataBuffer.first().eps;
    for(counter = 0;counter >= counttime; counter++)//找到最小功率
    {
        tempminpower = (tempminpower<realTimeDataBuffer.at(counter).eps?tempminpower:realTimeDataBuffer.at(counter).eps);//寻找最小功率
    }
    return tempminpower;
}
/*
*timeLength:计算时间 单位:second
*默认计算10分钟内的平均功率,600个数据
*如果计算时间内的要求数据少于 realdtimedatabuffer 则使用当前记录数据
*/
datatype DataProcessor::getAveragePower(int timeLength)
{
    datatype tempaveragepower = 0.0;
    datatype temptotalpower   = 0.0;
    int   counttime = 0;//计数个数
    int   counter   = 0;//计数

    if(realTimeDataBuffer.isEmpty())
    {
        emit actionError();//没有数据情况下报错
        return 0.0;
    }
    counttime = (timeLength>realTimeDataBuffer.size()?realTimeDataBuffer.size():timeLength);//选取取合理的数据个数
    for(counter = 0;counter >= counttime; counter++)//计算总功率
    {
        temptotalpower += realTimeDataBuffer.at(counter).eps * GetDataTimeInterval;
    }
    tempaveragepower = temptotalpower / (float)counttime;
    TotalPower = temptotalpower;
    return tempaveragepower;
}
/*
*向数据库中写入数据
*/
void DataProcessor::saveData()
{
    bool dbreturn;
    if(realTimeDataBuffer.isEmpty())//没有数据存储
    {
        emit actionError();
        return ;
    }
    else
    {
        dbreturn = database->saveData(realTimeDataBuffer.first());//存储当前读取的最新数据
        if(!dbreturn)//数据库存储错误
        {
            saveDataTimer->stop();
            emit dataBaseError();
            return ;
        }
        return ;
    }

}