Ejemplo n.º 1
0
int main(int argc, char * argv[])
{
    int counter1 = 0;
    int hashValue;
    int sizeOfList = 102;
    int * sizePtr = &sizeOfList;
    bucket * root;
    //bucket * conductor;
    char ** wordList;
    char * toBeHashed;
    char userInput[BUFSIZE];

    FILE* inputFile;
    
    if (argc != 2)
    {
        printf("Please input a file name and nothing else.\n");
        exit(0);
    }

    inputFile = fopen(argv[1], "r");
    if (inputFile == NULL)
    {
        printf("The file '%s' does not exist.  Quiting.\n", argv[1]);
        exit(0);
    }

    wordList = readFile(inputFile);
    fclose(inputFile);

    root = initLinkedList(sizePtr);    

    if(root == NULL)
    {
        printf("Error creating linked list, quiting...\n");
        exit(0);
    }

    while (wordList[counter1] != NULL)
    {
        hashValue = findHash(wordList[counter1]);
        addHash(hashValue, wordList[counter1], root);
        counter1++;
    }
    free(wordList);

    printf("List successfully hashed! Ready for queries: ");
    while (1==1)
    {
        fgets(userInput, BUFSIZE, stdin);
        toBeHashed = malloc(strlen(userInput)+1);
        strcpy(toBeHashed, userInput);
        hashValue = findHash(toBeHashed);

        queryDatabase(hashValue, root, toBeHashed);
        printf("Ready for queries: ");
    }

    return 0;
}
Ejemplo n.º 2
0
void QuranDbHelper::updateNote(QString surah, QString ayat, QString note) {
	QString query = "update Quran set note= '"+note+"' where SuraID = "
				+ surah + " and VerseID = " + ayat;

		// execute query
		queryDatabase(query);
}
MatrixXf param_sensitivity_widget::readParameterValues(QStringList realizations,
        QStringList parameters)
{
    realizations.sort();
    parameters.sort();

    MatrixXf real_params_val(realizations.size(), parameters.size()+1);

    for (unsigned int i = 0; i < realizations.size(); ++i)
    {
        QString realizationName = realizations.at(i);
        real_params_val(i,0) = 1;

        for (unsigned j = 0; j < parameters.size(); ++j)
        {
            QString parameterName = parameters.at(j);
            QString parameterValueStr = queryDatabase(parameterName,
                                        realizationName);

            float paramValueNum;

            if (!isCastable(parameterValueStr,paramValueNum))
                paramValueNum = 0.0f;

            // Write to matrix
            real_params_val(i,j+1) = paramValueNum;
        }
    }

    return real_params_val;
}
Ejemplo n.º 4
0
void QuranDbHelper::removeBookmark(QString surah, QString ayat) {
	QString query = "update Quran set bookmarked='false'  where SuraID ="
			+ surah + " and VerseID = " + ayat;

	// execute query
	queryDatabase(query);
}
bool MDSParameterExplorerTabWidget::isCastable(QString parameter,
                                               QString property)
{
    QString parameterValue = queryDatabase(parameter,property);

    bool ok;
    parameterValue.toFloat(&ok);
    return ok;
}
void MDSParameterExplorerTabWidget::displayParameters()
{

    QList<QListWidgetItem*> selProp =
            this->ui->completePropertiesList1->selectedItems();

    QString selectedProperty;

    // Make sure something is selected
    if (selProp.size()>0)
    {
        parameterModel *displayParameterModel = new parameterModel(this);

        selectedProperty = selProp.at(0)->data(Qt::DisplayRole).toString();

        // Find which algorithm to use
        QString usedAlgorithm =
                mdsObject_->readPropertyAlgorithm(selectedProperty);


        QStringList *completeParameterList =
                mdsObject_->getParameterNames(usedAlgorithm);

        QStringList selectedPropertyList;
        selectedPropertyList.append(selectedProperty);
        emit(this->highlightCommonModels(selectedPropertyList));


        for (int i = 0; i < completeParameterList->size(); ++i)
        {

            QString parameterValue = queryDatabase(completeParameterList->at(i),
                                                   selectedProperty);

            std::cout << "name: " << completeParameterList->at(i).toStdString() << " "
                      << parameterValue.toStdString() << std::endl;
            displayParameterModel->addNode(completeParameterList->at(i),
                                           parameterValue,
                                           displayParameterModel->root());

        }

        displayParameterModel->expandAll();

        // Resize columns to fit parameter names
        displayParameterModel->resizeColumnToContents(0);
        displayParameterModel->resizeColumnToContents(1);
        displayParameterModel->setHeaderHidden(true);

        this->ui->parametersTreeScrollArea->setWidget(displayParameterModel);
    }


}
Ejemplo n.º 7
0
void MainWindow::threadRun()
{
    QCoreApplication::flush();
    QString queryString = "select * from teensydata order by DeviceID ASC, Timestamp ASC";
    QSqlQueryModel *queryModel = new QSqlQueryModel();

    bool ret = 0;

    ret = queryDatabase(queryModel, queryString);

    if (ret == true)
    {
        /* Display contents in tableView */
        ui->tableView->setModel(queryModel);

        /* Call plotting function */
        makePlot();
    }
    else
    {
        ui->label_success->setText("Failed");
    }
}
Ejemplo n.º 8
0
bool param_search_widget::update()
{
    // Find search type
    // Hard code for now just use +/=

    // Map QString to boolean operator
    // Generate a vector with all properties values
    std::vector<float> parameterValues;

    for (unsigned int i = 0; i < propertyList_.size(); ++i)
        parameterValues.push_back(queryDatabase(currentSearchParam_,
                                                propertyList_.at(i)).toFloat());

    std::vector<bool> searchResults;

    if (ui->comboBoxSearch->currentText() == QString("<"))
        searchResults =
            numericalCompare(parameterValues,
                             ui->lineEditSearchValue->text().toFloat(),
                             std::less<float>());
    else if (ui->comboBoxSearch->currentText() == QString(">"))
        searchResults =
            numericalCompare(parameterValues,
                             ui->lineEditSearchValue->text().toFloat(),
                             std::greater<float>());
    else if (ui->comboBoxSearch->currentText() == QString(">="))
        searchResults =
            numericalCompare(parameterValues,
                             ui->lineEditSearchValue->text().toFloat(),
                             std::greater_equal<float>());
    else if (ui->comboBoxSearch->currentText() == QString("<="))
        searchResults =
            numericalCompare(parameterValues,
                             ui->lineEditSearchValue->text().toFloat(),
                             std::less_equal<float>());
    else if (ui->comboBoxSearch->currentText() == QString("=="))
        searchResults =
            numericalCompare(parameterValues,
                             ui->lineEditSearchValue->text().toFloat(),
                             std::equal_to<float>());
    else if (ui->comboBoxSearch->currentText() == QString("!="))
        searchResults =
            numericalCompare(parameterValues,
                             ui->lineEditSearchValue->text().toFloat(),
                             std::not_equal_to<float>());

    // Generate results table view
    model = new QStandardItemModel(searchResults.size(),2,this);
    model->setHeaderData(0, Qt::Horizontal, tr("Realization"));
    model->setHeaderData(1, Qt::Horizontal, tr("Param Value"));


    int numFound = 0;

    for (unsigned int i = 0; i < searchResults.size(); ++i)
    {
        if (searchResults.at(i))
        {
            model->setData(model->index(numFound,0,QModelIndex()),
                           propertyList_.at(i));
            model->setData(model->index(numFound,1,QModelIndex()),
                           parameterValues.at(i));

            numFound++;
        }
    }

    ui->tableViewResults->setModel(model);
    ui->tableViewResults->horizontalHeader()->setStretchLastSection(true);

    return true;

}
Ejemplo n.º 9
0
void MainWindow::makePlot()
{
    int row = 0, list = 0;
    QSqlQueryModel *tableModel = new QSqlQueryModel;
    tableModel = (QSqlQueryModel*)ui->tableView->model();

    QStringList deviceID;

    deviceID << tableModel->record(0).value(0).toString();
    for (row = 1; row < tableModel->rowCount(); row++)
    {
        if (tableModel->record(row).value(0).toString() != tableModel->record(row-1).value(0).toString())
        {
            deviceID << tableModel->record(row).value(0).toString();
        }
    }

    int listSize = deviceID.size();

    for (row = 0; row < listSize; row++)
    {
        addLine(row);
    }
//    for (row = listSize; row < 2*listSize; row++)
//    {
//        addDot(row, listSize);
//    }

    ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltNumber);
    ui->customPlot->xAxis->setNumberFormat("g");
    ui->customPlot->xAxis->setAutoTickStep(false);
    ui->customPlot->xAxis->setTickStep(1);
    ui->customPlot->axisRect()->setupFullAxesBox();

    // make left and bottom axes transfer their ranges to right and top axes:
    connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));

    QString queryString;
    QSqlQueryModel *queryModel = new QSqlQueryModel();
    double xMax = 0;

    bool ret = 0;

//    ui->customPlot->legend->setVisible(false);
//    ui->customPlot->legend->setVisible(true);
//    ui->customPlot->legend->setFont(QFont("Helvetica", 9));
//    ui->customPlot->legend->setRowSpacing(-3);

    for (list = 0; list < listSize; list++)
    {
        double x = 0;
        double y = 0;
        queryString = "select Data from teensydata where DeviceID=\"" + deviceID[list] + "\" order by Timestamp ASC";
        ret = queryDatabase(queryModel, queryString);

        ui->customPlot->graph(list)->setName(deviceID[list]);
        if (ret == true)
        {
            for (row = 0; row < queryModel->rowCount(); row++)
            {
                y = queryModel->record(row).value(0).toDouble();
                /* Add data to lines*/
                ui->customPlot->graph(list)->addData(x++, y);
                /* Add dots to latest data */
//                ui->customPlot->graph(list + listSize)->clearData();
//                ui->customPlot->graph(list + listSize)->addData(x-1, y);
//                ui->customPlot->legend->removeItem(list + listSize);

                //ui->customPlot->graph(list)->rescaleValueAxis(true);
                ui->customPlot->replot();
                if (x > xMax)
                {
                    xMax = x;
                }
            }
        }
    }
    ui->customPlot->xAxis->setRange(xMax-10, 10, Qt::AlignLeft);
    ui->customPlot->yAxis->setRange(0, 1023);
}
Ejemplo n.º 10
0
int ObjectRecognition::find(Mat _image)
{
	//-----------------------------------------------------------
	//  image = imread( "../../../New_modules1/image_014.jpeg");
	//  image = imread( "../../../TestDATA/snap-unknown-20120901-203157-1.jpeg" );
	//  imshow( "mywindow", image );
	//  waitKey(0);


	//      imshow("Capure_Image", image);
	//      waitKey();

	//-----------------Extract the features----------------------------
	//cout<< ss.str() << endl;
	double t = (double)cvGetTickCount(); 
	loadFeatures(_image, keypoints, features, descriptors);

	//-----------------Query the Database----------------------------
	//cout <<endl<<"-----------------Start to QUERY-------------------" <<endl;
	queryDatabase(features, db, ret, ret_num);
	//testAP(ret); 
	//cout << ret <<endl;
	//t = (double)cvGetTickCount()-t;
	//       cout << "voc tree time = " <<  t/((double)cvGetTickFrequency()*1000)<< endl;
	//if (ret[0].Score<0.6 && ret[0].Score>0.24)
	{
		cout << "        Start to Homography   " <<endl;
		initModule_nonfree();
		double HomographyT = (double)cvGetTickCount();
		checkHomography( _image, keypoints, descriptors, ret);
		HomographyT = (double)cvGetTickCount()-HomographyT;
		cout << "Homography time (ms) = " <<  HomographyT/((double)cvGetTickFrequency()*1000)<< endl;
		sort(ret.begin(), ret.end());
		//       if ((ranking/(OBJ_IMG+1))==(ret[0].Id/(OBJ_IMG+1)))
		// 	AP+=1;

		 	//cout<<ret<<endl<<endl;
	}


	int dis_id=0;
	bool ret_correct_flag = false;
	int ret_end = ret.size()-1;
	if (ret[ret_end].Score>ret[0].Score) 
	{
		if(ret[ret_end].Id/10==ret[ret_end-1].Id/10)
		{
			dis_id = ret_end;
			ret_correct_flag = true;
		}
	}
	else 
	{
		if (ret[1].Id/10==ret[0].Id/10)
		{
			dis_id = 0;
			ret_correct_flag = true;
		}
	}


	if ((ret[dis_id].Score>=0.6) && ret_correct_flag)
	{

		cout<< "-----Object "<< ret[dis_id].Id << " is detected!!!---------------"<<endl;
		return ret[dis_id].Id;
		// 	stringstream ss;
		// 	ss<<"../../../New_modules1/image_";
		// 	if(ret[dis_id].Id<10) 			ss<< "00"<<ret[dis_id].Id<< ".jpeg";
		// 	if(ret[dis_id].Id>=10&&ret[dis_id].Id<100) 	ss<< "0"<<ret[dis_id].Id<<".jpeg";
		// 	if(ret[dis_id].Id>=100	)		ss<< ret[dis_id].Id<<".jpeg";
		// 	cout<< ss.str()<< endl;
		// 	Mat r=imread(ss.str());
		// // 	namedWindow(ss.str());
		// // 	imshow(ss.str(), r);
		// // 	moveWindow(ss.str(), 650, 0);
		// 	imshow("result", r);
		//          waitKey(0);
	}
	else
	{
		cout<< "No object!!!!!"<<endl;
		return 255;

	}
	//cout<<"AP is : " << AP <<endl<<endl<<endl;
	//testAP(ret);

	//------------------------------------------------------------------

	//        waitKey(0);
	//       if ( (waitKey(1) & 255) == 27 ) break;

	return 255;
}