示例#1
0
// ------------------------------------readMovieFile-----------------------------------------
// Description: reads from .txt file and insert each movie in
// movies in corresponding binary search tree.
// ------------------------------------------------------------------------------------------
void Store::readMovieFile()
{
	const string movieFileName = "data4movies.txt";
	fstream infile(movieFileName, ios_base::in);
	
	if (infile.fail())
	{
		cerr << "Can't find movie file: " << movieFileName << endl;
		return;
	}
	
    while(!infile.eof())
    {
        Movie *movie = MovieFactory::Create(infile);
        if (movie)
        {
            switch (movie->getMovieType())
            {
                case MovieType::ComedyType:
                    ComedyTree.insert(dynamic_cast<Comedy *>(movie));
                    break;
                case MovieType::DramaType:
                    DramaTree.insert(dynamic_cast<Drama *>(movie));
                    break;
                case MovieType::ClassicalType:
                    ClassicsTree.insert(dynamic_cast<Classics *>(movie));
                    break;
                default:
                    throw new logic_error("Unexpected type");
                    
            }
        }
    }
}
示例#2
0
/**
 * @brief Called when backdrop scraping has finished
 * Starts the next backdrop download or tells the movie that scraping is done
 */
void Cinefacts::backdropFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    reply->deleteLater();
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    QStringList backdrops = reply->property("backdrops").toStringList();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    if (!movie)
        return;

    if (reply->error() == QNetworkReply::NoError) {
        QString msg = QString::fromUtf8(reply->readAll());
        QRegExp rx("<a href=\"([^\"]*)\" target=\"_blank\">Bild in Originalgr..e</a>");
        rx.setMinimal(true);
        if (rx.indexIn(msg) != -1) {
            Poster p;
            p.thumbUrl = rx.cap(1);
            p.originalUrl = rx.cap(1);
            movie->addBackdrop(p);
        }

        if (!backdrops.isEmpty()) {
            reply = qnam()->get(QNetworkRequest(QUrl(QString("http://www.cinefacts.de%1").arg(backdrops.takeFirst()))));
            reply->setProperty("storage", Storage::toVariant(reply, movie));
            reply->setProperty("backdrops", backdrops);
            reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
            connect(reply, SIGNAL(finished()), this, SLOT(backdropFinished()));
            return;
        }
    }
    movie->controller()->scraperLoadDone(this);
}
示例#3
0
void IMDB::onLoadFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    reply->deleteLater();
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    if (!movie)
        return;

    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = QString::fromUtf8(reply->readAll());
        parseAndAssignInfos(msg, movie, infos);
        QString posterUrl = parsePosters(msg);
        if (infos.contains(MovieScraperInfos::Poster) && !posterUrl.isEmpty()) {
            QNetworkReply *reply = qnam()->get(QNetworkRequest(posterUrl));
            reply->setProperty("storage", Storage::toVariant(reply, movie));
            reply->setProperty("infosToLoad", Storage::toVariant(reply, infos));
            connect(reply, SIGNAL(finished()), this, SLOT(onPosterLoadFinished()));
        } else {
            movie->controller()->scraperLoadDone(this);
        }
    } else {
        qWarning() << "Network Error (load)" << reply->errorString();
    }
}
示例#4
0
/**
 * @brief Called when backdrops are loaded
 */
void VideoBuster::backdropFinished()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(QObject::sender());
    Movie *movie = reply->property("storage").value<Storage*>()->movie();
    QList<int> infos = reply->property("infosToLoad").value<Storage*>()->infosToLoad();
    reply->deleteLater();
    if (!movie)
        return;

    if (reply->error() == QNetworkReply::NoError ) {
        QString msg = reply->readAll();
        QRegExp rx("href=\"https://gfx.videobuster.de/archive/resized/([^\"]*)\"(.*)([^<]*)<img (.*) src=\"https://gfx.videobuster.de/archive/resized/c110/([^\"]*)\"");
        rx.setMinimal(true);
        int pos = 0;
        while ((pos = rx.indexIn(msg, pos)) != -1) {
            pos += rx.matchedLength();
            if (rx.cap(2).contains("titledtl_cover_pictures")) {
                continue;
            }
            Poster p;
            p.thumbUrl = QUrl(QString("https://gfx.videobuster.de/archive/resized/w700/%1").arg(rx.cap(5)));
            p.originalUrl = QUrl(QString("https://gfx.videobuster.de/archive/resized/%1").arg(rx.cap(1)));
            movie->addBackdrop(p);
        }
    } else {
        qWarning() << "Network Error" << reply->errorString();
    }
    movie->controller()->scraperLoadDone();
}
示例#5
0
void MovieCollection::topTen()
{
	//creating a copy of the array
	Movie tempArray[CAPACITY];
	for (int i=0; i < mySize; i++)
	{
		tempArray[i] = myArray[i];
	}
	//sort the copied array by the number of times rented in descending order
	for (int i=1; i < mySize; i++)
	{
		Movie tempMovie = tempArray[i];
		int j = i-1;
		while (j >= 0 && tempMovie.getNumTimesRented() >
			tempArray[j].getNumTimesRented())
		{
			tempArray[j+1] = tempArray[j];
			j = j-1;
		}
		tempArray[j+1] = tempMovie;
	}

	//output the first 10 movies of the array (if available)
	int iterations = 10;
	if (mySize < 10) {
		iterations = mySize;
	}
	cout << "--------------------Top Ten---------------------" << endl;
	for (int i=0; i < iterations; i++)
	{
		cout << "Movie: " << tempArray[i].getTitle() << "       ";
		cout << "Times Rented: " << tempArray[i].getNumTimesRented() << endl;
	}
	cout << "------------------------------------------------" << endl << endl;
}
示例#6
0
void OmdbDataProvider::GetMovieList(string &path, vector<Movie> & movies){
    fs::path p (path);   // p reads clearer than argv[1] in the following code
    try {
        if (!fs::exists(p)){     // does p actually exist?
            cout << p << " does not exist." << endl;
            return;
        }
        if (fs::is_directory(p)){       // is p a directory?
            vec v;                                // so we can sort them later
            copy(fs::directory_iterator(p), fs::directory_iterator(), back_inserter(v));
            sort(v.begin(), v.end());             // sort, since directory iteration
            // is not ordered on some file systems
            for (auto it = v.begin(); it != v.end(); ++it){
                string fn = it->filename().string();
                if(fn[0] == '.' && fn.size() > 1) continue;
                size_t f = fn.find("(");
                Movie m;
                m.Set(FIELDS::NAME, fn.substr(0, f-1));
                m.Set(FIELDS::YEAR, fn.substr(f+1, 4));
                m.SetVotes(0);
                m.SetRate(0);
                movies.push_back(m);
            }
        }
    }
    catch (const fs::filesystem_error& ex){
        cerr << ex.what() << endl;
//        exit(EXIT_FAILURE);
        return;
    }
}
示例#7
0
文件: lwf_movie.cpp 项目: KitoHo/lwf
void Movie::LinkButton()
{
	if (!visible || !active || !hasButton)
		return;

	for (int dlDepth = 0; dlDepth < data->depths; ++dlDepth) {
		Object *obj = m_displayList[dlDepth].get();
		if (obj) {
			if (obj->IsButton()) {
				((Button *)obj)->LinkButton();
			} else if (obj->IsMovie()) {
				Movie *movie = (Movie *)obj;
				if (movie->hasButton)
					movie->LinkButton();
			}
		}
	}

	if (!m_attachedMovies.empty()) {
		AttachedMovieList::iterator it(m_attachedMovieList.begin()),
			itend(m_attachedMovieList.end());
		for (; it != itend; ++it)
			if (it->second && it->second->hasButton)
				it->second->LinkButton();
	}

	if (!m_attachedLWFs.empty()) {
		AttachedLWFList::iterator
			it(m_attachedLWFList.begin()), itend(m_attachedLWFList.end());
		for (; it != itend; ++it)
			if (it->second)
				it->second->LinkButton();
	}
}
bool StoreManager::checkIn(int customerId, int movieId)
{
	Customer *customer = findCustomer(customerId);
	Movie *movie = findMovie(movieId);

	if (customer == NULL)
		std::cout << "Customer not found.\n\n";

	if (movie == NULL)
		std::cout << "Movie not found.\n\n";

	if (customer == NULL || movie == NULL)
		return false;

	std::set<Movie *> movies = customer->getMovies();

	for (std::set<Movie *>::iterator it = movies.begin(); it != movies.end(); ++it)
	{
		if (*it == movie)
		{
			customer->removeMovie(movie);
			movie->setInCount(movie->getInCount() + 1);
			movie->setOutCount(movie->getOutCount() - 1);
			return true;
		}
	}

	std::cout << "That movie was not found in customer's profile.\n\n";

	return false;
	
}
示例#9
0
文件: lwf_core.cpp 项目: ElAleyo/lwf
Button *LWF::SearchButtonInstance(string instanceName) const
{
	size_t pos = instanceName.find(".");
	if (pos != string::npos) {
		vector<string> names = Utility::Split(instanceName, '.');
		if (names[0] != data->strings[m_rootMovieStringId])
			return 0;

		Movie *m = rootMovie.get();
		for (size_t i = 1; i < names.size(); ++i) {
			if (i == names.size() - 1) {
				return m->SearchButtonInstance(names[i], false);
			} else {
				m = m->SearchMovieInstance(names[i], false);
				if (!m)
					return 0;
			}
		}

		return 0;
	}

	int stringId = GetStringId(instanceName);
	if (stringId == -1)
		return rootMovie->SearchButtonInstance(instanceName, true);

	return SearchButtonInstance(stringId);
}
示例#10
0
int LWF::AddMovieEventHandler(
	string instanceName, const MovieEventHandlerDictionary &h)
{
	if (h.empty())
		return -1;

	int instId = SearchInstanceId(GetStringId(instanceName));
	if (instId >= 0)
		return AddMovieEventHandler(instId, h);

	if (instanceName.find('.') == string::npos)
		return -1;

	MovieEventHandlersDictionary::iterator it =
		m_movieEventHandlersByFullName.find(instanceName);
	if (it == m_movieEventHandlersByFullName.end()) {
		m_movieEventHandlersByFullName[instanceName] = MovieEventHandlers();
		it = m_movieEventHandlersByFullName.find(instanceName);
	}
	int id = GetEventOffset();
	it->second.Add(id, h);

	Movie *m = SearchMovieInstance(instId);
	if (m)
		m->AddHandlers(&it->second);

	return id;
}
示例#11
0
vector<Movie*>MoFileRepo::findAll()
{
	vector<Movie*> v;
	Movie* pm;
	ifstream in(fileName);
	if(!in.is_open())
		cout <<"Failed to open movies file!findAll()"<<fileName<<endl;
	else
	{
		while(!in.eof())
		{
			pm = new Movie ;
			cout<<v.size()<<"---------------------------------"<<endl;
			in >> *pm;
			if(pm->getTitle().length() == 0)
				delete pm;
			else{
				v.push_back(pm);
			}
			cout<<v.size()<<"---------------------------------"<<endl;
		}
		in.close();
	}
	return v;
}
示例#12
0
shared_ptr<class LWF> LWFNode::attachLWF(
	const char *pszFilename, const char *pszTarget, const char *pszAttachName)
{
	if (!lwf)
		return shared_ptr<class LWF>();

	shared_ptr<LWFData> data =
		LWFResourceCache::sharedLWFResourceCache()->loadLWFData(pszFilename);
	if (!data)
		return shared_ptr<class LWF>();

	shared_ptr<LWFRendererFactory> factory =
		make_shared<LWFRendererFactory>(this);
	shared_ptr<class LWF> child = make_shared<class LWF>(data, factory);
	if (!child) {
		LWFResourceCache::sharedLWFResourceCache()->unloadLWFData(data);
		return child;
	}

	Movie *movie = lwf->SearchMovieInstance(pszTarget);
	if (!movie) {
		LWFResourceCache::sharedLWFResourceCache()->unloadLWFData(data);
		return shared_ptr<class LWF>();
	}

	movie->AttachLWF(child, pszAttachName);

	return child;
}
示例#13
0
Instruction* Borrow:: create(MovieStore* store, ifstream& infile) const {
    int id;
    Customer* customerToBeProcessed = NULL;
    infile >> id;
    if ((store->customers).retrieve(id, customerToBeProcessed)) {
        char mediaT, movieT;
        Movie* movieToBeSearch = NULL;
        infile >> mediaT >> movieT;
        movieToBeSearch = movieFactory->createSimpleIt(movieT, infile);
        if (movieToBeSearch == NULL) {
            string reading;
            getline(infile, reading);
            return NULL;
        }
        Movie* movieToBeProcessed = NULL;
        if ((store->moviesDatabase)[hash(movieT)]->
            retrieve(movieToBeSearch, movieToBeProcessed)) {
            if (movieToBeProcessed->borrowType(mediaT, 1)) {
                customerToBeProcessed->addOwn(movieToBeProcessed);
                Borrow* newInstruction = new Borrow;
                newInstruction->movie = movieToBeProcessed;
                newInstruction->customer = customerToBeProcessed;
                newInstruction->mediaType = mediaT;
                newInstruction->customer->addHistory(newInstruction);
                return newInstruction;
            }
        }
    }
示例#14
0
ostream& operator<<(ostream& os, const ActIn& ai) {
  Person p = ai.actorId;
  os << "\t\tActor ID: " << p.getId() << endl;
  Movie m = ai.movieId;
  os << "\t\tMovie ID: " << m.getId() << endl;

  return os;
}
示例#15
0
void FilesWidget::unmarkForSync()
{
    m_contextMenu->close();
    foreach (const QModelIndex &index, ui->files->selectionModel()->selectedRows(0)) {
        int row = index.model()->data(index, Qt::UserRole).toInt();
        Movie *movie = Manager::instance()->movieModel()->movie(row);
        movie->setSyncNeeded(false);
        ui->files->update(index);
    }
}
示例#16
0
void Theater::AddMovie(Movie& Movie)
{
	

	timeKeeper[counter] = Movie.GetShowtime();
	genreKeeper[counter] = Movie.GetGenre();
	movieTitleKeeper[counter] = Movie.GetTitle();
	
	counter++;
}
示例#17
0
void FilesWidget::openFolder()
{
    m_contextMenu->close();
    int row = ui->files->currentIndex().data(Qt::UserRole).toInt();
    Movie *movie = Manager::instance()->movieModel()->movie(row);
    if (movie->files().isEmpty())
        return;
    QFileInfo fi(movie->files().at(0));
    QDesktopServices::openUrl(QUrl::fromLocalFile(fi.absolutePath()));
}
示例#18
0
// This function takes the values that are stored in the "Movie" class and makes them accessiable in the "Theater" class
// This function takes the values taken from the "Movie" class and stores them into the corresponding array 
void Theater::AddMovie(Movie& Movie)
{
	MovieTITLE[x] = Movie.getTitle(); // Takes the value of "MovieTitle" from the "Movie" class and stores it in the "MovieTITLE" array
	MovieHOURS[y] = Movie.getShowTime(); // Takes the value of "MovieShowTime" from the "Movie" class and stores it in the "MovieHOURS" array
	MovieGENRE[z] = Movie.getGenre(); // Takes the value of "MovieGenre" from the "Movie" class and stores it in the "MovieGENRE" array

	x++; // Increases the the variable in the "MovieTITLE" array by one so that it can take in the next value 
	y++; // Increases the the variable in the "MovieHOURS" array by one so that it can take in the next value 
	z++; // Increases the the variable in the "MovieGENRE" array by one so that it can take in the next value 
}
示例#19
0
void MovieValidator::validate(const Movie& m) throw (ValidatorException)
{
    if(m.getTitle().length() == 0)
        throw ValidatorException("Movie title is empty!");
    if(m.getType().length() == 0)
        throw ValidatorException("Movie type is empty!");
    if(m.getDesc().length() == 0)
        throw ValidatorException("Movie description is empty!");
    if(m.getAvailable() != 0 and m.getAvailable()!=1)
        throw ValidatorException("Movie availability is invalid!");
}
示例#20
0
/**
 * Iteratively train each feature on the entire data set
 * Once sufficient progress has been made, move on
 */
void Svd::calculateFeatures()
{
    double err, p, sq, rmse_last, rmse = 2.0;
    float cf, mf;

    printf("--Total Users: %d", currentMovie.dataBase()->totalUsers());
    for (int f = 0; f < 5 && f < MAX_FEATURES; ++f) {
        printf("\n--- Calculating feature: %d ---\n", f);
        // Keep looping until you have passed a minimum number
        // of epochs or have stopped making significant progress
        User user(currentMovie.dataBase());
        int totalUsers = currentMovie.dataBase()->totalUsers();
        int movieId;
        for (int e = 0; (e < MIN_EPOCHS) || (rmse <= rmse_last - MIN_IMPROVEMENT); ++e) {
            sq = 0;
            rmse_last = rmse;
            int cacheId = 0;
            user.setId(1);
            for (int i = 0; i < totalUsers; ++i) {
                int custId = currentMovie.dataBase()->mapUser(user.id());
                for (int v = 0; v < user.votes(); ++v) {
                    movieId = user.movie(v);
                    // Predict rating and calc error
                    p = predictRating(movieId, custId, f, cache[cacheId], true);

                    err = (1.0 * user.score(v) - p);
                    sq += err * err;

                    // Cache off old feature values
                    cf = m_aCustFeatures[f][custId];
                    mf = m_aMovieFeatures[f][movieId];
                    // Cross-train the features
                    m_aCustFeatures[f][custId] += (float)(LRATE * (err * mf - K * cf));
                    m_aMovieFeatures[f][movieId] += (float)(LRATE * (err * cf - K * mf));
                    ++cacheId;
                }
                user.next();
            }
            rmse = sqrt(sq / MAX_RATINGS);
            printf("     <set x='%d' y='%f' e='%d'/>\n", e * f + e, rmse, e);
        }

        int cacheId = 0;
        // Cache off old predictions
        user.setId(6);
        for (int i = 0; i < currentMovie.dataBase()->totalUsers(); ++i) {
            for (int v = 0; v < user.votes(); ++v) {
                cache[cacheId] = (float)predictRating(user.movie(v), i, f, cache[cacheId], false);
                ++cacheId;
            }
            user.next();
        }
    }
}
示例#21
0
string MoviesSystem::printAllMovieDetails(string movieId) {
	string result = "";
	Movie* movie = this->findMovie(movieId);
	if (movie != NULL) {
		result += movie->toString();
	} else {
		result += "Failure\n";
	}
	string resultToSend = result.c_str();
	return resultToSend;
}
示例#22
0
void MovieCollection::display(ostream& stream) const
{
	stream << "---------------------Movies---------------------" << endl;
	for (int i = 0; i < mySize; i++)
	{
		Movie tempMovie = myArray[i];
		stream << tempMovie.getTitle() << " : ";
		stream << tempMovie.getNumInStore() << " copies in store" << endl;
	}
	stream << endl;
}
示例#23
0
string MoviesSystem::setSortingTypeMovie(string movieId, int sortingTypeToAdd) {
	string result = "";
	if (this->isSortingTypeValid(sortingTypeToAdd)) {
		Movie* movie = this->findMovie(movieId);
		movie->setSortingType(sortingTypeToAdd);
		result += "Success\n";
	} else {
		result += "Failure\n";
	}
	string resultToSend = result.c_str();
	return resultToSend;
}
示例#24
0
void ActsIn::printMovieActorMultiMap(Movie searchMovie) {
  cout << "Printing Multi-Map..." << endl;
  pair<multimap<Movie, Person>::iterator, multimap<Movie, Person>::iterator> p;
  p = movieActorMultiMap.equal_range(searchMovie);
  cout << endl << "Key					Value" << endl;
  for (multimap<Movie, Person>::iterator it = p.first; it != p.second; ++it) {
    Movie tempMovie = it->first;
    Person tempPerson = it->second;
    //string tempName = (*it).second.getFName();
    cout << tempMovie.getTitle() << "\t" << tempPerson.getLName() << " " << tempPerson.getFName() << endl;
  }
}
示例#25
0
/**
 * Loop through the entire list of finished features
 */
double Svd::determine(int user)
{
    double sum = 1; //m_aMovies[movieId].PseudoAvg;

    int movieId = currentMovie.id();
    int userId = currentMovie.dataBase()->mapUser(user);
    for (int feature = 0; feature < MAX_FEATURES; ++feature) {
        sum += m_aMovieFeatures[feature][movieId] * m_aCustFeatures[feature][userId];
    }
    if (sum < 1.0) sum = 1.0;
    else if (sum > 5.0) sum = 5.0;
    return sum;
}
示例#26
0
string MoviesSystem::printAllProfessionalsOfMovie(string movieId) {
	string result = "";
	Movie* movie = this->findMovie(movieId);
	if (movie != NULL) {
		for (vector<Professional*>::iterator it = movie->getStaff().begin();
				it != movie->getStaff().end(); ++it) {
			result += "~~-/SEPARATOR/-~~\n";
			result += (*it)->toString();		}
	} else {
		result += "Failure\n";
	}
	string resultToSend = result.c_str();
	return resultToSend;
}
bool StoreManager::checkOut(int customerId, int movieId)
{
	Customer *customer = findCustomer(customerId);
	Movie *movie = findMovie(movieId);

	if (customer == NULL)
		std::cout << "Customer not found.\n\n";

	if (movie == NULL)
		std::cout << "Movie not found.\n\n";

	if (customer == NULL || movie == NULL)
		return false;
	else
	{
		if (movie->getOutCount() == movie->getStockCount())
		{
			std::cout << movie->getTitle() << " is out of stock.\n"
				<< "Cannot add to customer # " << customer->getId() << "\n\n";
			return false;
		}
		else
		{
			customer->addMovie(movie);
			movie->setInCount(movie->getInCount() - 1);
			movie->setOutCount(movie->getOutCount() + 1);
			return true;
		}
	}
}
示例#28
0
void FilesWidget::markAsUnwatched()
{
    m_contextMenu->close();
    foreach (const QModelIndex &index, ui->files->selectionModel()->selectedRows(0)) {
        int row = index.model()->data(index, Qt::UserRole).toInt();
        Movie *movie = Manager::instance()->movieModel()->movie(row);
        if (movie->watched())
            movie->setWatched(false);
        if (movie->playcount() != 0)
            movie->setPlayCount(0);
    }
    if (ui->files->selectionModel()->selectedRows(0).count() > 0)
        movieSelectedEmitter();
}
示例#29
0
void Store::loadMovies(){
    string line;
    ifstream file ("src/movies.txt");
    if (file.is_open()){

        int input = 0;
        Movie aMovie = Movie();
        while (getline(file,line,';')) {
            if(input > 6) {
                this->rentals.insert(aMovie);
                aMovie = Movie();
                input = 0;
            }
            switch(input) {
                case 0: aMovie.setTitle(line);
                        break;
                case 1: aMovie.setReleased(line);
                        break;
                case 2: aMovie.setGenre(line);
                        break;
                case 3: aMovie.setDuration(line);
                        break;
                case 4: aMovie.setDirector(line);
                        break;
                case 5: aMovie.setRating(line);
                        break;
                case 6: aMovie.setStars(line);
                        break;
            }
            ++input;
        }
        file.close();
    } else cout << "Unable to open file";

} // end Store::loadMovies();
示例#30
0
MovieCollection::MovieCollection(const string& fileName) {
	ifstream fin( fileName.c_str() );
	assert( fin.is_open() );

	Movie aMovie;
	while (true) {
		aMovie.readFrom(fin);
		if ( !fin ) break;
		string blankLine;
		getline(fin, blankLine);
		myMovies.push_back(aMovie);
	}
	fin.close();
}