Adds temperature history plotting
This commit is contained in:
@ -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()
|
||||
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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):
|
||||
|
||||
Reference in New Issue
Block a user