Commit ff6e8ece82a768f8f067f5cfd4635d32dfa70b20
1 parent
5716be60
Exists in
dev
check captors config page
Showing
4 changed files
with
31 additions
and
27 deletions
Show diff stats
src/dashboard/templates/dashboard/config_weather.html
@@ -16,28 +16,26 @@ | @@ -16,28 +16,26 @@ | ||
16 | <table class="table"> | 16 | <table class="table"> |
17 | <thead> | 17 | <thead> |
18 | <tr> | 18 | <tr> |
19 | - <th>Device type</th> | ||
20 | - <th>Deice id </th> | ||
21 | - <th>value </th> | 19 | + <th>device_name</th> |
20 | + <th>device_type</th> | ||
21 | + <th>serial_number</th> | ||
22 | + <th>valid</th> | ||
23 | + <th>name</th> | ||
24 | + <th>type</th> | ||
22 | <th>Select </th> | 25 | <th>Select </th> |
23 | </tr> | 26 | </tr> |
24 | </thead> | 27 | </thead> |
25 | <tbody> | 28 | <tbody> |
26 | - {% for key1, value1 in weather_config.items %} | ||
27 | - <tr> | ||
28 | - <td>{{key1}}</td> | ||
29 | - <td></td> | ||
30 | - <td></td> | ||
31 | - <td></td | 29 | + {% for line in weather_config%} |
30 | + <tr class="info"> | ||
31 | + <td>{{line.0}}</td> | ||
32 | + <td>{{line.1}}</td> | ||
33 | + <td>{{line.2}}</td> | ||
34 | + <td>{{line.3}}</td> | ||
35 | + <td>{{line.4}}</td> | ||
36 | + <td>{{line.5}}</td> | ||
37 | + <td><input class="form-check-input" name="{{line.4}}" value="{{line.6}}" checked="" type="radio"></td> | ||
32 | </tr> | 38 | </tr> |
33 | - {% for key2, value2 in value1.items %} | ||
34 | - <tr class="info"> | ||
35 | - <td></td> | ||
36 | - <td>{{key2}}</td> | ||
37 | - <td>{{value2}}</td> | ||
38 | - <td><input class="form-check-input" name="{{key1}}" id="{{key1}}/{{key2}}" value="{{key1}}/{{key2}}" checked="" type="radio"></td> | ||
39 | - </tr> | ||
40 | - {% endfor %} | ||
41 | {% endfor %} | 39 | {% endfor %} |
42 | </tbody> | 40 | </tbody> |
43 | </table> | 41 | </table> |
src/dashboard/views.py
@@ -181,7 +181,7 @@ def weather_config(request): | @@ -181,7 +181,7 @@ def weather_config(request): | ||
181 | plc_checker = PlcChecker() | 181 | plc_checker = PlcChecker() |
182 | #plc_checker.scan_sensors() | 182 | #plc_checker.scan_sensors() |
183 | # Return template with sensors list | 183 | # Return template with sensors list |
184 | - return render(request, 'dashboard/config_weather.html', {'weather_config' : plc_checker.captors_conf, 'base_template' : "base.html"}) | 184 | + return render(request, 'dashboard/config_weather.html', {'weather_config' : plc_checker.captors_table, 'base_template' : "base.html"}) |
185 | except Config.DoesNotExist: | 185 | except Config.DoesNotExist: |
186 | return render(request, 'dashboard/config_weather.html', {'weather_info' : None}) | 186 | return render(request, 'dashboard/config_weather.html', {'weather_info' : None}) |
187 | 187 |
src/monitoring/plc_checker.py
@@ -13,8 +13,6 @@ class PlcChecker(object): | @@ -13,8 +13,6 @@ class PlcChecker(object): | ||
13 | self.struct = None | 13 | self.struct = None |
14 | self.path_list = None | 14 | self.path_list = None |
15 | # self.plc_global = copy.copy(self.struct["devices"]) | 15 | # self.plc_global = copy.copy(self.struct["devices"]) |
16 | - # | ||
17 | - self.load_config() | ||
18 | self.device_name = None | 16 | self.device_name = None |
19 | self.device_type = None | 17 | self.device_type = None |
20 | self.serial_number = None | 18 | self.serial_number = None |
@@ -33,11 +31,12 @@ class PlcChecker(object): | @@ -33,11 +31,12 @@ class PlcChecker(object): | ||
33 | ] | 31 | ] |
34 | self.captors_conf = {} | 32 | self.captors_conf = {} |
35 | self.captors_table = [] | 33 | self.captors_table = [] |
34 | + self.load_config() | ||
36 | 35 | ||
37 | def load_config(self): | 36 | def load_config(self): |
38 | try: | 37 | try: |
39 | colibri_json = open("./monitoring/plc_config.json") | 38 | colibri_json = open("./monitoring/plc_config.json") |
40 | - self.struct = json.load(colibri_json) | 39 | + self.captors_table = json.load(colibri_json) |
41 | logger.info("Loaded : plc_config.json") | 40 | logger.info("Loaded : plc_config.json") |
42 | colibri_json.close | 41 | colibri_json.close |
43 | except: | 42 | except: |
@@ -46,7 +45,7 @@ class PlcChecker(object): | @@ -46,7 +45,7 @@ class PlcChecker(object): | ||
46 | def save_config(self): | 45 | def save_config(self): |
47 | #try: | 46 | #try: |
48 | _file = open("./monitoring/plc_config.json" , 'w') | 47 | _file = open("./monitoring/plc_config.json" , 'w') |
49 | - _file.write(json.dumps(self.captors_conf)) | 48 | + _file.write(json.dumps(self.captors_table)) |
50 | _file.close() | 49 | _file.close() |
51 | logger.info("Saved : plc_config.json") | 50 | logger.info("Saved : plc_config.json") |
52 | #except: | 51 | #except: |
@@ -58,17 +57,18 @@ class PlcChecker(object): | @@ -58,17 +57,18 @@ class PlcChecker(object): | ||
58 | self.struct = struct[0] | 57 | self.struct = struct[0] |
59 | else: | 58 | else: |
60 | self.struct = struct | 59 | self.struct = struct |
61 | - if self.struct["entity_name"] == "PLC_STATUS": | ||
62 | - if not self.same_origin(): | 60 | + if not self.same_origin(): |
63 | self.scan_sensors() | 61 | self.scan_sensors() |
64 | self.save_config() | 62 | self.save_config() |
65 | - else: | ||
66 | - logger.info("No PLC_STATUS") | ||
67 | 63 | ||
68 | def same_origin(self): | 64 | def same_origin(self): |
65 | + # check new origin | ||
69 | if self.struct["from"] == self.plc_from and self.struct["site"] == self.plc_site: | 66 | if self.struct["from"] == self.plc_from and self.struct["site"] == self.plc_site: |
70 | return True | 67 | return True |
71 | else: | 68 | else: |
69 | + # update origin | ||
70 | + self.plc_from = self.struct["from"] | ||
71 | + self.plc_site = self.struct["site"] | ||
72 | return False | 72 | return False |
73 | 73 | ||
74 | def get_key(self, struct, key): | 74 | def get_key(self, struct, key): |
@@ -80,15 +80,19 @@ class PlcChecker(object): | @@ -80,15 +80,19 @@ class PlcChecker(object): | ||
80 | 80 | ||
81 | def scan_sensors(self): | 81 | def scan_sensors(self): |
82 | # return captors table from struct | 82 | # return captors table from struct |
83 | + self.captors_table = [] | ||
83 | try: | 84 | try: |
84 | logger.debug(self.struct["date"]) | 85 | logger.debug(self.struct["date"]) |
85 | except Exception as e: | 86 | except Exception as e: |
86 | logger.debug("No date") | 87 | logger.debug("No date") |
88 | + ind1 = 0 | ||
87 | for device in self.struct["devices"]: | 89 | for device in self.struct["devices"]: |
88 | self.device_name = self.get_key(device, "device_name") | 90 | self.device_name = self.get_key(device, "device_name") |
89 | self.device_type = self.get_key(device, "device_type") | 91 | self.device_type = self.get_key(device, "device_type") |
90 | self.serial_number = self.get_key(device, "serial_number") | 92 | self.serial_number = self.get_key(device, "serial_number") |
91 | self.valid = self.get_key(device, "valid") | 93 | self.valid = self.get_key(device, "valid") |
94 | + ind1 += 1 | ||
95 | + ind2 = 0 | ||
92 | for device_values in device["device_values"]: | 96 | for device_values in device["device_values"]: |
93 | captor = [] | 97 | captor = [] |
94 | captor.append(self.device_name) | 98 | captor.append(self.device_name) |
@@ -97,7 +101,9 @@ class PlcChecker(object): | @@ -97,7 +101,9 @@ class PlcChecker(object): | ||
97 | captor.append(self.valid) | 101 | captor.append(self.valid) |
98 | captor.append(self.get_key(device_values, "name")) | 102 | captor.append(self.get_key(device_values, "name")) |
99 | captor.append(self.get_key(device_values, "type")) | 103 | captor.append(self.get_key(device_values, "type")) |
104 | + captor.append(str(ind1) + "_" + str(ind2)) | ||
100 | self.captors_table.append(captor) | 105 | self.captors_table.append(captor) |
106 | + ind2 += 1 | ||
101 | 107 | ||
102 | 108 | ||
103 | # deprecated find captor list in struct | 109 | # deprecated find captor list in struct |
src/monitoring/tasks.py
@@ -259,7 +259,7 @@ class Monitoring(Task): | @@ -259,7 +259,7 @@ class Monitoring(Task): | ||
259 | 259 | ||
260 | def parseNewStatus(self,status_plc ): | 260 | def parseNewStatus(self,status_plc ): |
261 | # """ PM 20181009 parse new status for config | 261 | # """ PM 20181009 parse new status for config |
262 | - if status_plc[:7] != "NOT_SET": | 262 | + if status_plc.find('PLC_STATUS') >= 0: |
263 | self.plc_checker.chk_config(status_plc) | 263 | self.plc_checker.chk_config(status_plc) |
264 | 264 | ||
265 | ''' | 265 | ''' |