-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.py
59 lines (44 loc) · 1.5 KB
/
file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# file.py - Filesystem type operations.
#
import json
import linecache
import os
from config import *
from const import *
def load_state_file(state_file_path):
state_file = open(state_file_path, "r")
state_tracker = json.loads(state_file.read())
state_file.close()
print("Loaded State File: ", state_tracker)
return state_tracker
def create_state_file(state_file_path):
# Instantiate a default state_tracker JSON object
state_tracker = {
"current_line": 1,
"eps": 0,
"time_window": 0.0,
}
print("Creating New State File: ", state_file_path)
# Write the new state file to disk (with current_line=1 and calculated time_offset)
write_state_to_disk(state_file_path, state_tracker)
print("Created New State File", state_file_path, "\n")
return state_tracker
def get_data_file_length(data_file_path):
data_file = open(data_file_path, "r")
for data_file_length, line in enumerate(data_file):
pass
data_file_length += 1
data_file.close()
print("Data File Length:", data_file_length, "\n")
return data_file_length
def get_line(data_file_path, line_number):
lineData = linecache.getline(data_file_path, line_number)
return json.loads(lineData)
def write_state_to_disk(state_file_path, state_tracker):
file = open(state_file_path, "w")
json.dump(state_tracker, file)
file.close()
def delete_state_file(state_file_path):
os.remove(state_file_path)
print("Deleted State File")