Skip to content

Commit

Permalink
Update generate_delivery_calendar.js
Browse files Browse the repository at this point in the history
Delivery calendars are now broken down by both route and segment. Route determines which day of the week; segment determines which week deliveries begin. This is intended to break down deliveries into more manageable chunks that can be fulfilled by a single driver.
  • Loading branch information
cnative100 authored Feb 21, 2023
1 parent 2f60577 commit f9126da
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions generate_delivery_calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ let subscriptionsView = subscriptionsTable.getView("Grid view");
let deliveryCalendarTable = base.getTable("Delivery Calendar");
let deliveryCalendarView = deliveryCalendarTable.getView("Grid view");

let subscriberResults = await subscribersView.selectRecordsAsync({fields: ['Name', 'Route']});
let subscriberResults = await subscribersView.selectRecordsAsync({fields: ['Name', 'Route', 'Segment']});
let subscriptionsResults = await subscriptionsView.selectRecordsAsync({fields: ['Subscribers','Frequency (in weeks)']});
let deliveryCalendarResults = await deliveryCalendarView.selectRecordsAsync({fields: ['Delivery Weekend','Subscriptions']});

let deliveryStartDate = new Date("April 8, 2023");
let deliveryStartDate = new Date("April 11, 2023");

// Updates can only be in batches of 50
let updates = new Array();
Expand All @@ -26,6 +26,7 @@ for(let subscriberRecord of subscriberResults.records){
let deliverySlots = new Set();
let subscriberName = subscriberRecord.getCellValue('Name');
let route = subscriberRecord.getCellValueAsString('Route');
let segment = subscriberRecord.getCellValueAsString('Segment');

for(let shareRecord of subscriptionsResults.records){

Expand All @@ -34,8 +35,11 @@ for(let subscriberRecord of subscriberResults.records){
let freqency = parseInt(shareRecord.getCellValueAsString("Frequency (in weeks)"));
let freqIterator = 1;
let deliveryIterator = new Date(deliveryStartDate);
if(route == "North"){
deliveryIterator.setDate(deliveryIterator.getDate() + 1);
let routeIncrement = (route == "CVL" ? 0 : (route == "RVA" ? 1 : (route == "NOVA" ? 2 : (route == "DC") ? 3 : 0)));

deliveryIterator.setDate(deliveryIterator.getDate() + routeIncrement);
if(segment == "EAST"){
deliveryIterator.setDate(deliveryIterator.getDate() + 7);
}

let newDeliveries = new Array();
Expand Down Expand Up @@ -66,10 +70,6 @@ for(let subscriberRecord of subscriberResults.records){

newDeliveries.push({id: deliveryDate.id, fields: {"Subscriptions": newSubsArr}});
interiorBatchSize++;
output.text(interiorBatchSize);
//await deliveryCalendarTable.updateRecordAsync(deliveryDate.id, {
// "Subscriptions" : newSubsArr,
// });

if(interiorBatchSize == 50){
await deliveryCalendarTable.updateRecordsAsync(newDeliveries);
Expand Down

0 comments on commit f9126da

Please sign in to comment.