@go-avro/avro-js 1.6.6-rc13 → 1.6.6-rc15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,7 +50,10 @@ export class Job {
50
50
  if (!this.tasks || this.tasks.length === 0) {
51
51
  return 0;
52
52
  }
53
- const routeJob = this.routes.find((r) => r.job_id === this.id);
53
+ // This route's stop: a job on several routes visits different tasks
54
+ // on each. Fall back to any stop if the route's isn't loaded.
55
+ const routeJob = this.routes.find((r) => r.job_id === this.id && r.route_id === route.id) ??
56
+ this.routes.find((r) => r.job_id === this.id);
54
57
  if (!routeJob) {
55
58
  return 0;
56
59
  }
@@ -58,7 +61,13 @@ export class Job {
58
61
  if (contextTasks.length === 0) {
59
62
  return 0;
60
63
  }
61
- return contextTasks.filter((t) => t.isDone?.(route)).length / contextTasks.length;
64
+ // Progress counts only what this visit should do: tasks not due until
65
+ // after the route's next visit (or inactive) are left out entirely.
66
+ const due = contextTasks.filter((t) => t.isDueOn?.(route) ?? true);
67
+ if (due.length === 0) {
68
+ return 1;
69
+ }
70
+ return due.filter((t) => t.isDone?.(route)).length / due.length;
62
71
  };
63
72
  this.isDone = (route) => {
64
73
  return this.portionDone(route) === 1;
@@ -122,6 +122,16 @@ export declare class Task {
122
122
  computeNextTaskState: (isCustomer: boolean, action: "accept" | "modify" | "reject") => TaskStatus;
123
123
  getPrepaidEventsRemaining: () => number;
124
124
  getPrepaidMonthsRemaining: () => number;
125
+ /** Local midnight starting the day of the route's current occurrence. */
126
+ private routeDayStart;
125
127
  isDone: (route: Route) => boolean;
128
+ /**
129
+ * Whether this visit of `route` should do the task: it's active and
130
+ * either done on the route's day or due before the route's next visit.
131
+ * A task repeating less often than its route (biweekly edging on a
132
+ * weekly route) is not due on its off-weeks, so a stop's progress
133
+ * leaves it out instead of showing the stop as partly done.
134
+ */
135
+ isDueOn: (route: Route) => boolean;
126
136
  }
127
137
  export {};
@@ -173,6 +173,12 @@ export class Task {
173
173
  return acc;
174
174
  }, 0);
175
175
  };
176
+ /** Local midnight starting the day of the route's current occurrence. */
177
+ this.routeDayStart = (route) => {
178
+ const day = new Date((route.start_time ?? 0) * 1000);
179
+ day.setHours(0, 0, 0, 0);
180
+ return day;
181
+ };
176
182
  this.isDone = (route) => {
177
183
  if (!this.status || this.status !== TaskStatus.ACTIVE) {
178
184
  return true;
@@ -182,11 +188,32 @@ export class Task {
182
188
  // an early-started visit that finishes a few minutes before
183
189
  // route.start_time) while still rejecting stale events from previous
184
190
  // occurrences. Applies to both recurring and one-shot tasks.
185
- const routeDay = new Date((route.start_time ?? 0) * 1000);
186
- routeDay.setHours(0, 0, 0, 0);
187
- const cutoff = Math.floor(routeDay.getTime() / 1000);
191
+ const cutoff = Math.floor(this.routeDayStart(route).getTime() / 1000);
188
192
  return (this.last_completed_event?.time_ended ?? 0) >= cutoff;
189
193
  };
194
+ /**
195
+ * Whether this visit of `route` should do the task: it's active and
196
+ * either done on the route's day or due before the route's next visit.
197
+ * A task repeating less often than its route (biweekly edging on a
198
+ * weekly route) is not due on its off-weeks, so a stop's progress
199
+ * leaves it out instead of showing the stop as partly done.
200
+ */
201
+ this.isDueOn = (route) => {
202
+ if (this.status !== TaskStatus.ACTIVE)
203
+ return false;
204
+ if (this.isDone(route))
205
+ return true;
206
+ const nextDue = this.getNextDue();
207
+ if (nextDue == null)
208
+ return true;
209
+ const routeDayEnd = this.routeDayStart(route);
210
+ routeDayEnd.setDate(routeDayEnd.getDate() + 1);
211
+ const nextVisit = route.getNextOccurrence(routeDayEnd);
212
+ // One-off routes have no next visit: then only the route's day counts.
213
+ const horizon = nextVisit ? new Date(nextVisit) : routeDayEnd;
214
+ horizon.setHours(0, 0, 0, 0);
215
+ return nextDue < Math.floor(horizon.getTime() / 1000);
216
+ };
190
217
  assignData(this, init);
191
218
  // Payloads from the server carry no timestamp: they were computed
192
219
  // just now. Copies keep the one they were made with.
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "1.6.6-rc13";
1
+ export declare const AVRO_JS_VERSION = "1.6.6-rc15";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '1.6.6-rc13';
3
+ export const AVRO_JS_VERSION = '1.6.6-rc15';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "1.6.6-rc13",
3
+ "version": "1.6.6-rc15",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",