Jump to content

Recommended Posts

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 other
M - main client
Wx - Worker
Cx - 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 proportional

And 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.

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.

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.

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;
}

  • 4 weeks later...

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.

 

 

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.