Skip to content

Add sensor datapoint access with linear interpolation support#14

Draft
Copilot wants to merge 3 commits into
developfrom
copilot/fix-5
Draft

Add sensor datapoint access with linear interpolation support#14
Copilot wants to merge 3 commits into
developfrom
copilot/fix-5

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 16, 2025

This PR implements a new GraphQL API for accessing single sensor datapoints before, after, or interpolated at a given datetime value, addressing the need for precise sensor data retrieval at specific timestamps.

New Features

GraphQL API

Added a new sensor_datapoint resolver that supports three access modes:

query GetSensorDatapoint($sensorId: String!, $targetTime: DateTime!, $direction: String!) {
  sensorDatapoint(sensorId: $sensorId, targetTime: $targetTime, direction: $direction) {
    value
    timestamp
    isInterpolated
    sourceReadings {
      timestamp
      value
    }
  }
}

Direction modes:

  • "before" - Returns the last reading before the target time
  • "after" - Returns the first reading after the target time
  • "interpolate" - Returns a linearly interpolated value at the target time

Linear Interpolation

The interpolation feature calculates time-weighted averages between the closest readings:

interpolated_value = before_value + factor * (after_value - before_value)
factor = (target_time - before_time) / (after_time - before_time)

This enables smooth data access for applications like Heat Pump COP calculations where precise values at period boundaries are needed.

Implementation Details

  • Backend: New SingleDatapoint GraphQL type with interpolation metadata
  • Frontend: Added GET_SENSOR_DATAPOINT query for easy integration
  • Tests: Comprehensive test suite covering all modes and edge cases
  • Performance: Efficient database queries using proper indexing and limits

Use Cases

This feature is particularly valuable for:

  • Heat pump efficiency analysis requiring precise energy readings at period boundaries
  • Historical data analysis at specific timestamps
  • Data smoothing and gap filling in time series
  • Threshold monitoring at exact times

Fixes #5.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 16, 2025

@intui 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits September 16, 2025 12:34
Co-authored-by: intui <15924901+intui@users.noreply.github.com>
Co-authored-by: intui <15924901+intui@users.noreply.github.com>
Copilot AI changed the title [WIP] access single datapoint Add sensor datapoint access with linear interpolation support Sep 16, 2025
Copilot AI requested a review from intui September 16, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

access single datapoint

2 participants