<commit_before>var WEEKDAYS = ['일', '월', '화', '수', '목', '금', '토'];
var SHIFTS = ['day', 'night', 'prn'];
var POSITION_COUNT = 4;
var PERSON_COUNT = 15;

$(function() {
  function moveToPage(pageName) {
    $('.page').hide();
    $('#' + pageName).show();
  }
  
  function getAllPositionNames() {
    var allPositions = [];
    for (var i = 1; i <= POSITION_COUNT; i++) {
      var positionName = $('#position' + i).val().trim();
      if (positionName) {
        allPositions.push(positionName);
      }
    }
    return allPositions;
  }
  
  function getAllPersonNames() {
    var allNames = [];
    for (var i = 1; i <= PERSON_COUNT; i++) {
      var name = $('#name' + i).val().trim();
      if (name) {
        var hour = parseInt($('#hour' + i).val());
        allNames.push(name);
      }
    }
    return allNames;
  }
  
  function getAllHours() {
    var allHours = [];
    for (var i = 1; i <= PERSON_COUNT; i++) {
      var name = $('#name' + i).val().trim();
      if (name) {
        var hour = parseInt($('#hour' + i).val());
        allHours.push(hour);
      }
    }
    return allHours;
  }
  
  function getTotalDays() {
    var scheduleYear = parseInt($('#schedule-year').val());
    var scheduleMonth = parseInt($('#schedule-month').val());
    // total number of days in the selected month
    var totalDays = new Date(scheduleYear, scheduleMonth, 0).getDate();
    return totalDays;
  }
  
  function getAllDateStrings() {
    var dateStrings = [];
    var scheduleYear = parseInt($('#schedule-year').val());
    var scheduleMonth = parseInt($('#schedule-month').val());
    // total number of days in the selected month
    var totalDays = new Date(scheduleYear, scheduleMonth, 0).getDate();
    for (var i = 1; i <= totalDays; i++) {
      var weekday = new Date(scheduleYear, scheduleMonth-1, i).getDay();
      var weekdayKor = WEEKDAYS[weekday];
      var dateString = '' + scheduleMonth + '월 ' + i + '일 (' + weekdayKor + ')';
      dateStrings.push(dateString);
    }
    return dateStrings;
  }
  
  function renderPage1() {
    var currentDate = new Date();
    var currentYear = currentDate.getFullYear();
    var currentMonth = currentDate.getMonth() + 1;
    $('#schedule-year').val(currentYear);
    $('#schedule-month').val(currentMonth);
  }
  
  function renderNamePositionTable(allPositions, allPersonNames) {
    // render name-position table header
    var inHtml = '<tr><th>이름</th>';
    for (var i = 0; i < allPositions.length; i++) {
      var positionName = allPositions[i];
      inHtml += '<th>' + positionName + '</th>';
    }
    inHtml + '</tr>';
    
    // render name-position table content
    for (var i = 0; i < allPersonNames.length; i++) {
      var personName = allPersonNames[i];
      inHtml += '<tr><td>' + personName + '</td>';
      for (var j = 0; j < allPositions.length; j++) {
        inHtml += '<td><input id="name' + i + '-position' + j 
            + '" type="checkbox" checked></td>';
      }2
      inHtml += '</tr>';
    }
    
    var namePositionTable = $('#name-positions-table');
    namePositionTable.empty();
    namePositionTable.html(inHtml);
  }
  
  function renderNameVacationTable(allPersonNames, allDateStrings) {
    // render name-vacation table header
    var inHtml = '<tr><th>날짜/시간</th>';
    for (var i = 0; i < allPersonNames.length; i++) {
      var personName = allPersonNames[i];
      inHtml += '<th>' + personName + '</th>';
    }
    inHtml + '</tr>';
    
    // render name-vacation table content
    for (var i = 0; i < allDateStrings.length; i++) {
      var dateString = allDateStrings[i];
      for (var j = 0; j < SHIFTS.length; j++) {
        inHtml += '<tr><td>' + dateString + ' ' + SHIFTS[j] + '</td>';
        for (var k = 0; k < allPersonNames.length; k++) {
          inHtml += '<td><input id="name-vacation-' + k + '-' + i + '-' + j
              + '" type="checkbox"></td>';
        }
        inHtml += '</tr>';
      }
    }
    
    var nameVacationTable = $('#name-vacations-table');
    nameVacationTable.empty();
    nameVacationTable.html(inHtml);
  }
  
  function renderNameMustWorkTable(allPersonNames, allDateStrings) {
    // render name-must-work table header
    var inHtml = '<tr><th>날짜/시간</th>';
    for (var i = 0; i < allPersonNames.length; i++) {
      var personName = allPersonNames[i];
      inHtml += '<th>' + personName + '</th>';
    }
    inHtml + '</tr>';
    
    // render name-must-work table content
    for (var i = 0; i < allDateStrings.length; i++) {
      var dateString = allDateStrings[i];
      for (var j = 0; j < SHIFTS.length; j++) {
        inHtml += '<tr><td>' + dateString + ' ' + SHIFTS[j] + '</td>';
        for (var k = 0; k < allPersonNames.length; k++) {
          inHtml += '<td><input id="name-must-work-' + k + '-' + i + '-' + j
              + '" type="checkbox"></td>';
        }
        inHtml += '</tr>';
      }
    }
    
    var nameMustWorkTable = $('#name-must-works-table');
    nameMustWorkTable.empty();
    nameMustWorkTable.html(inHtml);
  }
  
  function renderPage2() {
    var allPositions = getAllPositionNames();
    var allPersonNames = getAllPersonNames();
    var allDateStrings = getAllDateStrings();
    
    renderNamePositionTable(allPositions, allPersonNames);
    renderNameVacationTable(allPersonNames, allDateStrings);
    renderNameMustWorkTable(allPersonNames, allDateStrings);
  }
  
  function addToResultPanel(message) {
    var millisecondsToWait = 1000;
    setTimeout(function() {
      var inHtml = '<p>' + message + '</p>';
      $('#process-area').append(inHtml);
    }, millisecondsToWait);
    
  }
  
  function generateMathProgString() {
    // generate MathProg string
    return 'Maximize\nobj: + 786433 x1 + 655361 x2 + 589825 x3 + 557057 x4\n+ 540673 x5 + 532481 x6 + 528385 x7 + 526337 x8 + 525313 x9\n+ 524801 x10 + 524545 x11 + 524417 x12 + 524353 x13\n+ 524321 x14 + 524305 x15\n\nSubject To\ncap: + 786433 x1 + 655361 x2 + 589825 x3 + 557057 x4\n+ 540673 x5 + 532481 x6 + 528385 x7 + 526337 x8 + 525313 x9\n+ 524801 x10 + 524545 x11 + 524417 x12 + 524353 x13\n+ 524321 x14 + 524305 x15 <= 4194303.5\n\nBounds\n0 <= x1 <= 1\n0 <= x2 <= 1\n0 <= x3 <= 1\n0 <= x4 <= 1\n0 <= x5 <= 1\n0 <= x6 <= 1\n0 <= x7 <= 1\n0 <= x8 <= 1\n0 <= x9 <= 1\n0 <= x10 <= 1\n0 <= x11 <= 1\n0 <= x12 <= 1\n0 <= x13 <= 1\n0 <= x14 <= 1\n0 <= x15 <= 1\n\nGenerals\nx1\nx2\nx3\nx4\nx5\nx6\nx7\nx8\nx9\nx10\nx11\nx12\nx13\nx14\nx15\n\nEnd\n\n';
  }<commit_msg>intermediate commit of calculate()<commit_after>var WEEKDAYS = ['일', '월', '화', '수', '목', '금', '토'];
var SHIFTS = ['day', 'night', 'prn'];
var MAX_SLOTS = [3, 3, 1]; // persons to work in day, night, prn
var POSITION_COUNT = 4;
var TOTAL_PERSON_FIELD_COUNT = 15;

$(function() {
  function moveToPage(pageName) {
    $('.page').hide();
    $('#' + pageName).show();
  }
  
  function getAllPositionNames() {
    var allPositions = [];
    for (var i = 1; i <= POSITION_COUNT; i++) {
      var positionName = $('#position' + i).val().trim();
      if (positionName) {
        allPositions.push(positionName);
      }
    }
    return allPositions;
  }
  
  function getAllPersonNames() {
    var allNames = [];
    for (var i = 1; i <= TOTAL_PERSON_FIELD_COUNT; i++) {
      var name = $('#name' + i).val().trim();
      if (name) {
        var hour = parseInt($('#hour' + i).val());
        allNames.push(name);
      }
    }
    return allNames;
  }
  
  function getAllHours() {
    var allHours = [];
    for (var i = 1; i <= TOTAL_PERSON_FIELD_COUNT; i++) {
      var name = $('#name' + i).val().trim();
      if (name) {
        var hour = parseInt($('#hour' + i).val());
        allHours.push(hour);
      }
    }
    return allHours;
  }
  
  function getTotalDays() {
    var scheduleYear = parseInt($('#schedule-year').val());
    var scheduleMonth = parseInt($('#schedule-month').val());
    // total number of days in the selected month
    var totalDays = new Date(scheduleYear, scheduleMonth, 0).getDate();
    return totalDays;
  }
  
  function getAllDateStrings() {
    var dateStrings = [];
    var scheduleYear = parseInt($('#schedule-year').val());
    var scheduleMonth = parseInt($('#schedule-month').val());
    // total number of days in the selected month
    var totalDays = new Date(scheduleYear, scheduleMonth, 0).getDate();
    for (var i = 1; i <= totalDays; i++) {
      var weekday = new Date(scheduleYear, scheduleMonth-1, i).getDay();
      var weekdayKor = WEEKDAYS[weekday];
      var dateString = '' + scheduleMonth + '월 ' + i + '일 (' + weekdayKor + ')';
      dateStrings.push(dateString);
    }
    return dateStrings;
  }
  
  function renderPage1() {
    var currentDate = new Date();
    var currentYear = currentDate.getFullYear();
    var currentMonth = currentDate.getMonth() + 1;
    $('#schedule-year').val(currentYear);
    $('#schedule-month').val(currentMonth);
  }
  
  function renderNamePositionTable(allPositions, allPersonNames) {
    // render name-position table header
    var inHtml = '<tr><th>이름</th>';
    for (var i = 0; i < allPositions.length; i++) {
      var positionName = allPositions[i];
      inHtml += '<th>' + positionName + '</th>';
    }
    inHtml + '</tr>';
    
    // render name-position table content
    for (var i = 0; i < allPersonNames.length; i++) {
      var personName = allPersonNames[i];
      inHtml += '<tr><td>' + personName + '</td>';
      for (var j = 0; j < allPositions.length; j++) {
        inHtml += '<td><input id="name' + i + '-position' + j 
            + '" type="checkbox" checked></td>';
      }2
      inHtml += '</tr>';
    }
    
    var namePositionTable = $('#name-positions-table');
    namePositionTable.empty();
    namePositionTable.html(inHtml);
  }
  
  function renderNameVacationTable(allPersonNames, allDateStrings) {
    // render name-vacation table header
    var inHtml = '<tr><th>날짜/시간</th>';
    for (var i = 0; i < allPersonNames.length; i++) {
      var personName = allPersonNames[i];
      inHtml += '<th>' + personName + '</th>';
    }
    inHtml + '</tr>';
    
    // render name-vacation table content
    for (var i = 0; i < allDateStrings.length; i++) {
      var dateString = allDateStrings[i];
      for (var j = 0; j < SHIFTS.length; j++) {
        inHtml += '<tr><td>' + dateString + ' ' + SHIFTS[j] + '</td>';
        for (var k = 0; k < allPersonNames.length; k++) {
          inHtml += '<td><input id="name-vacation-' + k + '-' + i + '-' + j
              + '" type="checkbox"></td>';
        }
        inHtml += '</tr>';
      }
    }
    
    var nameVacationTable = $('#name-vacations-table');
    nameVacationTable.empty();
    nameVacationTable.html(inHtml);
  }
  
  function renderNameMustWorkTable(allPersonNames, allDateStrings) {
    // render name-must-work table header
    var inHtml = '<tr><th>날짜/시간</th>';
    for (var i = 0; i < allPersonNames.length; i++) {
      var personName = allPersonNames[i];
      inHtml += '<th>' + personName + '</th>';
    }
    inHtml + '</tr>';
    
    // render name-must-work table content
    for (var i = 0; i < allDateStrings.length; i++) {
      var dateString = allDateStrings[i];
      for (var j = 0; j < SHIFTS.length; j++) {
        inHtml += '<tr><td>' + dateString + ' ' + SHIFTS[j] + '</td>';
        for (var k = 0; k < allPersonNames.length; k++) {
          inHtml += '<td><input id="name-must-work-' + k + '-' + i + '-' + j
              + '" type="checkbox"></td>';
        }
        inHtml += '</tr>';
      }
    }
    
    var nameMustWorkTable = $('#name-must-works-table');
    nameMustWorkTable.empty();
    nameMustWorkTable.html(inHtml);
  }
  
  function renderPage2() {
    var allPositions = getAllPositionNames();
    var allPersonNames = getAllPersonNames();
    var allDateStrings = getAllDateStrings();
    
    renderNamePositionTable(allPositions, allPersonNames);
    renderNameVacationTable(allPersonNames, allDateStrings);
    renderNameMustWorkTable(allPersonNames, allDateStrings);
  }
  
  function addToResultPanel(message) {
    var millisecondsToWait = 1000;
    setTimeout(function() {
      var inHtml = '<p>' + message + '</p>';
      $('#process-area').append(inHtml);
    }, millisecondsToWait);
    
  }
  
  function getVariables() {
    // x_a_b_c:
  }
  
  function println(str, line) {
    str += line + '\n';
  }
  
  function formatVar(a, b, c, d) {
    return '+ 1 x_' + a + '_' + b + '_' + c + '_' + d + ' ';
  }
  
  function generateMathProgString() {
    var allHours = getAllHours();
    var personCount = getAllPersonNames().length;
    var positionCount = getAllPositionNames().length;
    var dayCount = getTotalDays();
    
    var str = '';
    
    // generate objective string
    println(str, 'Maximize');
    var line = 'obj: ';
    for (var a = 0; a < personCount; a++) {
      for (var b = 0; b < dayCount; b++) {
        var c = 2;
        for (var d = 0; d < MAX_SLOTS[c]; d++) {
          line += formatVar(a, b, c, d);
        }
      }
    }
    println(str, line);
    
    // generate subject to string
    println(str, 'Subject To');
    
    // 1. per-person total work
    for (var a = 0; a < personCount; a++) {
      var line = 'total_' + a + '_max: ';
      for (var b = 0; b < dayCount; b++) {
        for (var c = 0; c < SHIFTS.length; c++) {
          for (var d = 0; d < MAX_SLOTS[c]; d++) {
            line += formatVar(a, b, c, d);
          }
        }
      }
      line += ' <= ' + allHours[a];
      println(str, line);
    }
    
    // 2. cannot work more than once in the same day
    for (var a = 0; a < personCount; a++) {
      for (var b = 0; b < dayCount; b++) {
        var line = 'nextday_' + a + '_' + b + ': ';
        for (var c = 0; c <= SHIFTS.length; c++) {
          for (var d = 0; d < MAX_SLOTS[c]; d++) {
            line += formatVar(a, b, c, d);
          }
        }
        line += '<= 1';
        println(line);
      }
    }
    
    // 3. cannot work more than once night-prn-day
    for (var a = 0; a < personCount; a++) {
      for (var b = 0; b < )
    }
    
      
      
      
      
      
    return str;
  }
{'fraction_non_alphanumeric': 0.17452428287418348, 'fraction_numerical': 0.027122976427151377, 'mean_word_length': 2.4479804161566707, 'pattern_counts': {'":': 0, '<': 161, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2579188', 'n_tokens_mistral': 5057, 'n_tokens_neox': 4819, 'n_words': 1167}