Download prepare.py from jashing/TimeSeries01: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/datasets/jashing/TimeSeries01/resolve/main/prepare.py
- Command line
-
hf download hf://datasets/jashing/TimeSeries01/prepare.py
-
curl -L -o prepare.py https://huggingface.co/datasets/jashing/TimeSeries01/resolve/main/prepare.py
1.54 kB
| import json | |
| def prepare(): | |
| file_path = 'energy_train.jsonl.txt' | |
| targets = [] | |
| # Open the JSON file and read it line by line | |
| with open(file_path, 'r') as file: | |
| for line in file: | |
| #print (line) | |
| try: | |
| # Parse the JSON string in each line | |
| data = json.loads(line) | |
| # Extract the values of "timestamp" and "target" keys | |
| #timestamp = data.get("timestamp") | |
| target = data.get("target") | |
| if target is not None: | |
| #timestamps.append(timestamp) | |
| targets.append(target) | |
| except json.JSONDecodeError: | |
| print(f"Skipping invalid JSON: {line}") | |
| # Now, you have the extracted values in the "timestamps" and "targets" lists | |
| # You can use these lists as needed | |
| #print("Timestamps:", timestamps) | |
| #print("Targets:", targets) | |
| hist_size = 10 | |
| prd_size = 1 | |
| while targets: | |
| # Get the first 5 elements and join them with spaces | |
| history = ' '.join(map(str, targets[:hist_size])) | |
| out = ' '.join(map(str,targets[hist_size:hist_size+prd_size])) | |
| # Construct the JSON string | |
| json_str = json.dumps({"color": out, "description": history}) | |
| print (json_str) | |
| # Remove the first 6 elements from the float array | |
| targets = targets[1:] | |
| if len(targets) == hist_size: | |
| break | |
| if __name__ == "__main__": | |
| #import fire | |
| #fire.Fire(prepare) | |
| prepare() | |