Created
July 13, 2017 23:12
-
-
Save SergProduction/877cb9803e13fb51a1481d10e4bed736 to your computer and use it in GitHub Desktop.
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
/* | |
нужно расчитать график касиров | |
каждый касир должен работать не больше 5 дней в неделю И не больше 9 часов в день | |
рабочий день начинаеться с 8 до 23 - 15 раб часов | |
* --------------------- | |
const kAll = 70 // кол-во касиров всего | |
let k = 0 // кол-во касиров в день (нужно найти эту переменную) | |
let p = 0 // поток покупателей | |
let t = 0 // время (от 8 до 23) | |
let wd = 0 // день недели (1-7) | |
22 / 31 // 22 дня из 31 дня касир работает | |
wdOneProcent = 7 / 100 | |
procentWorkDayInWd = 5 / wdOneProcent | |
peopleOneProcent = 70 / 100 | |
qPeopleInDay = peopleOneProcent * procentWorkDayInWd // 50 из 70 работают | |
*/ | |
function randomIntegerFromTo(min, max) { | |
var rand = Math.random()*(max-min+1)+min | |
rand = Math.floor(rand) | |
return rand | |
} | |
function guid() { | |
function s4() { | |
return Math.floor((1 + Math.random()) * 0x10000) | |
.toString(16) | |
.substring(1); | |
} | |
return s4() + s4() | |
} | |
var weekDayName = [ | |
'пн', | |
'вт', | |
'ср', | |
'чт', | |
'пт', | |
'сб', | |
'вс', | |
] | |
function getdaysInMonth(){ | |
var currentDate = new Date() | |
currentDate.setDate(32) | |
return 32 - currentDate.getDate() | |
} | |
// ^^^^^^^^^^^^ tools ^^^^^^^^^^^^^^^ | |
// return [ {name:'randomString', busy: null}, ... ] | |
function createBaseArrayPeople(quantity){ | |
var people = [] | |
for (let i=0; i<quantity; i++){ | |
var name = guid() | |
people.push({name, workingDays: []}) | |
} | |
return people | |
} | |
function offTimeManyPeople(allPeople, workingDaysInWeek = 5) { | |
var peopls = createBaseArrayPeople(allPeople) | |
var busyPeoplsInDay = Math.floor( (allPeople / 100) * ( 5 / (7 / 100) ) ) | |
var daysInMonth = getdaysInMonth() | |
var workingDaysInMonth = Math.floor(daysInMonth / 7 * workingDaysInWeek) | |
var commonBusyDay = new Array(daysInMonth) | |
// var stack = 0 // debug | |
function randomDay(from, to, isWorkingDays){ | |
var day = randomIntegerFromTo(from, to) | |
var busy = isWorkingDays.includes(day) | |
if (commonBusyDay[day] >= busyPeoplsInDay +1 || busy) { | |
// stack += 1 // debug | |
// if (stack >= busyPeoplsInDay) return false // debug | |
return randomDay(from, to, isWorkingDays) | |
} | |
// stack = 0 // debug | |
return day | |
} | |
for(let d=0; d < workingDaysInMonth; d++ ) { | |
for(let i=0; i < allPeople; i++ ) { | |
var day = randomDay(1, daysInMonth, peopls[i].workingDays) | |
// if( day === false ) { // debug | |
// console.log(`daysInMonth ${d} is ${daysInMonth}`) // debug | |
// console.log(`allPeople ${i} is ${allPeople}`) // debug | |
// console.log('busyDay', busyDay) // debug | |
// console.log('peopls', peopls) // debug | |
// return peopls // debug | |
// } | |
commonBusyDay[day] = commonBusyDay[day] | |
? commonBusyDay[day] +1 | |
: 1 | |
peopls[i].workingDays.push(day) | |
} | |
} | |
console.log(commonBusyDay) | |
return {peopls, commonBusyDay} | |
} | |
var outputWorkingGraphic = offTimeManyPeople(70) | |
// console.log(a) | |
// ^^^^^^^^^^^^^^^^^^^^^^ complete ^^^^^^^^^^^^^^^^^^^^^^ | |
function test(data) { | |
/* | |
отклонение от идеала. так как люди это целый числа, | |
то невожно все поделить по равно, | |
данное число может варьиироваться от 0 до измеряющего числа меяца (30,31) это общие число | |
*/ | |
var vvv = data.slice() | |
var faill = 0 | |
var max = vvv.sort((a,b) => b - a)[0] | |
vvv.forEach(el => { | |
if( el !== max && typeof el === 'number') faill += max - el | |
}) | |
return faill | |
} | |
var faill = test(outputWorkingGraphic.commonBusyDay) | |
function searchPeoplsOfDay(arr, day){ | |
return arr.filter(peop => peop.workingDays.filter(d => d === day).length !== 0 ) | |
} | |
function sortDaysOfPeopls(arr){ | |
return arr.map( peop => { | |
peop.workingDays.sort((a,b) => a - b) | |
return peop | |
}) | |
} | |
// ^^^^^^^^^^^^^^^^^^^^^^ tests ^^^^^^^^^^^^^^^^^^^^^^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment