Commit a47fb4c9 authored by Elisabetta Giani's avatar Elisabetta Giani
Browse files

k8s-configuration: add grid and test number

parent 86597dc7
Loading
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ class attributePlot:
    def __init__(self, plotLength = 100, device='mid_csp/elt/subarray_01'):
        self.plotMaxLength = plotLength
        self.data = collections.deque([0] * plotLength, maxlen=plotLength)
        self.test_number = 0
        self.previous_test_num = 0
        self.plotTimer = 0
        self.previousTimer = 0
        self.proxy = 0
@@ -20,6 +22,7 @@ class attributePlot:
        self.anim = None
        try:
            self.proxy = tango.DeviceProxy("mid_csp/elt/subarray_01")
            self.proxy.testNumber = 0
            print('Connected to device {}'.format(device))
        except:
            print("Failed to connect to device {}".format(device) )
@@ -29,6 +32,9 @@ class attributePlot:
            self.proxy.subscribe_event("obsState", tango.EventType.CHANGE_EVENT,
                                      self.attributes_change_evt_cb,
                                      stateless=False)
            self.proxy.subscribe_event("testNumber", tango.EventType.CHANGE_EVENT,
                                      self.attributes_change_evt_cb,
                                      stateless=False)

    def getAttributeData(self, frame, lines, lineValueText, lineLabel, timeText):
        currentTimer = time.perf_counter()
@@ -36,9 +42,15 @@ class attributePlot:
        self.previousTimer = currentTimer
        #timeText.set_text('Plot Interval = ' + str(self.plotTimer) + 'ms')
        self.data.append(self.obs_state)    # we get the latest data point and append it to our array
        #plt.annotate(test_label, # this is the text
        #         (x, 5), # this is the point to label
        #         textcoords="offset points", # how to position the text
        #         xytext=(0,10), # distance from text to points (x,y)
        #         ha='center')
        lines.set_data(range(self.plotMaxLength), self.data)
        lineValueText.set_text('[' + lineLabel + '] = ' + str(self.obs_state))

        #lineValueText.set_text('[' + lineLabel + '] = ' + str(self.obs_state))
        if self.test_number != self.previous_test_num:
            lineValueText.set_text('[Test number] = ' + str(self.test_number))
    def attributes_change_evt_cb(self, evt):
        dev_name = evt.device.dev_name()
        if not evt.err:
@@ -47,6 +59,9 @@ class attributePlot:
                    self.obs_state = evt.attr_value.value
                    self.data.append(self.obs_state)    # we get the latest data point and append it to our array
                    self.data.append(self.obs_state)    # we get the latest data point and append it to our array
                if evt.attr_value.name.lower() == "testnumber": 
                    self.previous_test_num = self.test_number
                    self.test_number = evt.attr_value.value
                    #print("Received event on {}/{}: {}".format(dev_name, 
                    #                                      str(evt.attr_value.name),
                    #                                      str(evt.attr_value.value)))
@@ -67,18 +82,20 @@ class attributePlot:
            exit()

def main():
    maxPlotLength = 100
    maxPlotLength = 200
    s = attributePlot(maxPlotLength, 'mid_csp/elt/subarray_01')   # initializes all required variables
    s.readAttributeStart()                                               # starts background thread
 
    # plotting starts below
    pltInterval = 200    # Period at which the plot animation updates [ms]
    pltInterval = 100    # Period at which the plot animation updates [ms]
    xmin = 0
    xmax = maxPlotLength
    ymin = -1 
    ymax = 12
    fig = plt.figure("MID CSP Subarray ADR-8 transitions")
    fig.set_size_inches(18.5, 8.5)
    ax = plt.axes(xlim=(xmin, xmax), ylim=(ymin, ymax ))
    plt.grid()
    ax.set_title('obsState real-time graph')
    ax.set_xlabel("time")
    ax.set_ylabel("obsState")