Skip to content

Commit

Permalink
Quick example graph
Browse files Browse the repository at this point in the history
  • Loading branch information
debug committed Jan 1, 2018
1 parent 18046ac commit a41c460
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*.pyc
*~
*.swp

constants.py

tests/graph.py
Empty file added graphs/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions graphs/bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from reporter_api.reports import Mode, Series
import pygal
series = Series(Mode.LOCAL)

config = pygal.Config()

happyValues = []
dates = []

for report in series.reportObjs:
for snapshot in report.snapshots:
if unicode("How happy are you?") in snapshot.responses.keys():
happyValues.append(int(snapshot.responses[unicode("How happy are you?")]))


config.style = pygal.style.DarkStyle
bar_chart = pygal.Bar(config)
bar_chart.title = "Happiness by time."
bar_chart.x_labels = dates
bar_chart.add('Happiness', happyValues)

bar_chart.render_to_file("/Users/Dom/Desktop/moo.svg")
16 changes: 7 additions & 9 deletions reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def log(msg):
print("reporter_api :: {0}".format(msg))


class Reports(object):
class Series(object):

def __init__(self, mode=None):
if mode == None:
Expand All @@ -48,6 +48,7 @@ def __fetchLocal(self):
home = os.path.expanduser("~")
dropboxPath = os.path.join(str(home), "Dropbox", str(APP_PATH))
files = glob.glob("{path}/*.json".format(path=dropboxPath))
files.sort()

if(DEBUG):
start = time.time()
Expand Down Expand Up @@ -100,7 +101,9 @@ def latestReport(self):
""" Returns latest Report object """

if self.__mode == 0:
return Report(self.__listFolderObj.entries[-1])
md, res = self.__db.files_download(self.__listFolderObj.entries[-1].path_display)
data = res.content
return Report(json.loads(data))


class Report(object):
Expand All @@ -116,11 +119,6 @@ def __setup(self):
snapshotObj = Snapshot(snapshot, parent=self)
self.__snapshots.append(snapshotObj)

#healthInfo = Fetcher.getHealthKit(self.date)
#if healthInfo != None:
# for snapshot in self.__snapshots:
# snapshot.weight = healthInfo['weight']

@property
def snapshots(self):
return self.__snapshots
Expand Down Expand Up @@ -323,5 +321,5 @@ def report(self):
return self.__parent

if __name__ == "__main__":
reports = Reports(Mode.DROPBOX)
reports.latestReport
series = Series(Mode.DROPBOX)
series.latestReport

0 comments on commit a41c460

Please sign in to comment.