adrozdz Posted May 25, 2015 Share Posted May 25, 2015 Hey everyone,I have a question, and I don't know if it's even possible to achieve.I have clients and workers, each worker has a "main client" who is the most important client for this worker.Also each worker can have other clients assignet to him and one client can be assigned to many workers.The schemma looks more or less like this:A - assiged to each otherM - main clientWx - WorkerCx - Client | C1 | C2 | C3 | C4 | C5 | w1 | M | | A | A | A | w2 | A | M | | A | | w3 | | | A | A | M | w4 | A | A | | A | M | w5 | A | | M | A | | w6 | | A | M | | | w7 | A | M | | A | | Now, I want assign a survey for workers who would answer some questions about clients. But there are some rules- Each worker has to evaluate his "main client"- Each worker has to evaluate one client assigned to him excluding "main client"- Clinets has to be evaluated somehow proportionalAnd with that third rule I have a problem. Without it I would create an array with main client and the other would be a result of the following code: $clientsToEvaluate = []; $clientsToEvaluate[] = $mainClient; //finding is easy /*gather other clients' ids and shuffle it*/ shuffle($otherClients); $clientsToEvaluate[] = array_slice($otherClients,0,1); But I don't know how to implement the third rule (to make it proportional).Do you happen to know how to solve it. I'd be very grateful foe each suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/ Share on other sites More sharing options...
Barand Posted May 25, 2015 Share Posted May 25, 2015 What attribute of an evaluation has to be proportional? To what should it be proportional? Perhaps the number of words in each evaluation should be proportional to the client's weight? Give us a clue. Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/#findComment-1512593 Share on other sites More sharing options...
adrozdz Posted May 25, 2015 Author Share Posted May 25, 2015 Sorry my bad. General number of randomly choosen clients should be more or less the same for each clients. What I mean is that there should be equal number of surveys for each client. Sorry for my English. Maybe other words: There shouldn't be a sitiation where one client is evaluated f.e 10 times and another one only once. Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/#findComment-1512594 Share on other sites More sharing options...
CroNiX Posted May 25, 2015 Share Posted May 25, 2015 Why not store the date that the person was last evaluated? Then when you query to get new person to evaluate, exclude those within a date range so you only get someone who hasn't been evaluated for that time period yet. Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/#findComment-1512606 Share on other sites More sharing options...
Barand Posted May 25, 2015 Share Posted May 25, 2015 From your data +--------+--------+------+ | worker | client | main | +--------+--------+------+ | w1 | c1 | 1 | | w1 | c3 | 0 | | w1 | c4 | 0 | | w1 | c5 | 0 | | w2 | c1 | 0 | | w2 | c2 | 1 | | w2 | c4 | 0 | | w3 | c3 | 0 | | w3 | c4 | 0 | | w3 | c5 | 1 | | w4 | c1 | 0 | | w4 | c2 | 0 | | w4 | c4 | 0 | | w4 | c5 | 1 | | w5 | c1 | 0 | | w5 | c3 | 1 | | w5 | c4 | 0 | | w6 | c2 | 0 | | w6 | c3 | 1 | | w7 | c1 | 0 | | w7 | c2 | 1 | | w7 | c4 | 0 | +--------+--------+------+ I got this assessment schedule (which is as even as I can get it) c1 c2 c3 c4 c5 w1 M A w2 A M w3 A M w4 A M w5 M A w6 A M w7 A M The code $sql = "SELECT worker , client , main FROM worker_client"; $worker = []; // worker assessments $client = []; // client assessed by $res = $db->query($sql); while (list($w,$c,$m) = $res->fetch_row()) { $client[$c][$w] = 0; if ($m) { // allocate assessments of main clients first $worker[$w][] = $c; $client[$c][$w] = 1; } } // while still workers with < 2 assessments while (array_filter($worker, 'assess1')) { // sort to get clients with least assessments first uasort($client, function($a,$b){ return array_sum($a) - array_sum($b);}); foreach ($client as $c => $warr) { asort($warr); foreach ($warr as $w => $k) { if ($k==0) { // if worker has < 2 assessments, add client to their list if (count($worker[$w])<2) { $worker[$w][] = $c; $client[$c][$w]++; break; } } } } } echo '<pre>',print_r($worker, true),'</pre>'; // assessment schedule function assess1($var) // array filter function { return count($var) < 2; } Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/#findComment-1512614 Share on other sites More sharing options...
adrozdz Posted June 17, 2015 Author Share Posted June 17, 2015 Thx Barand for the answer but unfortunalety the situation has changed and another solution is expected. Forget the main client i have only workers connected with clients, there will only be "regular" clients . And my clients wants to choose how many clients workers must assess. Of course clients have to be assessed more or less proporionally. But I'm sure there will be a situation where workers don't have assigned clients or have less assigned clients than chosen quantity. I don't know if any of this makes sense This project is written in Yii2 Frameword if it gives any help. Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/#findComment-1514166 Share on other sites More sharing options...
Barand Posted June 17, 2015 Share Posted June 17, 2015 Send me a PM and we can agree a price. Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/#findComment-1514175 Share on other sites More sharing options...
Muddy_Funster Posted June 17, 2015 Share Posted June 17, 2015 And my clients... I just have to say, if you have a client then you are getting paid for this. If you are getting paid for this then you have pitched yourself as someone who can do this job. You have had code for free for something you are going to profit from (and have since asked for more) that get's you pretty close to where you need to be, if you can't take that and adapt it to what you need then you really shouldn't be taking on these clients, or asking people here to do your job for you for nothing. What's with people these days? Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/#findComment-1514176 Share on other sites More sharing options...
adrozdz Posted June 17, 2015 Author Share Posted June 17, 2015 First of all I didn't ask for any code, but guidelines how to achieve some goal beacuse I didn't have any cule then how to work it out. Second of all next time I visit this forum I won't forget go take ma wallet with me. Quote Link to comment https://forums.phpfreaks.com/topic/296477-randomly-choose-from-group-but-proportional/#findComment-1514179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.