Skip to content

Commit

Permalink
Fixed an issue where visualization types were not correctly read from…
Browse files Browse the repository at this point in the history
… the configs.
  • Loading branch information
daboth committed Oct 14, 2014
1 parent 965f4d6 commit 4ef8f89
Show file tree
Hide file tree
Showing 14 changed files with 1,410 additions and 1,311 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ coverage.xml
# Sphinx documentation
docs/_build/

# Misc
.idea/
48 changes: 48 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# file GENERATED by distutils, do NOT edit
LICENSE
MANIFEST.in
README.txt
setup.py
pive/__init__.py
pive/consistenceprofiler.py
pive/datavalidater.py
pive/environment.py
pive/inputmanager.py
pive/inputreader.py
pive/visualizationmapper.py
pive/visualization/__init__.py
pive/visualization/barchart.py
pive/visualization/basevisualization.py
pive/visualization/bubblechart.py
pive/visualization/chordchart.py
pive/visualization/colorthemes.py
pive/visualization/customscalesvisualization.py
pive/visualization/defaults.py
pive/visualization/linechart.py
pive/visualization/piechart.py
pive/visualization/scatterchart.py
pive/visualization/viewportvisualization.py
pive/visualization/config/barChart.json
pive/visualization/config/bubbleChart.json
pive/visualization/config/chordChart.json
pive/visualization/config/lineChart.json
pive/visualization/config/pieChart.json
pive/visualization/config/scatterChart.json
pive/visualization/templates/barchart/css.jinja
pive/visualization/templates/barchart/html.jinja
pive/visualization/templates/barchart/js.jinja
pive/visualization/templates/bubblechart/css.jinja
pive/visualization/templates/bubblechart/html.jinja
pive/visualization/templates/bubblechart/js.jinja
pive/visualization/templates/chordchart/css.jinja
pive/visualization/templates/chordchart/html.jinja
pive/visualization/templates/chordchart/js.jinja
pive/visualization/templates/linechart/css.jinja
pive/visualization/templates/linechart/html.jinja
pive/visualization/templates/linechart/js.jinja
pive/visualization/templates/piechart/css.jinja
pive/visualization/templates/piechart/html.jinja
pive/visualization/templates/piechart/js.jinja
pive/visualization/templates/scatterchart/css.jinja
pive/visualization/templates/scatterchart/html.jinja
pive/visualization/templates/scatterchart/js.jinja
57 changes: 34 additions & 23 deletions pive/consistenceprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,42 @@
# POSSIBILITY OF SUCH DAMAGE.

def getDatapointTypes(datapoint):
"""Determines the datas visualization-types of a given datapoint.
"""Determines the datas visualization-types of a given datapoint.
Valid visualization-types are 'number', 'string' and 'time'"""
types = []
for key in list(datapoint.keys()):
types = []
for key in list(datapoint.keys()):

item = datapoint[key]
if str(key).endswith("date") or str(key).endswith("time"):
types.append("time")
item = datapoint[key]
if str(key).endswith("date") or str(key).endswith("time"):
types.append("time")

elif isfloat(item) or isint(item):
types.append("number")
elif isfloat(item) or isint(item):
types.append("number")

# Python 3 string determination.
elif isinstance(item, (str)):
types.append("string")
# Python 2.7 workaround to determine strings.
# Basestring was deprecated in Python 3.
else:
try:
if isinstance(item, basestring):
types.append("string")
except TypeError:
pass

return types

elif type(item) == (type(u'string') or type('string')):
types.append("string")
else:
types.append(type(item))
return types

def isfloat(value):
try:
number = float(value)
number = float(value)
except ValueError:
return False
else:
return True


def isint(value):
try:
num_a = float(value)
Expand All @@ -59,15 +69,16 @@ def isint(value):
else:
return num_a == num_b


def checkConsistency(input_data):
"""Checks the consistency of the dataset. Each item
"""Checks the consistency of the dataset. Each item
must contain the exact datapoint-type as the other."""
if input_data:
current = getDatapointTypes(input_data[0])
for item in input_data[1:]:
previous = current
current = getDatapointTypes(item)
if previous != current:
return False
return True
if input_data:
current = getDatapointTypes(input_data[0])
for item in input_data[1:]:
previous = current
current = getDatapointTypes(item)
if previous != current:
return False
return True

7 changes: 2 additions & 5 deletions pive/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ def load(self, source):
self.__modules = self.importSuitableVisualizations(self.__suitables)
self.__data = inputdata
self.__hasDates = self.__inputmanager.hasDatePoints()
self.__datakeys = list(self.__data[0].keys())
# Converting the datakeys into strings.
self.__datakeys = [str(i) for i in list(self.__data[0].keys())]
return self.__suitables

# Import all visualization modules.
def importSuitableVisualizations(self, suitables):
"""Dynamically import all suited visualization files."""
print ("SYSTEMPATH")
print (sys.path[0])

mods = []
for item in suitables:
Expand All @@ -85,8 +84,6 @@ def importSuitableVisualizations(self, suitables):
for item in mods:
modules.append(importlib.import_module(item, package=default.module_path))

print (modules)

return modules

# Choose a chart to start modifying or render it.
Expand Down
6 changes: 4 additions & 2 deletions pive/visualization/barchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class Chart(bv.BaseVisualization, vv.ViewportVisualization):
def __init__(self,
dataset,
template_url,
template_name,
width=default.width,
height=default.height,
padding=default.padding,
Expand All @@ -48,7 +48,8 @@ def __init__(self,
# Metadata
self.__title = 'barchart'
self.__dataset = dataset
self.__template_url = template_url
realpath = os.path.dirname(os.path.realpath(__file__))
self.__template_url = '%s%s%s' % (realpath, default.template_path, template_name)
self.__datakeys = []

# Visualization properties.
Expand Down Expand Up @@ -174,6 +175,7 @@ def writeFile(self, output, destination_url, filename):
print ('Writing: %s' % (dest_file))

for line in output:
#f.write(line.encode('utf-8'))
f.write(line)

f.close()
Expand Down
Loading

0 comments on commit 4ef8f89

Please sign in to comment.