示例#1
0
/*
 * @brief		Main function to classify a collection (list of datasets)
 *
 * This function is the main call of the classification system. It takes a set of parameters and launch computations.
 *
 * @param       mParameter* Global parameters to apply for the system
 *
 */
void                    classifyCollection(mParameters *param)
{
    collection          *datasets;
    dataset             *current, *test;
    distances           *distanceSet;
    criteria            *criterias;
    char                *directories;
    int                 i;
    
    datasets = importCollection(param->collection, 0);
    if (datasets == NULL)
        return;
    criterias = init_criteria(1);
    distanceSet = init_distances(1);
    directories = calloc(1024, sizeof(char));
    for (i = 0; i < datasets->size; i++)
    {
        current = NULL;
        printf("Processing dataset : %s - %s\n", datasets->name[i], datasets->path[i]);
        // Preparing output directories
        sprintf(directories, "%s/%s", param->output, datasets->name[i]);
        umask(0); mkdir(directories, 0777);
        sprintf(directories, "%s/%s/distances", param->output, datasets->name[i]);
        umask(0); mkdir(directories, 0777);
        sprintf(directories, "%s/%s/optimize_distance", param->output, datasets->name[i]);
        umask(0); mkdir(directories, 0777);
        sprintf(directories, "%s/%s/optimize_criteria", param->output, datasets->name[i]);
        umask(0); mkdir(directories, 0777);
        sprintf(directories, "%s/%s/results", param->output, datasets->name[i]);
        umask(0); mkdir(directories, 0777);
        if (datasets->type[i] == TYPE_LOO || datasets->type[i] == TYPE_TRAIN)
            current = importRaw(datasets->path[i], datasets->name[i], NULL, 0);
        if (datasets->type[i] == TYPE_LOO_MULTI || datasets->type[i] == TYPE_TRAIN_MULTI)
            current = importRawMultiple(datasets->path[i], datasets->name[i]);
        if (current == NULL) { printf("Skipping.\n"); continue; }
        if (datasets->type[i] == TYPE_LOO)
            classifyDatasetLOO(current, distanceSet, criterias);
        if (datasets->type[i] == TYPE_LOO_MULTI)
            classifyDatasetLOO(current, distanceSet, criterias);
        if (datasets->type[i] == TYPE_TRAIN)
        {
            test = importRaw(datasets->path_test[i], datasets->name[i], current->class_vals, current->nb_classes);
            if (test == NULL) { printf("Skipping.\n"); continue; }
            optimizeDatasetTT(current, distanceSet, criterias, param);
            classifyDatasetTT(current, test, distanceSet, criterias, param);
        }
        freeDataset(current, datasets->type[i]);
    }
    free(directories);
}
示例#2
0
MainWindow::MainWindow(QWidget *parent)
	: QMainWindow(parent)
	, ui_()
	, poolWindow_()
	, cardWindow_()
	, collectionWindow_()
	, deckWindow_()
{
	ui_.setupUi(this);

	loadSettings();

	// window management
	ui_.actionPoolWindow->setChecked(poolWindow_.isVisible());
	connect(ui_.actionPoolWindow, SIGNAL(toggled(bool)), this, SLOT(poolWindowActionToggled(bool)));
	connect(&poolWindow_, SIGNAL(windowClosed(bool)), ui_.actionPoolWindow, SLOT(setChecked(bool)));
	ui_.actionCardWindow->setChecked(cardWindow_.isVisible());
	connect(ui_.actionCardWindow, SIGNAL(toggled(bool)), this, SLOT(cardWindowActionToggled(bool)));
	connect(&cardWindow_, SIGNAL(windowClosed(bool)), ui_.actionCardWindow, SLOT(setChecked(bool)));
	ui_.actionCollectionWindow->setChecked(collectionWindow_.isVisible());
	connect(ui_.actionCollectionWindow, SIGNAL(toggled(bool)), this, SLOT(collectionWindowActionToggled(bool)));
	connect(&collectionWindow_, SIGNAL(windowClosed(bool)), ui_.actionCollectionWindow, SLOT(setChecked(bool)));
	ui_.actionDeckWindow->setChecked(deckWindow_.isVisible());
	connect(ui_.actionDeckWindow, SIGNAL(toggled(bool)), this, SLOT(deckWindowActionToggled(bool)));
	connect(&deckWindow_, SIGNAL(windowClosed(bool)), ui_.actionDeckWindow, SLOT(setChecked(bool)));

	// options
	connect(ui_.actionOptions, SIGNAL(triggered()), this, SLOT(optionsActionClicked()));

	// about
	connect(ui_.actionAbout, SIGNAL(triggered()), this, SLOT(aboutActionClicked()));
	connect(ui_.actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));

	// import collection
	connect(ui_.actionImportCollection, SIGNAL(triggered()), this, SLOT(importCollection()));

	// import decks
	connect(ui_.actionImportDeckFromXML, SIGNAL(triggered()), this, SLOT(importDeckFromXML()));
	connect(ui_.actionImportDeckFromText, SIGNAL(triggered()), this, SLOT(importDeckFromText()));

	// global filter
	connect(ui_.actionGlobalFilter, SIGNAL(triggered()), this, SLOT(globalFilter()));
	connect(this, SIGNAL(globalFilterChanged()), &poolWindow_, SLOT(handleGlobalFilterChanged()));
	connect(this, SIGNAL(globalFilterChanged()), &collectionWindow_, SLOT(handleGlobalFilterChanged()));
	connect(this, SIGNAL(globalFilterChanged()), &deckWindow_, SLOT(handleGlobalFilterChanged()));

	// online manual
	connect(ui_.actionOnlineManual, SIGNAL(triggered()), this, SLOT(onlineManual()));

	// card preview
	connect(&poolWindow_, SIGNAL(selectedCardChanged(int)), &cardWindow_, SLOT(changeCardPicture(int)));
	connect(&collectionWindow_, SIGNAL(selectedCardChanged(int)), &cardWindow_, SLOT(changeCardPicture(int)));
	connect(&deckWindow_, SIGNAL(selectedCardChanged(int)), &cardWindow_, SLOT(changeCardPicture(int)));

	// add / remove
	connect(&poolWindow_, SIGNAL(addToCollection(QVector<int>)), &collectionWindow_, SLOT(addToCollection(QVector<int>)));
	connect(&poolWindow_, SIGNAL(removeFromCollection(QVector<int>)), &collectionWindow_, SLOT(removeFromCollection(QVector<int>)));
	connect(&poolWindow_, SIGNAL(addToDeck(QVector<int>)), &deckWindow_, SLOT(addToDeck(QVector<int>)));
	connect(&poolWindow_, SIGNAL(removeFromDeck(QVector<int>)), &deckWindow_, SLOT(removeFromDeck(QVector<int>)));
	connect(&collectionWindow_, SIGNAL(addToDeck(QVector<int>)), &deckWindow_, SLOT(addToDeck(QVector<int>)));
	connect(&collectionWindow_, SIGNAL(removeFromDeck(QVector<int>)), &deckWindow_, SLOT(removeFromDeck(QVector<int>)));
	connect(&deckWindow_, SIGNAL(addToCollection(QVector<int>)), &collectionWindow_, SLOT(addToCollection(QVector<int>)));
	connect(&deckWindow_, SIGNAL(addToCollection(QVector<QPair<int,int>>)), &collectionWindow_, SLOT(addToCollection(QVector<QPair<int,int>>)));
	connect(&deckWindow_, SIGNAL(removeFromCollection(QVector<int>)), &collectionWindow_, SLOT(removeFromCollection(QVector<int>)));

	// open used decks
	connect(&collectionWindow_, SIGNAL(requestOpenDeck(QString)), &deckWindow_, SLOT(handleOpenDeckRequest(QString)));
}
CollectionSetup::CollectionSetup( QWidget *parent )
        : QWidget( parent )
        , m_rescanDirAction( new QAction( this ) )
{
    m_ui.setupUi(this);

    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );

    setObjectName( "CollectionSetup" );
    s_instance = this;

    if( KGlobalSettings::graphicEffectsLevel() != KGlobalSettings::NoEffects )
        m_ui.view->setAnimated( true );
    connect( m_ui.view, SIGNAL(clicked(QModelIndex)),
             this, SIGNAL(changed()) );

    connect( m_ui.view, SIGNAL(pressed(QModelIndex)),
             this, SLOT(slotPressed(QModelIndex)) );
    connect( m_rescanDirAction, SIGNAL(triggered()),
             this, SLOT(slotRescanDirTriggered()) );

    KPushButton *rescan = new KPushButton( KIcon( "collection-rescan-amarok" ), i18n( "Full rescan" ), m_ui.buttonContainer );
    rescan->setToolTip( i18n( "Rescan your entire collection. This will <i>not</i> delete any statistics." ) );
    connect( rescan, SIGNAL(clicked()), CollectionManager::instance(), SLOT(startFullScan()) );

    KPushButton *import = new KPushButton( KIcon( "tools-wizard" ), i18n( "Import" ), m_ui.buttonContainer );
    import->setToolTip( i18n( "Import collection and/or statistics from older Amarok versions, the batch scanner or media players." ) );
    connect( import, SIGNAL(clicked()), this, SLOT(importCollection()) );

    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addWidget( rescan );
    buttonLayout->addWidget( import );
    m_ui.buttonContainer->setLayout( buttonLayout );

    m_recursive = new QCheckBox( i18n("&Scan folders recursively (requires full rescan if newly checked)"), m_ui.checkboxContainer );
    m_monitor   = new QCheckBox( i18n("&Watch folders for changes"), m_ui.checkboxContainer );
    connect( m_recursive, SIGNAL(toggled(bool)), this, SIGNAL(changed()) );
    connect( m_monitor  , SIGNAL(toggled(bool)), this, SIGNAL(changed()) );

    QVBoxLayout *checkboxLayout = new QVBoxLayout();
    checkboxLayout->addWidget( m_recursive );
    checkboxLayout->addWidget( m_monitor );
    m_ui.checkboxContainer->setLayout( checkboxLayout );

    m_recursive->setToolTip( i18n( "If selected, Amarok will read all subfolders." ) );
    m_monitor->setToolTip( i18n( "If selected, the collection folders will be watched "
            "for changes.\nThe watcher will not notice changes behind symbolic links." ) );

    m_recursive->setChecked( AmarokConfig::scanRecursively() );
    m_monitor->setChecked( AmarokConfig::monitorChanges() );

    // set the model _after_ constructing the checkboxes
    m_model = new CollectionFolder::Model( this );
    m_ui.view->setModel( m_model );
    #ifndef Q_OS_WIN
    m_ui.view->setRootIndex( m_model->setRootPath( QDir::rootPath() ) );
    #else
    m_ui.view->setRootIndex( m_model->setRootPath( m_model->myComputer().toString() ) );
    #endif

    Collections::Collection *primaryCollection = CollectionManager::instance()->primaryCollection();
    QStringList dirs = primaryCollection ? primaryCollection->property( "collectionFolders" ).toStringList() : QStringList();
    m_model->setDirectories( dirs );

    // make sure that the tree is expanded to show all selected items
    foreach( const QString &dir, dirs )
    {
        QModelIndex index = m_model->index( dir );
        m_ui.view->scrollTo( index, QAbstractItemView::EnsureVisible );
    }
CollectionSetup::CollectionSetup( QWidget *parent )
        : KVBox( parent )
{
    DEBUG_BLOCK

    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );

    setObjectName( "CollectionSetup" );
    s_instance = this;

    (new QLabel( i18n(
        "These folders will be scanned for "
        "media to make up your collection:"), this ))->setAlignment( Qt::AlignJustify );

    m_view  = new QTreeView( this );
    m_view->setHeaderHidden( true );
    m_view->setRootIsDecorated( true );
    m_view->setAnimated( true );
    m_view->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    connect( m_view, SIGNAL( clicked( const QModelIndex & ) ), this, SIGNAL( changed() ) );

    KHBox* buttonBox = new KHBox( this );

    KPushButton *rescan = new KPushButton( KIcon( "collection-rescan-amarok" ), i18n( "Rescan Collection" ), buttonBox );
    connect( rescan, SIGNAL( clicked() ), CollectionManager::instance(), SLOT( startFullScan() ) );

    KPushButton *import = new KPushButton( KIcon( "tools-wizard" ), i18n( "Import Collection" ), buttonBox );
    connect( import, SIGNAL( clicked() ), this, SLOT( importCollection() ) );

    m_recursive = new QCheckBox( i18n("&Scan folders recursively"), this );
    m_monitor   = new QCheckBox( i18n("&Watch folders for changes"), this );
    connect( m_recursive, SIGNAL( toggled( bool ) ), this, SIGNAL( changed() ) );
    connect( m_monitor  , SIGNAL( toggled( bool ) ), this, SIGNAL( changed() ) );

    m_recursive->setToolTip( i18n( "If selected, Amarok will read all subfolders." ) );
    m_monitor->setToolTip(   i18n( "If selected, folders will automatically get rescanned when the content is modified, e.g. when a new file was added." ) );

    m_recursive->setChecked( AmarokConfig::scanRecursively() );
    m_monitor->setChecked( AmarokConfig::monitorChanges() );

    // set the model _after_ constructing the checkboxes
    m_model = new CollectionFolder::Model();
    m_view->setModel( m_model );
    #ifndef Q_OS_WIN
    m_view->setRootIndex( m_model->setRootPath( QDir::rootPath() ) );
    #else
    m_view->setRootIndex( m_model->setRootPath( m_model->myComputer().toString() ) );
    #endif
    
    // Read config values
    //we have to detect if this is the actual first run and not get the collectionFolders in that case
    //there won't be any anyway and accessing them creates a Sqlite database, even if the user wants to
    //use another database
    //bug 131719 131724
    //if( !Amarok::config().readEntry( "First Run", true ) )
    QStringList dirs = MountPointManager::instance()->collectionFolders();
    m_model->setDirectories( dirs );
    
    // make sure that the tree is expanded to show all selected items
    foreach( const QString &dir, dirs )
    {
        QModelIndex index = m_model->index( dir );
        m_view->scrollTo( index, QAbstractItemView::EnsureVisible );
    }