Skip to content

Instantly share code, notes, and snippets.

@aipi
Created May 15, 2019 12:15
Show Gist options
  • Save aipi/5960b6ef5f2010c9bf802dc6ebbdd866 to your computer and use it in GitHub Desktop.
Save aipi/5960b6ef5f2010c9bf802dc6ebbdd866 to your computer and use it in GitHub Desktop.
import requests
from requests.auth import HTTPBasicAuth
import json
import math
from enum import Enum
from datetime import datetime
class Mnemonic(Enum):
TORQUE = 'TORQUE_AVG'
SURF_RPM = 'SURF_RPM'
class BaseProcessData:
host = 'https://genesis.intelie.com/'
def decoder(self, result):
raw_text_data = result.text.split('\n')
threated_text_data = list(filter(None, raw_text_data))
return [json.loads(data) for data in threated_text_data]
def get_request_data(self, path):
return requests.get(
'{}{}'.format(self.host, path),
auth=HTTPBasicAuth('igor', 'Genesis@2017')
)
class RotationAndTorqueTime(BaseProcessData):
path = ''
def __init__(self):
self.result = self.get_request_data(self.path)
self.torque = 0
self.surf = 0
self.time = None
self.last_time = None
def between_time(self, data):
timestamp_to_datetime = datetime.fromtimestamp(data['timestamp'])
max_time = timestamp_to_datetime + datetime.timedelta(minutes=+5)
if timestamp_to_datetime > self.last_time \
and timestamp_to_datetime < max_time:
self.last_time = timestamp_to_datetime
return data
def get_dataset(self):
return filter(self.between_time, self.result)
def tanh_surf(self, value):
self.torque += int(math.tanh(value))
def tanh_torque(self, value):
self.surf += int(math.tanh(value))
def calculate_tanh(self):
dataset = self.get_dataset()
for data in dataset:
if data['mnemonic'] == Mnemonic.TORQUE.value and \
(data.value >= 0 or data.value <= 80):
self.tanh_torque(data.value)
elif data['mnemonic'] == Mnemonic.SURF_RPM.value and \
(data.value >= 0 or data.value <= 80):
self.tanh_torque(data.value)
def execute(self):
if self.surf == 0 and self.torque == 0:
self.calculate_tanh()
if
'''for data in data_set.json():
torque = data[0].value
surf = data[1].value
if not surf > 80 or torque > 11000:
tang_torque += tangh(torque)
tang_surf += tangh(torque)
if not (surf == 0 and torque == 0):
break
while(duration >= 90)
sleep(5000)
duration = 0
return
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment