Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
WISP / src /wisp /utils /jsonl.py
Zipeng365's picture
Add files using upload-large-folder tool
80b01cc verified
Raw History Blame Contribute Delete
756 Bytes
# Paper-scoped implementation; see SOURCE_PROVENANCE.json.
from __future__ import annotations
import json
from pathlib import Path
from typing import Any, Iterable
def append_jsonl(path: str | Path, row: dict[str, Any]) -> None:
p = Path(path)
p.parent.mkdir(parents=True, exist_ok=True)
with p.open('a', encoding='utf-8') as f:
f.write(json.dumps(row, ensure_ascii=False, sort_keys=True) + '\n')
def read_jsonl(path: str | Path) -> list[dict[str, Any]]:
p = Path(path)
if not p.exists():
return []
rows: list[dict[str, Any]] = []
with p.open('r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if line:
rows.append(json.loads(line))
return rows