Пример #1
0
void TimeAnalysisWidget::on_applyButton_clicked()
{
    bool low = _ui->lowRadioButton->isChecked();
    int numClusters = _ui->numClustersSpin->value();
    std::vector<Point*> &points = low?_lowPoints.data():_highPoints.data();

    std::vector<Point> centers;
    std::vector<int> assignment;
    PointClusterer::kmeans(PointClusterer::RANDOM,numClusters,
                           PointClusterer::EUCLIDEAN,
                           points, 10, centers, assignment);

    std::ostringstream ss;
    ss << "K-means " << numClusters << (low?" [low]":" [high]");
    Scalar *scalar = addScalar(ss.str());

    // create labels
    scalar->labels().clear();
    for (unsigned i=0; i<centers.size(); ++i) {
        ss.str("");
        ss << "Cluster [" << i << "]";
        scalar->labels().push_back(ss.str());
    }

    // assigne scalar values to points
    for (unsigned i=0; i<assignment.size(); ++i) {
        Point *p = _lowPoints.data()[i];
        p->setScalarValue(scalar, assignment[i]);
    }

    // refill combox
    fillScalarComboBox();
    _ui->colorByComboBox->setCurrentIndex(scalar->index());
}
Пример #2
0
void TimeAnalysisWidget::loadLowAndHighData(std::string filename)
{
    std::string basename = filename.substr(0, filename.find_last_of('.'));    
    _highPoints.load(basename + ".high");

    //_lowPoints.load(basename + ".low");
    //_lowPoints.load(basename + ".low_normalized_cols");
//    _lowPoints.load(basename + ".low_normalized_rows");
    _lowPoints.load(basename + ".low_standarised");
    //_lowPoints.load(basename + ".low_unnormalized");

    // adding default scalars
    Scalar *noneScalar = addScalar("None");
    noneScalar->labels().push_back("None");

    Scalar *dayScalar = addScalar("Day");
    for (int i=0; i<7; ++i)
        dayScalar->labels().push_back(QDate::longDayName(i+1).toStdString());

    Scalar *wend_wdayScalar = addScalar("Weekend/Weekdays");
    wend_wdayScalar->labels().push_back("Weekdays");
    wend_wdayScalar->labels().push_back("Weekends");

    for (int i=0; i<_lowPoints.numPoints(); ++i) {
        Point *lp = _lowPoints.data()[i];
        Point *hp = _highPoints.data()[i];

        QDate d = lp->getDate();

        lp->setScalarValue(noneScalar, 0);
        lp->setScalarValue(dayScalar, d.dayOfWeek()-1);
        lp->setScalarValue(wend_wdayScalar, d.dayOfWeek()==6||d.dayOfWeek()==7);

        hp->setScalarValue(noneScalar, 0);
        hp->setScalarValue(dayScalar, d.dayOfWeek());
        hp->setScalarValue(wend_wdayScalar, d.dayOfWeek()==6||d.dayOfWeek()==7);
    }
}