Created
March 23, 2017 22:47
-
-
Save dreamorosi/2a14f5c3f605e705aa6b8b8456355c92 to your computer and use it in GitHub Desktop.
Balance By CM - IDEA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var projects_current_status = [ | |
{project: 'xxx', count: 1}, | |
{project: 'yyy', count: 1}, | |
{project: 'zzz', count: 1}, | |
{project: 'aaa', count: 1} | |
] | |
var users_to_assign = 10 | |
var cm_projects_users = [ | |
{cm: 'A', usr_no_proj: 3, projs: [ | |
{project: 'zzz', count: 0}, | |
{project: 'xxx', count: 1}, | |
{project: 'yyy', count: 1}, | |
{project: 'aaa', count: 3} | |
]}, | |
{cm: 'B', usr_no_proj: 7, projs: [ | |
{project: 'xxx', count: 0}, | |
{project: 'yyy', count: 1}, | |
{project: 'zzz', count: 2}, | |
{project: 'aaa', count: 2} | |
]}, | |
{cm: 'C', usr_no_proj: 2, projs: [ | |
{project: 'aaa', count: 0}, | |
{project: 'xxx', count: 0}, | |
{project: 'yyy', count: 1}, | |
{project: 'zzz', count: 2} | |
]}, | |
{cm: 'D', usr_no_proj: 3, projs: [ | |
{project: 'xxx', count: 0}, | |
{project: 'yyy', count: 0}, | |
{project: 'zzz', count: 1}, | |
{project: 'aaa', count: 2} | |
]}, | |
{cm: 'E', usr_no_proj: 5, projs: [ | |
{project: 'xxx', count: 0}, | |
{project: 'yyy', count: 0}, | |
{project: 'zzz', count: 0}, | |
{project: 'aaa', count: 3} | |
]} | |
] | |
function create_asc_list_for_this_proj (proj) { | |
var proj_list = [] | |
// create list like this for each project | |
/* var proj_list = [ | |
* {cm: 'B', project: {project: 'xxx', count: 0}}, | |
* {cm: 'C', project: {project: 'xxx', count: 0}}, | |
* {cm: 'D', project: {project: 'xxx', count: 0}}, | |
* {cm: 'E', project: {project: 'xxx', count: 0}}, | |
* {cm: 'A', project: {project: 'xxx', count: 1}} | |
* ] | |
*/ | |
} | |
function get_this_project_in_cm (proj, cm_projects) { | |
cm_projects.filter(function (project) { | |
if (project.project === proj) { | |
return project | |
} | |
}) | |
return { | |
project: project, | |
available: usr_no_proj | |
} | |
} | |
var balanced_projects = function_that_we_have_now(projects_current_status) | |
/* Produces | |
* balanced_projects = [ | |
* {project: 'xxx', toAssign: 5}, | |
* {project: 'yyy', toAssign: 3}, | |
* {project: 'zzz', toAssign: 2} | |
* ] | |
*/ | |
var balanced_by_cm = balance_by_cm(balanced_projects) | |
function balance_by_cm (balanced_projects) { | |
balanced_projects.forEach(function (project) { | |
var this_proj_status = create_asc_list_for_this_proj(project.project) | |
var proposed_list = [] | |
while (project.toAssign > 0) { | |
// Run a function like the one we have now for global that will produce something like that (based on this example) | |
// and taking in account users' availability for each CM | |
/* proposed_list = [ | |
* {cm: 'A', project: 'xxx', toAssign: 1}, | |
* {cm: 'B', project: 'xxx', toAssign: 1}, | |
* {cm: 'C', project: 'xxx', toAssign: 1}, | |
* {cm: 'D', project: 'xxx', toAssign: 1}, | |
* {cm: 'E', project: 'xxx', toAssign: 1} | |
* ] // tot 5 (see balanced_projects) | |
*/ | |
} | |
}) | |
} | |
// In the end balanced_by_cm will be like this to be passed to server and process. | |
/* | |
* balanced_by_cm = [ | |
* {project: 'xxx', [ | |
* {cm: 'A', project: 'xxx', toAssign: 1}, | |
* {cm: 'B', project: 'xxx', toAssign: 1}, | |
* {cm: 'C', project: 'xxx', toAssign: 1}, | |
* {cm: 'D', project: 'xxx', toAssign: 1}, | |
* {cm: 'E', project: 'xxx', toAssign: 1} | |
* ]}, | |
* {project: 'yyy', [ | |
* {cm: 'C', project: 'yyy', toAssign: 1}, | |
* {cm: 'D', project: 'yyy', toAssign: 1}, | |
* {cm: 'E', project: 'yyy', toAssign: 1} | |
* ]}, | |
* {project: 'zzz', [ | |
* {cm: 'E', project: 'zzz', toAssign: 1} | |
* ]} | |
* ] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment