Repositories and contributors

Repository

app-status-reports

Turns Presence events into daily salesperson availability timelines for Manager Portal.

Browse the repository archive

Archive location. Dodol/app-status-reports. Purpose based on README.md at b4d7ca7.

Why compact the report

The v2 report ran on MySQL in Amazon RDS, where the team had substantial database load to manage. We moved the report to DynamoDB and compacted the status data to ease that pressure. The team accepted a less precise timeline and kept refining how the visualization handled edge cases. They also wanted a flat notation that could be reconstructed independently of the frontend.

The archived v3 code shows how the compact format worked. A salesperson who stayed available for 60 minutes could be represented by one run, 60:2, and the service could derive its minute counters from the runs. An early fix guarded against filling a zero-minute routing window with the last known status. app/lib/common.js at 78686670d0a3 app/getAppStatusReport.js at fd1cbbf

Salesperson app status

In Manager Portal, this report was under Reports → Salesperson app status. A manager could see when each salesperson’s app was available, away, or disconnected across a day. src/app/manager-portal/pages/reports/salesperson-app-status/salesperson-bar/salesperson-bar.component.ts in Portals/manager-portal at f1324139a

Monday, 26 July 2021Illustrative reconstruction · synthetic activity

Kuala Lumpur time · Read at 15:30 · Routing hours 09:00–18:00

Swipe across the chart to see the full day.

Salesperson A

Salesperson B

Salesperson C

  • Available
  • Available · engaged
  • Away
  • Away · engaged
  • Connecting or disconnected
  • Throttled
  • Logged off
  • Off routing hours
  • No data

From DynamoDB to the chart

The writer stores one item per salesperson per tenant-local day, keyed by composite_id and local_date. The s_data field holds the run lengths. In 20:4, 20 is the number of minutes and 4 is the status code. The item also holds duration totals and the latest status. models/AppStatus.js at b4d7ca7 app/updater.js at b4d7ca7

The report can extend a status to the requested minute before drawing it. Salesperson B’s last event was at 15:15, so the stored item has 0:2 followed by 165:x. The 15:30 read turns those into 15:2 and 150:x in the report response. The stored item keeps its original values. app/getAppStatusReport.js at b4d7ca7

Salesperson A demo-tenant_demo-01

DynamoDB item

{
  "composite_id": {"S":"demo-tenant_demo-01"},
  "local_date": {"S":"2021-07-26"},
  "tenantId": {"S":"demo-tenant"},
  "userId": {"S":"demo-01"},
  "routing_m": {"N":"540"},
  "away_m": {"N":"48"},
  "avail_m": {"N":"322"},
  "dc_m": {"N":"20"},
  "lo_m": {"N":"0"},
  "s_data": {"S":"540:3|65:2|43:22|42:2|20:4|28:2|48:1|89:2|35:22|20:2|0:1|150:x|360:3"},
  "last_status": {"S":"1"},
  "last_status_date": {"N":"1627284600000"},
  "tz": {"S":"Asia/Kuala_Lumpur"},
  "is_open": {"N":"4"},
  "close_at": {"N":"1627315199999"},
  "created": {"N":"1627261200000"},
  "modified": {"N":"1627284600000"}
}

Report response row

{
  "type": "updated",
  "salesperson": {"id":"demo-01","name":"Salesperson A"},
  "date": "2021-07-26",
  "data": "540:3|65:2|43:22|42:2|20:4|28:2|48:1|89:2|35:22|20:2|150:x|360:3"
}
Salesperson B demo-tenant_demo-02

DynamoDB item

{
  "composite_id": {"S":"demo-tenant_demo-02"},
  "local_date": {"S":"2021-07-26"},
  "tenantId": {"S":"demo-tenant"},
  "userId": {"S":"demo-02"},
  "routing_m": {"N":"540"},
  "away_m": {"N":"83"},
  "avail_m": {"N":"241"},
  "dc_m": {"N":"28"},
  "lo_m": {"N":"23"},
  "s_data": {"S":"540:3|23:0|89:2|28:24|45:2|63:21|20:1|65:2|42:22|0:2|165:x|360:3"},
  "last_status": {"S":"2"},
  "last_status_date": {"N":"1627283700000"},
  "tz": {"S":"Asia/Kuala_Lumpur"},
  "is_open": {"N":"4"},
  "close_at": {"N":"1627315199999"},
  "created": {"N":"1627261200000"},
  "modified": {"N":"1627283700000"}
}

Report response row

{
  "type": "updated",
  "salesperson": {"id":"demo-02","name":"Salesperson B"},
  "date": "2021-07-26",
  "data": "540:3|23:0|89:2|28:24|45:2|63:21|20:1|65:2|42:22|15:2|150:x|360:3"
}
Salesperson C demo-tenant_demo-03

DynamoDB item

{
  "composite_id": {"S":"demo-tenant_demo-03"},
  "local_date": {"S":"2021-07-26"},
  "tenantId": {"S":"demo-tenant"},
  "userId": {"S":"demo-03"},
  "routing_m": {"N":"540"},
  "away_m": {"N":"43"},
  "avail_m": {"N":"253"},
  "dc_m": {"N":"0"},
  "lo_m": {"N":"69"},
  "s_data": {"S":"540:3|59:2|43:1|38:2|33:22|33:2|69:0|90:2|0:4|175:x|360:3"},
  "last_status": {"S":"4"},
  "last_status_date": {"N":"1627283100000"},
  "tz": {"S":"Asia/Kuala_Lumpur"},
  "is_open": {"N":"4"},
  "close_at": {"N":"1627315199999"},
  "created": {"N":"1627261200000"},
  "modified": {"N":"1627283100000"}
}

Report response row

{
  "type": "updated",
  "salesperson": {"id":"demo-03","name":"Salesperson C"},
  "date": "2021-07-26",
  "data": "540:3|59:2|43:1|38:2|33:22|33:2|69:0|90:2|25:4|150:x|360:3"
}

routing_m includes time with no data during routing hours. The disconnected total dc_m also counts throttled minutes. app/lib/common.js at b4d7ca7

Where managers saw total availability

Salesperson app status showed when each status occurred during a selected day. Its Export to CSV control summed the returned timeline into minutes per status, with Available and Available (Engaged) in separate columns. The export followed the same report data as the bars, including any status the reader carried forward. src/app/manager-portal/pages/reports/salesperson-app-status/salesperson-app-status.component.ts in Portals/manager-portal at f1324139a

Salesperson action showed Total hours available and Available rate in its date-range grid, alongside lead acceptance and first-action time. Its backend summed the stored avail_m counters from the same DynamoDB table, combining the available and available-engaged statuses. The grid formatted that sum as a duration. For each salesperson with stored rows, the rate divided their available minutes by the largest cumulative routing-minutes total found across the tenant’s queried rows. app/lib/appStatus.js in Dodol/salesperson-action-report at 29de1ed src/app/manager-portal/pages/reports/salesperson-action/salesperson-action.component.ts in Portals/manager-portal at f1324139a

For Salesperson A in the synthetic day above, the CSV lists 244 minutes available and 78 minutes available while engaged. The Action report displays the stored 322 minutes as 05:22:00, or 59.63% of the 540-minute routing window in this example. For Salesperson B, the CSV includes the 15 minutes carried forward on read, so its two available columns add up to 256 minutes. The Action report still shows the stored 04:01:00 from 241 minutes.

These two reports shared the Manager Portal Reports menu with Lead source performance and Project CPX.

Architecture review

The central design is a daily rollup. DynamoDB holds one compact timeline per salesperson and tenant-local date, plus counters derived from that timeline. That suits the report’s main query, which opens one day for a roster of salespeople. It also gives the chart a simple contract. Each run tells the client how wide to draw one color. The archive shows how these pieces were designed and how they behaved in an offline replay.

How well the notation held up

The notation met the frontend-independence goal. Split on | to get the runs, split each run on : to get its duration and status code, and add up the durations to recover each start time. In Salesperson A’s row, the runs before 20:4 add up to 690 minutes after midnight, so any renderer can place that interval at 11:30–11:50. The original Angular component made one minute one pixel. This Jekyll reconstruction scales the same minutes to the width of the row. Colors and pixel widths are choices made by the renderer. src/app/manager-portal/pages/reports/salesperson-app-status/salesperson-bar/salesperson-bar.component.ts in Portals/manager-portal at f1324139a

The surrounding contract was mostly implicit. The string assumes minutes since local midnight and a shared status-code dictionary. The date and timezone live on the stored item. Code 23 contributes to off-routing totals and falls through both Angular lookups for colors and labels. The report reader can also merge adjacent runs, remove zero-duration changes, and extend a status beyond the last recorded event without marking which minutes were inferred. A renderer can recover the minute-by-minute timeline it was given. Recovering the original events or telling observed time from inferred time would require more information. app/lib/common.js at b4d7ca7 app/getAppStatusReport.js at b4d7ca7

A format version and a shared status dictionary would make it easier to add a renderer and keep old reports readable.

How the system fits together

  1. Presence publishes status changes. An SNS subscription forwards app events to SQS, and a Lambda consumes the queue and updates the daily rollup. A scheduled Lambda advances open rows every 15 minutes and closes past days. A separate worker reacts to routing-hours changes. app/lib/SNSAdapter.js in Dodol/Presence at 998c1f2 serverless.yml at b4d7ca7

  2. DynamoDB serves three access patterns. The primary key (composite_id, local_date) lets the report batch-read a roster’s rows. The tenant-and-date index lets the routing-hours worker find the rows to revise. The open-day index uses ten numeric buckets and a closing timestamp so the scheduled worker can query open rows by time. models/AppStatus.js at b4d7ca7 app/catchup.js at b4d7ca7

  3. The report joins activity to a roster. AppSync checks access and calls the report Lambda. CandyBase supplies active salesperson and grouping information, and the Lambda reads the corresponding daily rows. The same salesperson-day can appear under multiple project or team headings. Manager Portal receives JSON rows and turns the encoded runs into colored bars. mappingTemplates/reports.yml in Dodol/customer-api-appsync at d1778a0 app/lib/candyBaseDb.js at b4d7ca7 app/getAppStatusReport.js at b4d7ca7

How the team handled edge cases

  • Preserve the preceding run. In September 2019, Lim Shi Yek changed the reader to insert the elapsed minutes as a new run when filling a gap. The earlier code could write the latest status over the preceding run. The later updater also checked the stored event timestamp and skipped a message when it read a newer one already on the row. app/getAppStatusReport.js at 14fb701 app/updater.js at b4d7ca7

  • Keep the chart current and readable. Reza Rosli’s October 2020 changes extended the report to the current minute on read, imputed missing rows, and simplified the returned runs by dropping zero-duration transitions and merging adjacent spans of the same status. In Manager Portal, Mohd Thaqif Bin Abdullah Hasim introduced the one-bar-per-salesperson renderer and corrected the order of hour labels from midnight through noon. app/getAppStatusReport.js at ea76319 app/getAppStatusReport.js at 506d450 src/app/theme/pages/default/reports/salesperson-app-status/salesperson-bar/salesperson-bar.component.ts in Portals/manager-portal at 589006a8f src/app/theme/pages/default/reports/salesperson-app-status/salesperson-app-status.component.ts in Portals/manager-portal at 8d77892b6

  • React to schedule and calendar changes. A routing-hours notification triggered a rewrite of that tenant’s current-day rows. In December 2020, Reza changed the report lookup to derive the requested date in the manager’s timezone. The writer still chose the stored day in the tenant’s timezone. app/regenerate.js at b4d7ca7 app/lib/candyBaseDb.js at 5701572

Where correctness breaks

  • Concurrent writes can lose transitions. The updater reads the row, checks its timestamp in memory, and then writes it. In an offline replay, both same-row events passed the check, and the one at 15:45 persisted after the one at 15:55. The scheduled worker also writes whole rows it read earlier, so it creates another path for stale state to overwrite a newer update. app/updater.js at b4d7ca7 app/catchup.js at b4d7ca7

  • A routing-hours edit can corrupt an existing timeline. Moving the start from 09:00 to 10:00 in the synthetic day above produced 1,915 minutes. The worker replaced the first 65-minute available run with an unknown block, left the later runs in place, and kept the old availability total. The timeline and its derived counters could therefore disagree. app/regenerate.js at b4d7ca7

  • Two timezones define the day. The writer keys rows by the tenant’s local date, while the read path uses the requesting manager’s local date to look up those same keys. The mismatch matters near midnight and on weekday boundaries. The encoder also fixes each day at 1,440 minutes, which assumes a 24-hour day. A daylight-saving transition violates that assumption in zones that observe it. app/lib/candyBaseDb.js at 5701572 app/lib/common.js at b4d7ca7

What the chart can tell a manager

The bars combine observed transitions with carried-forward and imputed status. A report read can extend the latest status to the current minute. If a daily item is missing, the reader can use the previous day’s last status to construct a row. routing_m includes unknown time inside routing hours, so it measures the routing window rather than time the salesperson was observed online. Since grouping comes from the active CandyBase roster at read time, an older report can reflect later project membership. app/getAppStatusReport.js at b4d7ca7 app/lib/common.js at b4d7ca7

What I would keep and change

Keep the daily DynamoDB rollup and the interval-based chart. First, use a version check on every writer and retry from a fresh row on conflict. Apply routing-hours edits through the shared interval logic and derive all counters from the result. Define the report’s day in one timezone, send its actual start and end timestamps, and give the client explicit labels for observed, carried-forward, and imputed spans. If the report needs to support historical audits, retain the source transitions and the relevant schedule and roster versions so a past day can be rebuilt.

Development history

  1. 2019

    A daily status timeline

    1. Define a report driven by Presence

      Reza Rosli opened the repository with a README describing a service that observes Presence events and serves app-status reports.

      156da169f3d4
    2. Store the day as a compact run

      Lim Shi Yek made the scheduler create one DynamoDB item per salesperson and day. A default logged-off day could be stored as a single 1,440-minute run.

      5a853f6
    3. Handle a zero-minute routing window

      Lim guarded the last-status fill in the generator and report reader so it only wrote that run when the routing window contained time.

      fd1cbbf
  2. 2020

    Align live reports with the daily rollup

    1. Share interval and counter logic

      Reza refactored the report workers around a shared parser that advances status runs and derives the minute totals from those runs.

      78686670d0a3
    2. Use the manager’s timezone for report dates

      Reza changed the report lookup to use the requester’s timezone. The event writer continued to key items by the tenant’s local date.

      5701572

Primary contributor

Reza Rosli · 56 authored commits

Filtered the reporting stream to app status updates and made logged-out and engaged statuses explicit.

Example revisions 5135c24 (), 3b18d57 ().

When contributors were active

Authored commits per quarter through Q1 2023, oldest first. Rows are ordered by the first quarter with activity. Brighter cells show more commits. Scroll across to see later quarters.

Contributor2019 Q22019 Q32019 Q42020 Q12020 Q22020 Q32020 Q42021 Q12021 Q22021 Q3
Reza Rosli 56 commits · 2019 Q2–2021 Q3 1 7 2 0 3 0 37 2 0 4
Lim Shi Yek 53 commits · 2019 Q2–2020 Q1 4 31 17 1 0 0 0 0 0 0
Muhammad Anwaar 1 commit · 2020 Q1 0 0 0 1 0 0 0 0 0 0