311-data icon indicating copy to clipboard operation
311-data copied to clipboard

Spike: Data Loading Checklist for Socrata API Metrics

Open rayneng opened this issue 1 year ago • 12 comments

Dependency

  • [ ] Reopen when there is a need to analyze these results, or if the user flow is modified and it changes the amount of data we might expect to load

Overview

We need to create a process for measuring Socrata API response times, given our use-cases, so that the design team knows how long their loading-screen content should remain on-screen.

More Info (optional)

Design team is wanting to know whether to skip certain flows for very-fast response times, in the case that data always takes a certain time to load. I.e., we want to obtain a general minimum load time.

Action Items

  • [ ] Copy the template from the copy block in Resources into a comment

Resources/Instructions


### System Information
- Platform: (Postman, Thunder Client, etc)
- Request Status: (Open / Closed)
- Request Shortname (i.e. : Open Tickets From 2025 March, Electronic Waste)
- Request Duration (e.g. 10.57 seconds)

<paste your request body here with triple backticks before and after>

  • Parent Ticket: https://github.com/hackforla/311-data/issues/1890
    • Similar to: https://github.com/hackforla/311-data/issues/1716
Query Example: Open Tickets From 2025 March, Electronic Waste

https://data.lacity.org/resource/h73f-gn57.json?$where=status = 'Open' AND createddate between '2025-06-04' and '2025-06-18' AND requesttype = 'Electronic Waste'

Query Example: Open Tickets From 2025 Last Two Weeks, Bulky Items or Animal Remains

https://data.lacity.org/resource/h73f-gn57.json?$where=status = 'Open' AND createddate between '2025-06-04' and '2025-06-18' AND (requesttype = 'Bulky Items' OR requesttype = 'Animal Remains')

Query Example: Number of SRs Grouped By NC

https://data.lacity.org/resource/b7dx-7gc3.json?$select=ncname, nc as nc_id, status, COUNT(status) as total_open&$group=ncname, nc_id, status&$where=status = 'Open' AND createddate between '2024-10-26' and '2024-10-29T23:59:59'

Resource Base URLs

2025

https://data.lacity.org/resource/h73f-gn57.json

2024

https://data.lacity.org/resource/b7dx-7gc3.json

2023

https://data.lacity.org/resource/4a4x-mna2.json

All Service Request Types

[
  {
    "requesttype": "Bulky Items",
    "total": "167505"
  },
  {
    "requesttype": "Dead Animal Removal",
    "total": "6508"
  },
  {
    "requesttype": "Electronic Waste",
    "total": "9849"
  },
  {
    "requesttype": "Feedback",
    "total": "278"
  },
  {
    "requesttype": "Graffiti Removal",
    "total": "121791"
  },
  {
    "requesttype": "Homeless Encampment",
    "total": "24031"
  },
  {
    "requesttype": "Illegal Dumping Pickup",
    "total": "32735"
  },
  {
    "requesttype": "Metal/Household Appliances",
    "total": "26074"
  },
  {
    "requesttype": "Multiple Streetlight Issue",
    "total": "8149"
  },
  {
    "requesttype": "Other",
    "total": "2791"
  },
  {
    "requesttype": "Report Water Waste",
    "total": "357"
  },
  {
    "requesttype": "Single Streetlight Issue",
    "total": "6219"
  }
]

How does our app __currently__ query data

This code block was abridged to focus on the specific fields we are querying, i.e. CreatedDate !

async getAllRequests(startDate, endDate) {
    const { conn } = this.context;
   // ...
    let selectSQL = '';

    try {
      if (startYear === endYear) {
        // ...
        const tableName = `requests_${startYear}`;
        selectSQL = `SELECT * FROM ${tableName} WHERE CreatedDate BETWEEN '${startDate}' AND '${endDate}'`;
      } else {
        // If the dates span multiple years, create two queries and union them.
        // ...
      }

      // ...
      const requestsAsArrowTable = await conn.query(selectSQL);
      const requests = ddbh.getTableData(requestsAsArrowTable);
      return requests;
    } catch (e) {
      console.error("Error during database query execution:", e);
    }
  }

Notes on CreatedDate

There is one aspec-t that bothers me about how we are utilizing StartDate and EndDate: we are using these fields to filter the CreatedDate response field. But what question does this really answer? So, if I say, give me all of the Service Requests that were created-on June 1st through June15, that sounds useful for seeing what SRs were made in the last two weeks. But, what does it mean to ask "give me all of the SRs that were created-on Jan 1st through June 1st"?

Let's consider the two statuses, Open and Closed. Looking at all Open SRs created in the last two weeks is still useful -- it tells you "what's the latest activity (ongoing)". Finding all the Closed SRs created in the last two weeks gives you a slightly different lens: "what and where are all the quick-closing tickets?" Perhaps this can be used as a means to determine "which NCs close tickets very quickly", or "which SR types get closed very quickly". This also leads you to ask, "are these tickets closing very quickly because the responsible party is actually well resourced and is able to quickly address problems?". Conversely, you could ask, what NCs are closing tickets very quickly without actually solving the problem -- why are they allowed to do that? Are there any responsible parties that might want to close tickets quickly on their system, just to give the impression that they are actually being serviced?

Ramblings to continue...

rayneng avatar Jun 17 '25 22:06 rayneng

System Information

  • Platform: Thunder Client VS Code extension
  • Request Status: Open
  • Request Shortname: Open Tickets From 2025-06-04 to 2025-06-18, Bulky Items or Animal Remains
  • Request Duration: 0.333s

Query Example: Open Tickets From 2025-06-04 to 2025-06-18, Bulky Items or Animal Remains

https://data.lacity.org/resource/h73f-gn57.json?$where=status = 'Open' AND createddate between '2025-06-04' and '2025-06-18' AND (requesttype = 'Bulky Items' OR requesttype = 'Animal Remains')

DrAcula27 avatar Jun 19 '25 01:06 DrAcula27

System Information

  • Platform: Postman
  • Request Status: Open
  • Request Shortname: Open Tickets From 2025 — Last Two Weeks, Bulky Items or Animal Remains

Query Examples: Open Tickets From 2025 (Last Two Weeks)

Variant A: Encoded spaces (%20) with T00:00:00

  • Request Duration: 0.578, 0.289, 0.238, 0.254, 0.244 ~ 0.3206 seconds
https://data.lacity.org/resource/h73f-gn57.json?$where=status='Open'%20AND%20createddate%20between%20'2025-06-04T00:00:00'%20and%20'2025-06-18T23:59:59'%20AND%20(requesttype='Bulky%20Items'%20OR%20requesttype='Animal%20Remains')

Variant B: Natural spacing with IN (...)

  • Request Duration: 0.530, 0.257, 0.242, 0.226, 0.291 ~ 0.3092 seconds
https://data.lacity.org/resource/h73f-gn57.json?$where=status='Open' AND createddate between '2025-06-04T00:00:00' AND '2025-06-18T23:59:59' AND requesttype IN ('Bulky Items', 'Animal Remains')

Variant C: Date-only variant without timestamps

  • Request Duration: 0.554, 0.372, 0.414, 0.407, 0.375 ~ 0.4244 seconds
https://data.lacity.org/resource/h73f-gn57.json?$where=status='Open' AND createddate between '2025-01-06' AND '2025-06-18' AND (requesttype='Bulky Items' OR requesttype='Animal Remains')

Query Examples: Full Year (2025), Bulky Items or Animal Remains

January–December with encoded spaces and $limit=9999

  • Request Duration: 0.388, 0.385, 0.369, 0.487, 0.418 ~ 0.4094 seconds
https://data.lacity.org/resource/h73f-gn57.json?$where=status='Open'%20AND%20createddate%20between%20'2025-01-01T00:00:00'%20and%20'2025-12-31T23:59:59'%20AND%20(requesttype='Bulky%20Items'%20OR%20requesttype='Animal%20Remains')&$limit=9999

Same query with natural spacing

  • Request Durations: 0.418, 0.389, 0.396, 0.404, 0.390 ~ 0.3994 seconds
https://data.lacity.org/resource/h73f-gn57.json?$where=status='Open' AND createddate between '2025-01-01T00:00:00' and '2025-12-31T23:59:59' AND (requesttype='Bulky Items' OR requesttype='Animal Remains')&$limit=9999

Date-only variant without timestamps

  • Request Duration: 0.474, 0.388, 0.444, 0.357, 0.387 ~ 0.41 seconds
https://data.lacity.org/resource/h73f-gn57.json?$where=status='Open' AND createddate between '2025-01-01' AND '2025-12-31' AND (requesttype='Bulky Items' OR requesttype='Animal Remains')

ykimdeveloper avatar Jun 19 '25 01:06 ykimdeveloper

System Information

  • Platform: Postman
  • Request Status: Open
  • Request Shortname: Query Example: Number of SRs Grouped By NC
  • Request Duration: 1.24s
  • Records: 68

Query Example: Number of SRs Grouped By NC From 2024-10-26 to 2024-10-29

https://data.lacity.org/resource/b7dx-7gc3.json?$select=ncname, nc as nc_id, status, COUNT(status) as total_open&$group=ncname, nc_id, status&$where=status = 'Open' AND createddate between '2024-10-26' and '2024-10-29T23:59:59'

melissaluc avatar Jun 19 '25 01:06 melissaluc

System Information

  • Platform: Thunder Client VS Code extension
  • Request Status: Closed
  • Request Shortname: Closed Tickets From 2025-06-04 to 2025-06-18, Bulky Items or Animal Remains
  • Request Duration: 0.812s

Query Example: Closed Tickets From 2025-06-04 to 2025-06-18, Bulky Items or Animal Remains

https://data.lacity.org/resource/h73f-gn57.json?$where=status = 'Closed' AND createddate between '2025-06-04' and '2025-06-18' AND (requesttype = 'Bulky Items' OR requesttype = 'Animal Remains')

DrAcula27 avatar Jun 19 '25 01:06 DrAcula27

System Information

  • Platform: Postman
  • Request Status: Open
  • Request Shortname: Query Example: Number of SRs Grouped By NC
  • Request Duration: 1.08s
  • Records: 100

Query Example: Number of SRs Grouped By NC From 2024-06-13 to 2024-09-25

https://data.lacity.org/resource/b7dx-7gc3.json?$select=ncname, nc as nc_id, status, COUNT(status) as total_open&$group=ncname, nc_id, status&$where=status = 'Open' AND createddate between '2024-06-13' and '2024-09-25T23:59:59'

melissaluc avatar Jun 19 '25 01:06 melissaluc

System Information

  • Platform: Postman
  • Request Status: Open
  • Request Shortname: Open Tickets From 2025 Last Two Weeks (6/4-6/18), Electronic Waste Request Type
  • Request Duration: 0.306 seconds
  • Records: 163

Query Example: Open Tickets From 2025-06-04 to 2025-06-18, Electronic Waste

https://data.lacity.org/resource/b7dx-7gc3.json?$where=requesttype='Electronic Waste' AND status='Open' AND createddate >= '2024-06-04' AND createddate <= '2024-06-18'

githelsui avatar Jun 19 '25 01:06 githelsui

System Information

  • Platform: Thunder Client VS Code extension
  • Request Status: Open
  • Request Shortname: Open Tickets From 2025-01-04 to 2025-06-18, Bulky Items or Animal Remains
  • Request Duration: 0.534s

Query Example: Open Tickets From 2025-01-04 to 2025-06-18, Bulky Items or Animal Remains

https://data.lacity.org/resource/h73f-gn57.json?$where=status = 'Open' AND createddate between '2025-01-04' and '2025-06-18' AND (requesttype = 'Bulky Items' OR requesttype = 'Animal Remains') &$limit=999999

DrAcula27 avatar Jun 19 '25 01:06 DrAcula27

System Information

  • Platform: Thunder Client VS Code extension
  • Request Status: Open
  • Request Shortname: Open Tickets From 2024-01-04 to 2024-12-31, Bulky Items or Animal Remains
  • Request Duration: 0.932s

Query Example: Open Tickets From 2024-01-04 to 2024-12-31, Bulky Items or Animal Remains

https://data.lacity.org/resource/b7dx-7gc3.json?$where=status = 'Open' AND createddate between '2024-01-04' and '2024-12-31' AND (requesttype = 'Bulky Items' OR requesttype = 'Animal Remains') &$limit=999999

DrAcula27 avatar Jun 19 '25 01:06 DrAcula27

System Information

  • Platform: Postman
  • Request Status: Open
  • Request Shortname: Query Example: Number of SRs Grouped By NC
  • Request Duration: 3.85 s
  • Records: 101

Query Example: Number of SRs Grouped By NC From 2024-01-15 to 2024-12-30 w/ limit=999999

https://data.lacity.org/resource/b7dx-7gc3.json?$select=ncname, nc as nc_id, status, COUNT(status) as total_open&$group=ncname, nc_id, status&$where=status = 'Open' AND createddate between '2024-01-15' and '2024-12-30T23:59:59'&$limit=999999

melissaluc avatar Jun 19 '25 01:06 melissaluc

System Information

  • Platform: Thunder Client VS Code extension
  • Request Status: Open AND Closed
  • Request Shortname: Open and Closed Tickets From 2024-01-04 to 2024-12-31, Number of SRs Grouped By NC and Grouped By Status
  • Request Duration 1: 30.34s
  • Request Duration 2: 6.77s
  • Request Duration 3: 6.54s
  • Request Duration 4: 5.99s

Query Example: Open Tickets From 2023-01-01 to 2023-12-31, Number of SRs Grouped By NC and Grouped By Status

https://data.lacity.org/resource/4a4x-mna2.json?$select=ncname, nc as nc_id, status, COUNT(status) as total_open&$group=ncname, nc_id, status&$where=(status = 'Open' OR status = 'Closed') AND createddate between '2023-01-01' and '2023-12-31'

DrAcula27 avatar Jun 19 '25 02:06 DrAcula27

In regards to the first API call taking significantly longer than the subsequent ones, it most likely has to do with how HTTP protocols are handled. Establishing an HTTP connection takes some time the first time around in order to get established and have a secure connection. After it's established, subsequent calls take less time as the connection is already verified and secured.

This should help shed some light on why some of these results are longer than others. Possible solution would be to implement caching and sessions on the user side. We would just need to discuss time frames and what roadblocks from a dev side we might encounter with this solution.

efrenmarin45 avatar Jun 19 '25 02:06 efrenmarin45

Results of this ticket were forwarded to design team back in June. See mentioned tickets for more info. Moving back to Icebox.

rayneng avatar Aug 12 '25 20:08 rayneng