forked from aitoralmeida/c4a_activity_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpertActivityModel.py
89 lines (70 loc) · 2.43 KB
/
ExpertActivityModel.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
"""
Created on Wed May 4 10:49:28 2016
@author: gazkune
"""
from datetime import datetime
class ExpertActivityModel:
def __init__(self, name=None, infodict=None):
""" Constructor
Usage example:
eam = ExpertActivityModel("MakeChocolate", eamdict)
Parameters
----------
name : string
the name of the target activity
infodict : dict
a dict with the information related to an EAM (usually read from a JSON file)
Returns
----------
Instance of the class
"""
if name is not None and isinstance(infodict, dict):
self.name = name
self.locations = infodict["locations"]
self.actions = infodict["actions"]
self.duration = infodict["duration"]
# convert strings to datetime types
#self.start = infodict["start"]
self.start = []
self.convert_start_list(infodict["start"])
else:
self.name = ""
self.locations = []
self.actions = []
self.duration = -1
self.start = []
def print_eam(self):
""" Method to print an instance of EAM
Usage example:
print_eam()
Parameters
----------
None
Returns
----------
None
"""
print(self.name)
print(' locations:', self.locations)
print(' actions:', self.actions)
print(' duration:', self.duration)
print(' start:')
for timerange in self.start:
print (' ', timerange[0].strftime("%H:%M"), '-', timerange[1].strftime("%H:%M"))
def convert_start_list(self, rangelist):
""" Method to convert time ranges read from the dict to datetime type
Usage example:
convert_start_list(rangelist)
Parameters
----------
rangelist : list
a list of strings, with the start time ranges
Returns
----------
None
"""
for timerange in rangelist:
time1 = datetime.strptime(timerange[0], "%H:%M")
time2 = datetime.strptime(timerange[1], "%H:%M")
self.start.append([time1, time2])