jashing
commited on
Commit
·
ad228ad
1
Parent(s):
6e62294
learn from burkelibbey/colors
Browse files- parser.py +53 -0
- train.jsonl +0 -0
- train.tar.gz +3 -0
parser.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
# Specify the path to your JSON file
|
4 |
+
file_path = 'train.jsonl'
|
5 |
+
|
6 |
+
# Initialize empty lists to store the extracted values
|
7 |
+
#timestamps = []
|
8 |
+
targets = []
|
9 |
+
|
10 |
+
# Open the JSON file and read it line by line
|
11 |
+
with open(file_path, 'r') as file:
|
12 |
+
for line in file:
|
13 |
+
try:
|
14 |
+
# Parse the JSON string in each line
|
15 |
+
data = json.loads(line)
|
16 |
+
|
17 |
+
# Extract the values of "timestamp" and "target" keys
|
18 |
+
#timestamp = data.get("timestamp")
|
19 |
+
target = data.get("target")
|
20 |
+
|
21 |
+
if target is not None:
|
22 |
+
#timestamps.append(timestamp)
|
23 |
+
targets.append(target)
|
24 |
+
|
25 |
+
except json.JSONDecodeError:
|
26 |
+
print(f"Skipping invalid JSON: {line}")
|
27 |
+
|
28 |
+
# Now, you have the extracted values in the "timestamps" and "targets" lists
|
29 |
+
# You can use these lists as needed
|
30 |
+
#print("Timestamps:", timestamps)
|
31 |
+
print("Targets:", targets)
|
32 |
+
|
33 |
+
hist_size = 10
|
34 |
+
prd_size = 1
|
35 |
+
|
36 |
+
while targets:
|
37 |
+
# Get the first 5 elements and join them with spaces
|
38 |
+
history = ' '.join(map(str, targets[:hist_size]))
|
39 |
+
out = ' '.join(map(str,targets[hist_size:hist_size+prd_size]))
|
40 |
+
|
41 |
+
# Construct the JSON string
|
42 |
+
json_str = json.dumps({"color": out, "description": history})
|
43 |
+
|
44 |
+
print (json_str)
|
45 |
+
# Remove the first 6 elements from the float array
|
46 |
+
targets = targets[1:]
|
47 |
+
if len(targets) == hist_size:
|
48 |
+
break
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
train.jsonl
ADDED
The diff for this file is too large to render.
See raw diff
|
|
train.tar.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:93b88c939ad2f577769b7da2f8cad69c73937db99931edae90c21bb89b5bb46b
|
3 |
+
size 209
|