diff --git a/POCloud/Direct/poc.py b/POCloud/Direct/poc.py index a4fe549..b452eb7 100644 --- a/POCloud/Direct/poc.py +++ b/POCloud/Direct/poc.py @@ -27,38 +27,38 @@ import calendar class Channel(): def __init__(self, ch_name, chg_threshold, max_age): self.channel = ch_name - self.chg_treshold = chg_treshold, + self.chg_threshold = chg_threshold self.max_age = max_age self.last_sent = 0 self.value = float('inf') def check(self, val, force=False): - if (abs(self.value - val) > self.chg_treshold) or ((time.time() - self.last_sent) > self.max_age) or force: + if (abs(self.value - val) > self.chg_threshold) or ((time.time() - self.last_sent) > self.max_age) or force: return True return False card_data_channels = { - 'Downhole Adjusted Gross Stroke': {channel:'downhole_adjusted_gross_stroke', chg_threshold: 5.0, max_age: 3600}, - 'Downhole Fluid Load': {channel:'downhole_fluid_load', chg_threshold: 100.0, max_age: 3600}, - 'Downhole Gross Stroke': {channel:'downhole_gross_stroke', chg_threshold: 1.0, max_age: 3600}, - 'Downhole Max Position': {channel:'downhole_max_position', chg_threshold: 1.0, max_age: 3600}, - 'Downhole Min Position': {channel:'downhole_min_position', chg_threshold: 1.0, max_age: 3600}, - 'Downhole Net Stroke': {channel:'downhole_net_stroke', chg_threshold: 1.0, max_age: 3600}, - 'Fill Percentage': {channel:'fillage_percent', chg_threshold: 1.0, max_age: 3600}, - 'Fluid Level': {channel:'fluid_above_pump', chg_threshold: 10.0, max_age: 3600}, - 'Fluid Gradient': {channel:'fluid_gradient', chg_threshold: 1.0, max_age: 3600}, - 'Polished Rod HP': {channel:'polished_rod_hp', chg_threshold: 0.5, max_age: 3600}, - 'Pump HP': {channel:'pump_hp', chg_threshold: 0.5, max_age: 3600}, - 'Pump Intake Pressure': {channel:'pump_intake_pressure', chg_threshold: 10.0, max_age: 3600}, - 'Stroke Production': {channel:'stroke_production', chg_threshold: 0.005, max_age: 3600}, - 'Surface Max Load': {channel:'surface_max_load', chg_threshold: 100.0, max_age: 3600}, - 'Surface Min Load': {channel:'surface_min_load', chg_threshold: 100.0, max_age: 3600}, - 'Surface Stroke Length': {channel:'surface_stroke_length', chg_threshold: 1.0, max_age: 3600}, - 'Tubing Movement': {channel:'tubing_movement', chg_threshold: 1.0, max_age: 3600}, - 'SPM': {channel:'SPM', chg_threshold: 0.5, max_age: 3600}, - 'dt': {channel:'dt', chg_threshold: 0.01, max_age: 3600}, - 'Stuffing Box Friction': {channel:'stuffing_box_friction', chg_threshold: 1.0, max_age: 3600}, - 'Tubing Head Pressure': {channel:'tubing_head_pressure', chg_threshold: 5.0, max_age: 3600} + 'Downhole Adjusted Gross Stroke': Channel('downhole_adjusted_gross_stroke', 5.0, 3600), + 'Downhole Fluid Load': Channel('downhole_fluid_load', 100.0, 3600), + 'Downhole Gross Stroke': Channel('downhole_gross_stroke', 1.0, 3600), + 'Downhole Max Position': Channel('downhole_max_position', 1.0, 3600), + 'Downhole Min Position': Channel('downhole_min_position', 1.0, 3600), + 'Downhole Net Stroke': Channel('downhole_net_stroke', 1.0, 3600), + 'Fill Percentage': Channel('fillage_percent', 1.0, 3600), + 'Fluid Level': Channel('fluid_above_pump', 10.0, 3600), + 'Fluid Gradient': Channel('fluid_gradient', 1.0, 7200), + 'Polished Rod HP': Channel('polished_rod_hp', 0.5, 3600), + 'Pump HP': Channel('pump_hp', 0.5, 3600), + 'Pump Intake Pressure': Channel('pump_intake_pressure', 10.0, 3600), + 'Stroke Production': Channel('stroke_production', 0.005, 3600), + 'Surface Max Load': Channel('surface_max_load', 100.0, 3600), + 'Surface Min Load': Channel('surface_min_load', 100.0, 3600), + 'Surface Stroke Length': Channel('surface_stroke_length', 1.0, 3600), + 'Tubing Movement': Channel('tubing_movement', 1.0, 3600), + 'SPM': Channel('SPM', 0.5, 3600), + 'dt': Channel('dt', 0.01, 7200), + 'Stuffing Box Friction': Channel('stuffing_box_friction', 1.0, 7200), + 'Tubing Head Pressure': Channel('tubing_head_pressure', 5.0, 7200) } @@ -115,7 +115,7 @@ class start(threading.Thread, deviceBase): self.forceSend = True self.version = "3" self.device_address = "https://192.168.1.30:3000" - self.cardLoopTimer = 60 + self.cardLoopTimer = 600 self.finished = threading.Event() threading.Thread.start(self) self.last_status = "" @@ -171,6 +171,7 @@ class start(threading.Thread, deviceBase): self.sendtodb('dc', down_string, card_date) def run(self): + global card_data_channels self.runLoopStatus = "" while True: try: @@ -190,9 +191,15 @@ class start(threading.Thread, deviceBase): # self.channelCheck(go_channels[go], self.forceSend) - # runLoopStatus = "Stroke Parameter Data" - # for ch in channels: - # self.channelCheck(channels[ch], self.forceSend) + runLoopStatus = "Stroke Parameter Data" + l_req = requests.get('{}/tag_val/latest'.format(self.device_address), verify=False) + latest_values = json.loads(l_req.text) + for i in range(0, len(latest_values)): + if latest_values[i]['name'] in card_data_channels: + if card_data_channels[latest_values[i]['name']].check(float(latest_values[i]['val'])): + self.sendtodb(card_data_channels[latest_values[i]['name']].channel, float(latest_values[i]['val']), 0) + card_data_channels[latest_values[i]['name']].value = float(latest_values[i]['val']) + card_data_channels[latest_values[i]['name']].last_sent = time.time() runLoopStatus = "Reading Cards" c_req = requests.get('{}/card/latest'.format(self.device_address), verify=False)