Strong-type data points, avoid magic strings
- Dominant language
- TypeScript
- Stars
- 211
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
It is great that this project is being converted to TypeScript. I wanted to suggest to use generics for strong-typing data points in time series, and avoid magic strings as much as possible. I created this commit to show how the interfaces could be updated to do that (it does not include the implementation):
Commit: [Add generic type for data points](https://github.com/omidkrad/pond/commit/4e4818dfbc5233d08a040e821b0392babef22324)
With that, as an example, `avg` function could be updated to support this signature:
```typescript
avg(key: (data: TData) => number, filter?: any): number;
```
and be used like below:
```typescript
import { timeSeries } from "pondjs";
interface SensorDataPoint {
time: number;
sensor: number;
status: string;
}
const series = timeSeries({
name: "sensor_data",
columns: ["time", "sensor", "status"], // checked, non-existent keys like "status1" will give error
points: [
[1400425947000, 3, "ok"],
[1400425948000, 8, "high"],
[1400425949000, 2, "low"],
[1400425950000, 3, "ok"],
]
});
// by field
series.avg(d => d.sensor); // 4
// calculation
series.avg(d => d.sensor + d.sensor2 * 100);
// field path
series.avg(d => d.sensor.diningRoom);
```
I believe function signatures that receive magic strings should be deprecated in favor of this new signature.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.