Esempio n. 1
0
int intpol(int x, uint8_t idx) // -100, -75, -50, -25, 0 ,25 ,50, 75, 100
{
#if defined(XCURVES)
  CurveInfo &crv = g_model.curves[idx];
  int8_t *points = curveAddress(idx);
  uint8_t count = crv.points+5;
  bool custom = (crv.type == CURVE_TYPE_CUSTOM);
#else
  CurveInfo crv = curveInfo(idx);
  int8_t *points = crv.crv;
  uint8_t count = crv.points;
  bool custom = crv.custom;
#endif
  int16_t erg = 0;

  x += RESXu;

  if (x <= 0) {
    erg = (int16_t)points[0] * (RESX/4);
  }
  else if (x >= (RESX*2)) {
    erg = (int16_t)points[count-1] * (RESX/4);
  }
  else {
    uint16_t a=0, b=0;
    uint8_t i;
    if (custom) {
      for (i=0; i<count-1; i++) {
        a = b;
        b = (i==count-2 ? 2*RESX : RESX + calc100toRESX(points[count+i]));
        if ((uint16_t)x<=b) break;
      }
    }
    else {
      uint16_t d = (RESX * 2) / (count-1);
      i = (uint16_t)x / d;
      a = i * d;
      b = a + d;
    }
    erg = (int16_t)points[i]*(RESX/4) + ((int32_t)(x-a) * (points[i+1]-points[i]) * (RESX/4)) / ((b-a));
  }

  return erg / 25; // 100*D5/RESX;
}
Esempio n. 2
0
bool PSV_ChartRealItem::addCurve(const QMap<double, double> &data, const PSV_CurveParam &curveParam)
{
    QString curveName = curveParam.m_curveName;
    if(curveParam.m_isReplace)
    {
        clearCurve(curveName);
    }
    if(m_curveDataMap.contains(curveName) || curveName.isEmpty())
    {
        return false;
    }
    if(data.count() <= 0)
    {
        PSV_Public::printMes(QString::fromLocal8Bit("warning:数据为空"));
        return false;
    }
    QMapIterator<double,double> iter(data);
    PSV_CurveInfo curveInfo(curveName);
    curveInfo.m_axisType = curveParam.m_axisType;
    setCurrentAxisType(curveInfo.m_axisType);
    curveInfo.m_curveType = curveParam.m_curveType;
    double sum = 0.0;
    double max_y = 0.0;
    double min_y = 0.0;
//    double max_y_pointX = 0.0;
//    double min_y_pointX = 0.0;

    double max_x = 0.0;
    double min_x = 0.0;
    bool isFisrt = true;
    while(iter.hasNext())
    {
        iter.next();
        double value = iter.value();
        if(isFisrt)
        {
            isFisrt = false;
            max_y = value;
            min_y = value;
            sum = value;
            max_x = iter.key();
            min_x = iter.key();
//            max_y_pointX = iter.key();
//            min_y_pointX = iter.key();
        }
        else
        {
            sum += value;
            if(max_y < value)
            {
                max_y = value;
//                max_y_pointX = iter.key();
            }
            if(min_y > value)
            {
                min_y = value;
//                min_y_pointX = iter.key();
            }
            if(max_x < iter.key())
            {
                max_x = iter.key();
            }
            if(min_x > iter.key())
            {
                min_x = iter.key();
            }
        }
    }
    if(*m_isFisrtCurve_curP)
    {
        *m_max_y_curP = max_y;
        *m_min_y_curP = min_y;
        if(m_isFisrtCurve_left && m_isFisrtCurve_right)
        {
            m_rangeX.first = min_x;
            m_rangeX.second = max_x;
        }
        *m_isFisrtCurve_curP = false;
    }
    else
    {
        if(*m_max_y_curP < max_y)
        {
            *m_max_y_curP = max_y;
        }
        if(*m_min_y_curP > min_y)
        {
            *m_min_y_curP = min_y;
        }
    }
    if(m_rangeX.first > min_x)
    {
        m_rangeX.first = min_x;
    }
    if(m_rangeX.second < max_x)
    {
        m_rangeX.second = max_x;
    }
    m_max_x = m_rangeX.second;
    m_min_x = m_rangeX.first;
    double avg_y = sum / data.count();
    QStringList textList;
    textList.append(QString("%1:").arg(curveName));
    textList.append(QString(" %1:%2").arg(QString::fromLocal8Bit("最大值")).arg(QString::number(max_y,'f',m_decimal)));
    textList.append(QString(" %1:%2").arg(QString::fromLocal8Bit("最小值")).arg(QString::number(min_y,'f',m_decimal)));
    textList.append(QString(" %1:%2").arg(QString::fromLocal8Bit("平均值")).arg(QString::number(avg_y,'f',m_decimal)));

    QString staHtmText = PSV_Public::getStaText(textList/*,m_staFont*/);
    curveInfo.m_staHtmText = staHtmText;
    curveInfo.m_staText = textList.join("");
    curveInfo.m_curveDataMap = data;
    m_curveDataMap.insert(curveName,curveInfo);
    if(curveParam.m_isUpdate)
    {
        refreshItem();
    }
    return true;
}
bool PSV_ChartDateTimeItem::addCurve(const QMap<QDateTime, double> &data
                                     , const PSV_CurveParam &curveParam
                                     , bool isDate)
{
    QString curveName = curveParam.m_curveName;
    if(curveParam.m_isReplace)
    {
        clearCurve(curveName);
    }
    if(m_curveDataMap.contains(curveName) || curveName.isEmpty())
    {
        return false;
    }
    if(data.count() <= 0)
    {
        PSV_Public::printMes(QString::fromLocal8Bit("warning:数据为空"));
        return false;
    }

    QMap<double,double> curveData;
    QMapIterator<QDateTime,double> iter(data);
    PSV_CurveInfo curveInfo(curveName);
    curveInfo.m_axisType = curveParam.m_axisType;
    setCurrentAxisType(curveInfo.m_axisType);
    curveInfo.m_curveType = curveParam.m_curveType;
    if(isDate)
    {
        curveInfo.m_dataType = PSV::E_DATATYPE_DATE;
    }
    else
    {
        curveInfo.m_dataType = PSV::E_DATATYPE_DATETIME;
    }


    bool isChangedY = false;
    bool isChangedX = false;
    //==========================
    double sum = 0.0;
    double max_y = 0.0;
    double min_y = 0.0;
    QDateTime max_y_pointX = PSV_BEGIN_DATETIME;
    QDateTime min_y_pointX = PSV_BEGIN_DATETIME;

    QDateTime max_x = PSV_BEGIN_DATETIME;
    QDateTime min_x = PSV_BEGIN_DATETIME;

    bool isFisrt = true;

    while(iter.hasNext())
    {
        iter.next();
        if(!iter.key().isValid())
        {
            continue;
        }
        double value = iter.value();
        if(isFisrt)
        {
            isFisrt = false;
            max_y = value;
            min_y = value;
            sum = value;
            max_y_pointX = iter.key();
            min_y_pointX = iter.key();
            max_x = iter.key();
            min_x = iter.key();
        }
        else
        {
            sum += value;
            if(max_y < value)
            {
                max_y = value;
                max_y_pointX = iter.key();
            }
            if(min_y > value)
            {
                min_y = value;
                min_y_pointX = iter.key();
            }
            if(max_x < iter.key())
            {
                max_x = iter.key();
            }
            if(min_x > iter.key())
            {
                min_x = iter.key();
            }
        }
        int sec = m_beginDateTime.secsTo(iter.key());//
        curveData.insert(sec,iter.value());
    }

    if(*m_isFisrtCurve_curP)
    {
        *m_max_y_curP = max_y;
        *m_min_y_curP = min_y;
        if(m_isFisrtCurve_left && m_isFisrtCurve_right)
        {
            m_max_dateTime = max_x;
            m_min_dateTime = min_x;
        }
        *m_isFisrtCurve_curP = false;
    }
    else
    {
        if(*m_max_y_curP < max_y)
        {
            *m_max_y_curP = max_y;
        }
        if(*m_min_y_curP > min_y)
        {
            *m_min_y_curP = min_y;
        }
    }
    if(m_max_dateTime < max_x)
    {
        m_max_dateTime = max_x;
    }
    if(m_min_dateTime > min_x)
    {
        m_min_dateTime = min_x;
    }
//    PSV_Public::printMes(max_y_pointX,"max_y_pointX");
//    PSV_Public::printMes(min_y_pointX,"min_y_pointX");
    m_max_x = m_max_dateTime;
    m_min_x = m_min_dateTime;
//    PSV_Public::printMes(m_max_x,"m_max_x");
//    PSV_Public::printMes(m_min_x,"m_min_x");
    //======================================
    QString dateForm = curveInfo.m_dataType == PSV::E_DATATYPE_DATETIME ? "yyyy-MM-dd hh:mm:ss" : "yyyy-MM-dd";
    double avg_y = sum / data.count();
    QStringList textList;
    int dml = decimal();
    textList.append(QString("%1:").arg(curveName));
    textList.append(QString(" %1:(%2,%3)").arg(QString::fromLocal8Bit("最大值"))
                    .arg(max_y_pointX.toString(dateForm))
                    .arg(QString::number(max_y,'f',dml)));

    textList.append(QString(" %1:(%2,%3)")
                    .arg(QString::fromLocal8Bit("最小值"))
                    .arg(min_y_pointX.toString(dateForm))
                    .arg(QString::number(min_y,'f',dml)));
    textList.append(QString(" %1:%2")
                    .arg(QString::fromLocal8Bit("平均值"))
                    .arg(QString::number(avg_y,'f',dml)));

    QString staHtmText = PSV_Public::getStaText(textList/*,m_staFont*/);
    curveInfo.m_staHtmText = staHtmText;
    curveInfo.m_staText = textList.join("");
    //======================================
    curveInfo.m_curveDataMap = curveData;
    m_curveDataMap.insert(curveName,curveInfo);
    if(curveParam.m_isUpdate)
    {
        if(isChangedY || isChangedX)
        {
//            PSV_Public::printMes("19refreshItem");
            refreshItem();
        }
    }
    return true;
}