Skip to content

Commit

Permalink
Add aggregation and generalized channel output in View and View Colle…
Browse files Browse the repository at this point in the history
…ction __repr__ (#12)

* add aggregation funcs and generalize channel output

* capitalize aggregate function in repr
  • Loading branch information
westernguy2 committed Jun 7, 2020
1 parent eaf47df commit 2d26715
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 14 deletions.
26 changes: 20 additions & 6 deletions lux/view/View.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,32 @@ def __repr__(self):
x_channel = ""
y_channel = ""
filter_spec = None
channels, additional_channels = [], []
for spec in self.specLst:
if spec.value != "":
filter_spec = spec
if spec.channel == "x":
x_channel = spec.attribute
elif spec.channel == "y":
y_channel = spec.attribute
if spec.attribute != "":
if spec.aggregation != "":
attribute = spec.aggregation.upper() + "(" + spec.attribute + ")"
elif spec.binSize > 0:
attribute = "BIN(" + spec.attribute + ")"
else:
attribute = spec.attribute
if spec.channel == "x":
channels.insert(0, [spec.channel, attribute])
elif spec.channel == "y":
channels.insert(1, [spec.channel, attribute])
elif spec.channel != "":
additional_channels.append([spec.channel, attribute])
channels.extend(additional_channels)
str_channels = ""
for channel in channels:
str_channels += channel[0] + ": " + channel[1] + ", "

if filter_spec:
return f"<View (x: {x_channel}, y: {y_channel} -- [{filter_spec.attribute}{filter_spec.filterOp}{filter_spec.value}]) mark: {self.mark}, score: {self.score} >"
return f"<View ({str_channels[:-2]} -- [{filter_spec.attribute}{filter_spec.filterOp}{filter_spec.value}]) mark: {self.mark}, score: {self.score} >"
else:
return f"<View (x: {x_channel}, y: {y_channel}) mark: {self.mark}, score: {self.score} >"
return f"<View ({str_channels[:-2]}) mark: {self.mark}, score: {self.score} >"
def _repr_html_(self):
from IPython.display import display
checkImportLuxWidget()
Expand Down
42 changes: 34 additions & 8 deletions lux/view/ViewCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ def __repr__(self):
for spec in view.specLst:
if spec.value != "":
filter_spec = spec
if spec.channel == "x" and len(x_channel) < len(spec.attribute):
x_channel = spec.attribute
if spec.channel == "y" and len(y_channel) < len(spec.attribute):
y_channel = spec.attribute

if spec.aggregation != "":
attribute = spec.aggregation.upper() + "(" + spec.attribute + ")"
elif spec.binSize > 0:
attribute = "BIN(" + spec.attribute + ")"
else:
attribute = spec.attribute

if spec.channel == "x" and len(x_channel) < len(attribute):
x_channel = attribute
if spec.channel == "y" and len(y_channel) < len(attribute):
y_channel = attribute
if len(view.mark) > largest_mark:
largest_mark = len(view.mark)
if filter_spec and len(str(filter_spec.value)) + len(filter_spec.attribute) > largest_filter:
Expand All @@ -38,26 +46,44 @@ def __repr__(self):
filter_spec = None
x_channel = ""
y_channel = ""
additional_channels = []
for spec in view.specLst:
if spec.value != "":
filter_spec = spec

if spec.aggregation != "":
attribute = spec.aggregation.upper() + "(" + spec.attribute + ")"
elif spec.binSize > 0:
attribute = "BIN(" + spec.attribute + ")"
else:
attribute = spec.attribute

if spec.channel == "x":
x_channel = spec.attribute.ljust(largest_x_length)
x_channel = attribute.ljust(largest_x_length)
elif spec.channel == "y":
y_channel = spec.attribute
y_channel = attribute
elif spec.channel != "":
additional_channels.append([spec.channel, attribute])
if filter_spec:
y_channel = y_channel.ljust(largest_y_length)
elif largest_filter != 0:
y_channel = y_channel.ljust(largest_y_length + largest_filter + 9)
else:
y_channel = y_channel.ljust(largest_y_length + largest_filter)
if x_channel != "":
x_channel = "x: " + x_channel + ", "
if y_channel != "":
y_channel = "y: " + y_channel
aligned_mark = view.mark.ljust(largest_mark)
str_additional_channels = ""
for channel in additional_channels:
str_additional_channels += ", " + channel[0] + ": " + channel[1]
if filter_spec:
aligned_filter = " -- [" + filter_spec.attribute + filter_spec.filterOp + str(filter_spec.value) + "]"
aligned_filter = aligned_filter.ljust(largest_filter + 8)
views_repr.append(f" <View (x: {x_channel}, y: {y_channel} {aligned_filter}) mark: {aligned_mark}, score: {view.score:.2f} >")
views_repr.append(f" <View ({x_channel}{y_channel}{str_additional_channels} {aligned_filter}) mark: {aligned_mark}, score: {view.score:.2f} >")
else:
views_repr.append(f" <View (x: {x_channel}, y: {y_channel}) mark: {aligned_mark}, score: {view.score:.2f} >")
views_repr.append(f" <View ({x_channel}{y_channel}{str_additional_channels}) mark: {aligned_mark}, score: {view.score:.2f} >")
return '['+',\n'.join(views_repr)[1:]+']'
def map(self,function):
# generalized way of applying a function to each element
Expand Down

0 comments on commit 2d26715

Please sign in to comment.