VideoAsset::VideoAsset(bfs::path path) : path(path) { try { name = path.filename().string(); readInfoFile(); readTimetable(); readShotBoundaries(); readHistograms(); readMeans(); isReady = false; if(hasTimetable && hasShotBoundaries && hasHistograms && hasMeans) { if(frame2Timestamp.size() != histograms.size() || frame2Timestamp.size() != rgbMeans.size()) { throw VideoAssetException("Info files have wrong format."); } isReady = true; } loadPlayerSync(); } catch (const bfs::filesystem_error& ex) { (*Tobago.log)(Log::ERROR) << "Error loading video asset " << path.string() << ": " << ex.what(); throw VideoAssetException(ex.what()); } }
// =================================================================== // main function // =================================================================== int main(int argc, char * argv[]){ // read in movie in question either via cmd line if(argc != 3){ std::cerr << "usage: " << argv[0] << " movie_id customer_id" << std::endl; return -1; } // get the filename from the movie id std::string new_file = getFilename(argv[1]); // open that movie file and read in numbers to a vector std::vector<int> new_customer_ids; read_movie(new_customer_ids, new_file, atoi(argv[2])); // iterate through ever movie and compare for matches // first check for it being a movie the customer in question watched or break std::vector<int> old_customer_ids; std::vector<int> best_match; int best_match_rating = 0; int matches = 0; int movie_match = 0; for(int i = 1; i <= 1000; i++){ old_customer_ids.clear(); // make the filename std::stringstream ss; ss << i; std::string s = ss.str(); // make sure we aren't using the same movie we are predicting if ( s == argv[1]) continue; // get the filename std::string filename = getFilename(s); // get the vector of id's and customer rating for the movie int customer_rating = read_movie(old_customer_ids, filename, atoi(argv[2])); // means the customer didn't watch the movie and we don't need to check it if (customer_rating == 0) continue; int tmp = compare(old_customer_ids, new_customer_ids); if(tmp > matches){ matches = tmp; movie_match = i; best_match_rating = customer_rating; best_match = old_customer_ids; } } // find average and sd of both movies and rating customer gave std::vector<std::pair<float, float> > stats = readMeans(atoi(argv[1]), movie_match); // standardize and translate over to new movie float normal = (float(best_match_rating) - stats[1].first)/stats[1].second; float rating = normal*stats[0].second + stats[0].first; // helpful print statments std::cout.precision(3); std::cout << "\t\tMovies\tMean\tStd Dev\tRating\n" << "New:\t\t"<< argv[1] << '\t' << stats[0].first << '\t' << stats[0].second << '\t' << rating << "\nBest Match:\t" << movie_match << '\t' << stats[1].first << '\t' << stats[1].second << '\t' << best_match_rating << std::endl; }
// =================================================================== // main function // =================================================================== int main(int argc, char * argv[]){ // read in movie in question via cmd line if(argc < 3){ std::cerr << "usage: " << argv[0] << " batch filename" << std::endl; std::cerr << "usage: " << argv[0] << " single customer_id movie_id" << std::endl; return -1; } // vector of pairs of strings which are the test cases std::vector<std::pair<std::string,std::string> > cases; if(argc == 4) cases.push_back(std::make_pair(argv[2],argv[3])); else{ std::ifstream inputFile(argv[2]); if(!inputFile){ std::cerr << "ERROR: cannot read input file " << argv[2] << std::endl; return -1; } std::string s1; std::string s2; while(!inputFile.eof()){ getline(inputFile, s1, '\t'); getline(inputFile, s2); if(inputFile.eof()) break; cases.push_back(std::make_pair(s1,s2)); } } std::vector<std::pair<float, float> > stats; float normal; float rating; int best_match_rating = 0; int movie_match = 0; for(unsigned int i = 0; i < cases.size(); i++){ // get the filename from the movie id std::string new_file = getFilename(cases[i].second); // open that movie file and read in numbers to a vector std::vector<int> new_customer_ids; int customer_rating = read_movie(new_customer_ids, new_file, atoi(cases[i].first.c_str())); // iterate through ever movie and compare for matches // first check for it being a movie the customer in question watched or break std::vector<int> old_customer_ids; std::vector<int> best_match; int matches = 0; for(int j = 1; j <= 17770; j++){ old_customer_ids.clear(); // make the filename std::stringstream ss; ss << j; std::string s = ss.str(); // make sure we aren't using the same movie we are predicting if ( s == cases[i].second) continue; // get the filename std::string filename = getFilename(s); // get the vector of id's and customer rating for the movie int customer_rating = read_movie(old_customer_ids, filename, atoi(cases[i].first.c_str())); // means the customer didn't watch the movie and we don't need to check it if (customer_rating == 0) continue; int tmp = compare(old_customer_ids, new_customer_ids); if(tmp > matches){ matches = tmp; movie_match = j; best_match_rating = customer_rating; best_match = old_customer_ids; } } // find average and sd of both movies and rating customer gave stats = readMeans(atoi(cases[0].second.c_str()), movie_match); // standardize and translate over to new movie normal = (float(best_match_rating) - stats[1].first)/stats[1].second; rating = normal*stats[0].second + stats[0].first; std::cout << cases[i].second << ',' << stats[0].first << ',' << stats[0].second << ',' << rating << ',' << movie_match << ',' << stats[1].first << ',' << stats[1].second << ',' << best_match_rating << ',' << customer_rating << ',' << cases[i].first << std::endl; } if(argc == 4){ // helpful print statments std::cout.precision(3); std::cout << "\t\tMovies\tMean\tStd Dev\tRating\n" << "New:\t\t"<< argv[3] << '\t' << stats[0].first << '\t' << stats[0].second << '\t' << rating << "\nBest Match:\t" << movie_match << '\t' << stats[1].first << '\t' << stats[1].second << '\t' << best_match_rating << std::endl; } }