Skip to content

Commit

Permalink
Add total of changed collection dates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmacwhite committed Jul 1, 2024
1 parent 9d035e3 commit 07b9d45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getBinType(key) {
}

function formatAlternativeName(name) {
return name.replace('Day', '').replace('(Changed Collection)', '').replace('Garden Waste Collection', 'Garden Bin').trim();
return name.replace(/Day|\(Changed Collection\)/gi, '').replace('Garden Waste Collection', 'Garden Bin').trim();
}

function getWeekdayFromDate(date) {
Expand Down Expand Up @@ -83,6 +83,7 @@ calendars.forEach(function(filepath) {
"lastGenerated": new Date().toJSON(),
"lastModified": fileProperties.modifyTime,
"totalCollections": 0,
"totalChangedCollections": 0,
"collectionDates": []
};

Expand Down Expand Up @@ -110,6 +111,10 @@ calendars.forEach(function(filepath) {
.sort((a,b) => new Date(a.collectionDate) - new Date(b.collectionDate));

jsonData['totalCollections'] = allEvents.length;
jsonData['totalChangedCollections'] = allEvents.filter(function(item){
return item.name.includes("Changed Collection");
}).length;

jsonData['collectionDates'] = allEvents;

// Write to JSON folder for public API
Expand Down
2 changes: 2 additions & 0 deletions json-endpoints.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h1 class="h2">{{ page.title }}</h1>
<li><code>lastGenerated</code> - The last time the JSON data was generated from a deployment.</li>
<li><code>lastModified</code> - The last time the calendar data was modified, this is based on the modified date of the original iCal source.</li>
<li><code>totalCollections</code> - The total items within the <code>collectionDates</code>.</li>
<li><code>totalChangedCollections</code> - The total of one-off changed collection dates that differ from the <code>collectionWeekday</code>.</li>
<li><code>collectionDates</code> - The array containing all bin collection dates, with occurrences expanded to single events.</li>
</ul>

Expand All @@ -38,6 +39,7 @@ <h1 class="h2">{{ page.title }}</h1>
"lastGenerated": "2024-06-29T18:45:14.023Z",
"lastModified": "2024-06-17T14:12:39.206Z",
"totalCollections": 53,
"totalChangedCollections": 1,
"collectionDates": [
...
]
Expand Down

0 comments on commit 07b9d45

Please sign in to comment.