aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/DataStructures.py
diff options
context:
space:
mode:
authorThéo de la Hogue2022-11-08 14:42:36 +0100
committerThéo de la Hogue2022-11-08 14:42:36 +0100
commitd061d4729122cf7dbda2f78252826f4c93debc94 (patch)
tree9cba1bc4f3ee2e8cb4fbd3aff334a85653b1e190 /src/argaze/DataStructures.py
parentb92a114386c9abf5b2d22d013a18ae848e1eeca7 (diff)
downloadargaze-d061d4729122cf7dbda2f78252826f4c93debc94.zip
argaze-d061d4729122cf7dbda2f78252826f4c93debc94.tar.gz
argaze-d061d4729122cf7dbda2f78252826f4c93debc94.tar.bz2
argaze-d061d4729122cf7dbda2f78252826f4c93debc94.tar.xz
Improving code documentation.
Diffstat (limited to 'src/argaze/DataStructures.py')
-rw-r--r--src/argaze/DataStructures.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py
index c86d021..44f64cc 100644
--- a/src/argaze/DataStructures.py
+++ b/src/argaze/DataStructures.py
@@ -39,15 +39,20 @@ class TimeStampedBuffer(collections.OrderedDict):
self[ts] = value
def get_first(self):
- """Easing access to first item"""
+ """Easing access to first item.
+ **Returns:** data"""
+
return list(self.items())[0]
def pop_first(self):
- """Easing FIFO access mode"""
+ """Easing FIFO access mode.
+ **Returns:** data"""
+
return self.popitem(last=False)
def pop_first_until(self, ts):
- """Pop all item until a given timestamped value and return the last poped item"""
+ """Pop all item until a given timestamped value and return the last poped item.
+ **Returns:** data"""
# get last timestamp before given timestamp
earliest_ts = self.get_last_before(ts)
@@ -64,15 +69,20 @@ class TimeStampedBuffer(collections.OrderedDict):
return popep_ts, poped_value
def get_last(self):
- """Easing access to last item"""
+ """Easing access to last item.
+ **Returns:** data"""
+
return list(self.items())[-1]
def pop_last(self):
- """Easing FIFO access mode"""
+ """Easing FIFO access mode.
+ **Returns:** data"""
+
return self.popitem(last=True)
def get_last_before(self, ts):
- """Retreive last item timestamp before a given timestamp value."""
+ """Retreive last item timestamp before a given timestamp value.
+ **Returns:** data"""
ts_list = list(self.keys())
last_before_index = bisect.bisect_left(ts_list, ts) - 1
@@ -87,6 +97,7 @@ class TimeStampedBuffer(collections.OrderedDict):
def export_as_json(self, filepath):
"""Write buffer content into a json file."""
+
try:
with open(filepath, 'w', encoding='utf-8') as jsonfile:
json.dump(self, jsonfile, ensure_ascii = False, default=vars)
@@ -94,7 +105,8 @@ class TimeStampedBuffer(collections.OrderedDict):
raise RuntimeError(f'Can\' write {filepath}')
def as_dataframe(self, exclude=[], split={}):
- """Convert buffer as pandas dataframe. Timestamped values must be stored as dictionary where each keys will be related to a column."""
+ """Convert buffer as pandas dataframe. Timestamped values must be stored as dictionary where each keys will be related to a column.
+ **Returns:** pandas.Dataframe"""
df = pandas.DataFrame.from_dict(self.values())
df.drop(exclude, inplace=True, axis=True)
@@ -110,6 +122,7 @@ class TimeStampedBuffer(collections.OrderedDict):
def export_as_csv(self, filepath, exclude=[]):
"""Write buffer content into a csv file."""
+
try:
self.as_dataframe(exclude=exclude).to_csv(filepath, index=True)
@@ -118,6 +131,8 @@ class TimeStampedBuffer(collections.OrderedDict):
raise RuntimeError(f'Can\' write {filepath}')
def plot(self, names=[], colors=[], split={}, samples=None):
+ """Plot data into time chart.
+ **Returns:** list"""
df = self.as_dataframe(split=split)
legend_patches = []