-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpool_table_data.py
More file actions
47 lines (41 loc) · 1.72 KB
/
pool_table_data.py
File metadata and controls
47 lines (41 loc) · 1.72 KB
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
import json
from pool_table import PoolTable
from config import Config
config = Config()
# class handles generation of json files for susbsequent billing and for data recovery
class TableData():
def __init__(self, date):
self.date = date
self.entry_list = []
self.recovery_list = []
# cretes a session entry for later billing
def create_entry(self, table, start, end, total_time):
f_start = config.date_format(start)
f_end = config.date_format(end)
f_total_time = config.timer_format(end, start)
cost = config.cost_calc(end, start)
entry = {
"Pool Table Number": table, "Start Time": f_start,
"End Time": f_end, "Total Time Played": f_total_time, "Cost": cost
}
self.entry_list.append(entry)
return self.entry_list
# creates a data recocvery entry a checkout for possible app failure
def create_recovery_entry(self, table, start, end):
rec_entry = {"Pool Table Number": table,
"Start Time": str(start), "End Time": str(end)}
self.recovery_list.append(rec_entry)
return self.recovery_list
# writes to json file for billing
def log_entry(self, entry):
with open(f'{self.date}.json', 'w') as file_object:
json.dump(entry, file_object, indent=2)
# writes to json recovery file
def rec_entry(self, entry):
with open(f'{self.date}-rec.json', 'w') as file_object:
json.dump(entry, file_object, indent=2)
# loads json recovery file -- json object conversion
def recovery(self, date):
with open(f'{self.date}-rec.json') as file_object:
recovery_list = json.load(file_object)
return recovery_list