-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdatalist.py
More file actions
33 lines (26 loc) · 886 Bytes
/
datalist.py
File metadata and controls
33 lines (26 loc) · 886 Bytes
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
import json
import os
from names import shortNames
from gesture import Gesture
from matplotlib import pyplot as plt
class DataList:
def __init__(self):
if os.path.isfile("datalist.json"):
self.jsonData = json.load(open("datalist.json", "rb"))
else:
self.jsonData = { }
for i in range(len(shortNames)):
self.jsonData[i] = []
def commit(self):
json.dump(self.jsonData, open("datalist.json", "wb"), sort_keys=True, indent=4, separators=(',', ': '))
def add(self, gestType, subject):
if self.isGood(gestType, subject):
return
self.jsonData[str(gestType)].append(subject)
def remove(self, gestType, subject):
if self.isGood(gestType, subject):
self.jsonData[str(gestType)].remove(subject)
def isGood(self, gestType, subject):
return subject in self.jsonData[str(gestType)]
def numGood(self, gestType):
return len(self.jsonData[str(gestType)])