matiasmenares/Nissboard

View on GitHub
dashboard/api/settings/channels/obd.py

Summary

Maintainability
D
2 days
Test Coverage
Similar blocks of code found in 2 locations. Consider refactoring.
from flask_restful import Resource
Similar blocks of code found in 2 locations. Consider refactoring.
from flask import request, jsonify
Similar blocks of code found in 2 locations. Consider refactoring.
from model.models import db, Obd, ObdSchema , ObdInput, ObdInputSchema, ChannelInput
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
class OBDChannel(Resource):
Similar blocks of code found in 2 locations. Consider refactoring.
Similar blocks of code found in 2 locations. Consider refactoring.
def get(self):
Similar blocks of code found in 2 locations. Consider refactoring.
obd = Obd.query.all()
Similar blocks of code found in 2 locations. Consider refactoring.
obd_schema = ObdSchema(many=True)
Similar blocks of code found in 2 locations. Consider refactoring.
return {'obd': obd_schema.dump(obd)}
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
def post(self):
Similar blocks of code found in 2 locations. Consider refactoring.
try:
Similar blocks of code found in 2 locations. Consider refactoring.
params = request.json['obd']
Similar blocks of code found in 2 locations. Consider refactoring.
obd_input = ObdInput(name=params['name'], obd=Obd.query.get(params['obd_id']))
Similar blocks of code found in 2 locations. Consider refactoring.
channel_input = ChannelInput(obd_input=obd_input)
Similar blocks of code found in 2 locations. Consider refactoring.
db.session.add(obd_input)
Similar blocks of code found in 2 locations. Consider refactoring.
db.session.add(channel_input)
Similar blocks of code found in 2 locations. Consider refactoring.
db.session.commit()
Similar blocks of code found in 2 locations. Consider refactoring.
return {'response': True}
Similar blocks of code found in 2 locations. Consider refactoring.
except:
Similar blocks of code found in 2 locations. Consider refactoring.
return {'response': False}, 500
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
def patch(self):
Similar blocks of code found in 2 locations. Consider refactoring.
try:
Similar blocks of code found in 2 locations. Consider refactoring.
analog = request.json['analog']
Similar blocks of code found in 2 locations. Consider refactoring.
cursor = self.database.con.cursor()
Similar blocks of code found in 2 locations. Consider refactoring.
input = 1 if analog["input"] == "Voltage" else 0
Similar blocks of code found in 2 locations. Consider refactoring.
cursor.execute("UPDATE analog_channels SET name = ?, pin = ?, voltage_resistance = ? WHERE id = ? ", (analog["name"], analog["pin"], input, str(analog["id"])))
Similar blocks of code found in 2 locations. Consider refactoring.
self.database.con.commit()
Similar blocks of code found in 2 locations. Consider refactoring.
return {'response': True}
Similar blocks of code found in 2 locations. Consider refactoring.
except:
Similar blocks of code found in 2 locations. Consider refactoring.
return {'response': False}