From 89d26c1e8a4278ab960b15141d264770a31ac484 Mon Sep 17 00:00:00 2001 From: LSaldyt Date: Fri, 17 Nov 2017 11:17:15 -0700 Subject: [PATCH 1/2] Adds temperature history plotting --- copycat/copycat.py | 4 ++-- copycat/gui/gui.py | 19 ++++++++++++------- copycat/gui/plot.py | 9 ++++++++- copycat/temperature.py | 2 ++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/copycat/copycat.py b/copycat/copycat.py index 8112f61..30c0e6f 100644 --- a/copycat/copycat.py +++ b/copycat/copycat.py @@ -62,8 +62,8 @@ class Copycat(object): def mainLoop(self): currentTime = self.coderack.codeletsRun self.temperature.tryUnclamp(currentTime) - # Every 15 codelets, we update the workspace. - if currentTime >= self.lastUpdate + 15: + # Every 5 codelets, we update the workspace. + if currentTime >= self.lastUpdate + 5: self.update_workspace(currentTime) self.step() diff --git a/copycat/gui/gui.py b/copycat/gui/gui.py index 2cd42cc..7c603df 100644 --- a/copycat/gui/gui.py +++ b/copycat/gui/gui.py @@ -16,7 +16,7 @@ from .primary import Primary from .list import List from .style import configure_style -from .plot import plot_imbedded +from .plot import plot_answers, plot_temp plt.style.use('dark_background') @@ -40,10 +40,13 @@ class MainApplication(GridFrame): self.add(self.codeletList, 1, 1) self.objectList = List(self, columns) - self.add(self.objectList, 2, 1) + self.add(self.objectList, 2, 1, xspan=2) + + self.graph1 = Plot(self, 'Temperature history') + self.add(self.graph1, 2, 0) self.graph2 = Plot(self, 'Answer Distribution') - self.add(self.graph2, 2, 0) + self.add(self.graph2, 3, 0) def update(self, copycat): self.primary.update(copycat) @@ -57,6 +60,11 @@ class MainApplication(GridFrame): self.codeletList.update(codelets, key=lambda c:c.urgency, formatter= lambda s : '{}: {}'.format(s.name, round(s.urgency, 2))) get_descriptors = lambda s : ', '.join('({}={})'.format(d.descriptionType.name, d.descriptor.name) for d in s.descriptions) self.objectList.update(objects, formatter=lambda s : '{}: {}'.format(s, get_descriptors(s))) + + def modifier(status): + with plt.style.context(('dark_background')): + plot_temp(copycat.temperature, status) + self.graph1.status.modifier = modifier def reset_with_strings(self, initial, modified, target): self.primary.reset_with_strings(initial, modified, target) @@ -69,15 +77,12 @@ class GUI(object): tk.Grid.columnconfigure(self.root, 0, weight=1) self.app = MainApplication(self.root) self.app.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W) - configure_style(ttk.Style()) def add_answers(self, answers): def modifier(status): - print('Here') - print(answers) with plt.style.context(('dark_background')): - plot_imbedded(answers, status) + plot_answers(answers, status) self.app.graph2.status.modifier = modifier def refresh(self): diff --git a/copycat/gui/plot.py b/copycat/gui/plot.py index 8583ff7..54d900b 100644 --- a/copycat/gui/plot.py +++ b/copycat/gui/plot.py @@ -2,7 +2,14 @@ import matplotlib.pyplot as plt; plt.rcdefaults() import numpy as np import matplotlib.pyplot as plt -def plot_imbedded(answers, status): +def plot_temp(temperature, status): + status.subplot.clear() + status.subplot.plot(temperature.history) + status.subplot.set_ylabel('Temperature') + status.subplot.set_xlabel('Time') + status.subplot.set_title('Temperature History') + +def plot_answers(answers, status): answers = sorted(answers.items(), key=lambda kv : kv[1]['count']) objects = [t[0] for t in answers] yvalues = [t[1]['count'] for t in answers] diff --git a/copycat/temperature.py b/copycat/temperature.py index f00e479..37a5d6f 100644 --- a/copycat/temperature.py +++ b/copycat/temperature.py @@ -6,6 +6,7 @@ class Temperature(object): self.reset() def reset(self): + self.history = [100.0] self.actual_value = 100.0 self.last_unclamped_value = 100.0 self.clamped = True @@ -16,6 +17,7 @@ class Temperature(object): if self.clamped: self.actual_value = 100.0 else: + self.history.append(value) self.actual_value = value def clampUntil(self, when): From ff152c63984283c38fd954bde1519352b5855516 Mon Sep 17 00:00:00 2001 From: LSaldyt Date: Sat, 18 Nov 2017 17:32:37 -0700 Subject: [PATCH 2/2] WIP --- copycat/gui/workspacecanvas.py | 1 + 1 file changed, 1 insertion(+) diff --git a/copycat/gui/workspacecanvas.py b/copycat/gui/workspacecanvas.py index 843e0b0..62ccb90 100644 --- a/copycat/gui/workspacecanvas.py +++ b/copycat/gui/workspacecanvas.py @@ -21,6 +21,7 @@ class WorkspaceCanvas(GridFrame): self.changed = False self.canvas = tk.Canvas(self, background='black') + #self.canvas['width'] = 1600 self.add(self.canvas, 0, 0) GridFrame.configure(self)