Skip to content

Commit

Permalink
added .jsonl loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenknex committed Nov 7, 2018
1 parent 802ba74 commit 41e1344
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
35 changes: 33 additions & 2 deletions qtplot/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, filename):
self.shape = ()
self.ndim = 0

_, ext = os.path.splitext(filename)
base, ext = os.path.splitext(filename)

if ext == '.dat':
self.load_qtlab_data(self.filename)
Expand Down Expand Up @@ -57,9 +57,40 @@ def __init__(self, filename):
data.append(datafile['data'][key])

self.data = np.array(data).T

elif ext == '.jsonl':
try:
import pandas as pd
except ImportError:
logger.error('The pandas module was not found, it is needed to read .jsonl datasets')

df = pd.DataFrame(list(map(lambda x: json.loads(x) if len(x)>0 else {}, codecs.open(filename).read().split('\n'))))

data = []

for column in df.columns:
#if column == 'Datetime':
# continue

self.ids.append(column)
self.labels.append(column)

# The columns with the index are used to determine the grid dimensions
if column.startswith('_index'):
size = np.max(df[column].values) - np.min(df[column].values)

self.shape = self.shape + (size,)

if size > 1:
self.sizes[column] = size

# Count the number of non-length-1 coordinates
self.ndim += 1

self.data = df.values
else:
logger.error('Unknown file format: %s' % filename)


def load_qtlab_data(self, filename):
try:
Expand Down
2 changes: 1 addition & 1 deletion qtplot/qtplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def get_axis_names(self):
def on_load_dat(self, event):
open_directory = self.profile_settings['open_directory']
filename = str(QtGui.QFileDialog.getOpenFileName(directory=open_directory,
filter='*.dat *.json'))
filter='*.dat *.json *.jsonl'))

if filename != "":
self.load_dat_file(filename)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

version = '0.1.3'
version = '0.1.4'

setup(name='qtplot',
version=version,
Expand Down

0 comments on commit 41e1344

Please sign in to comment.