//creates a collage of all the customers who registered the coffee shop void FaceDetection::CreateCollage(const Customers& customers) { cv::Mat finalImage; cv::Mat temp; cv::Size *min= FindSmallest(customers);//we creates the collage with the measure, of the smallest image height for (int i= 0; i < customers.GetSize(); i++){ Customer *curCust= customers.GetCustomerAt(i); std::string custName= curCust->getName(); std::string imagePath= "faces/" + custName + "/" + custName + ".tiff"; cv::Mat curImage= cv::imread(imagePath); if (0 == i){//the first image added to the collage finalImage= curImage; cv::resize(finalImage, finalImage, *min); } else {//one or more images are already in the collage cv::resize(curImage, curImage, *min); temp= cv::Mat((*min).height, ((*min).width)*(i+1), CV_8UC3);//creates a blank image with the size of the current collage and the added image MergeImage(finalImage, temp, 0);//insert the current collage to the blank image, starting at the leftmostmost area MergeImage(curImage, temp, (temp.size().width-curImage.size().width));//added the image to the collage finalImage= temp; } } cv::imwrite( "collage.tiff", finalImage); delete min; }
Maybe < Customer const > getCustomer(Customers const &customers, std::string const &id) { auto customer = customers.find(id); if (customer == customers.end()) return nothing(); else return just(customer->second); };
/*given an image name of customer(s), the customers vector and the current profit, return the added revenue by the costumer(s), and updates the profit*/ double Simulation::BuyItem(Customers& custs, const std::string& custImg, double& profit){ double currentProfit= 0; double currentRevenue= 0; FaceDetection FD; std::vector<int> *custsFound= FD.Detect(custImg, custs);//gets a vector of the customers place, in the costumers vector int size= custsFound->size(); for (int i= 0; i < size; i++){ Customer *curCust= custs.GetCustomerAt((*custsFound)[i]); std::string favProduct= curCust->getFavProduct(); double priceFavPro= buyFavProduct(favProduct); if (0 == priceFavPro){ std::string message= "Costumer " + curCust->getName() + " failed to purchase " + favProduct; _logger->Log(message.c_str(), Poco::Message::PRIO_NOTICE); } else{ if (curCust->isVip()){ currentProfit= currentProfit+ 2.0/15 * priceFavPro; //(1/3 * priceFavPro) - (0.2 * priceFavPro); } else currentProfit= currentProfit + 1.0/3 * priceFavPro; currentRevenue= currentRevenue + curCust->computeProductPrice(priceFavPro); std::string message= "Costumer " + curCust->getName() + " purchased " + favProduct; _logger->Log(message.c_str(), Poco::Message::PRIO_NOTICE); } } profit= profit + currentProfit; delete custsFound; return currentRevenue; }
void Persist::saveCustomers(Customers& customers) { Customers::iterator iterator; const char* fileName = Customer::FILE_NAME.c_str(); std::ofstream file(fileName, std::ios::out); if (!file) { std::cerr << "Error while opening " << fileName << std::endl; exit(EXIT_FAILURE); } for (iterator = customers.begin(); iterator != customers.end(); ++iterator) { Customer customer = (*iterator).second; file.write(reinterpret_cast<const char*>(&customer), sizeof(Customer)); } file.close(); }
TEST(Bridge, Test1_CallConstract) { Customers *customers = new Customers("Chicago"); customers->Data(new CustomerData()); customers->Show(); customers->Next(); customers->Show(); customers->Next(); customers->Show(); customers->Add("Henry Valasquez"); customers->ShowAll(); delete customers->Data(); delete customers; EXPECT_EQ(1,1); }