-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (59 loc) · 2.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
''' @author: klimyflorez '''
from flask import Flask, request, jsonify
from sqlalchemy import true
from helper.isMutant import IsMutant
from flask_sqlalchemy import SQLAlchemy
from models.Stats import Stast
app = Flask(__name__)
app.config['SECRET_KEY'] = "7Nn37F]wXXR4zoLJl\[Y"
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///Mutants.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
@app.route('/mutant/', methods=['POST'])
def isMutant():
try:
data = request.get_json()
id = ''.join(data['dna'])
#data = Stats.query.filter_by(_id=id).first()
result = IsMutant(data['dna'])
#print(result)
if result.isMutant:
stat = Stast(id,result.isMutant)
db.session.add(stat)
db.session.commit()
return {
'id':id,
'isMutant': result.isMutant,
'result': '{0:2.2f}%'.format((result.count_mutant_dna * 100) / result.size),
'message': "Magneto quiere saber tu ubicación",
}, 200
else:
stat = Stast(id,result.isMutant)
db.session.add(stat)
db.session.commit()
if result.error.get('error'):
return result.error, 406
else:
return {}, 403
except Exception as err:
print(err)
return {'Error in mutation request': 'err'}
@app.route('/stats/', methods=['GET'])
def getStats():
isMutant = db.session.query(Stast).filter(Stast.is_mutant == True).count()
if isMutant > 0:
isHuman = db.session.query(Stast).filter(Stast.is_mutant == False).count()
ratio = '{0:2.2f}%'.format( (isMutant * 100) / (isMutant+isHuman))
return {
'count_mutant_dna': isMutant,
'count_human_dna': isHuman,
'ratio': ratio,
}
else:
return {
'Error': True,
'Message': 'First enter the DNA sequence'
}
if __name__ == '__main__':
db.create_all()
app.run(debug=True)