Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"
gunicorn = "*"
pymongo = "*"
opencv-python = "*"
sympy = "*"
matplotlib = "*"
numpy = "*"
pillow = "*"

[dev-packages]

[requires]
python_version = "3.6"
330 changes: 330 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn server:app
3 changes: 2 additions & 1 deletion controllers/controller_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

def insert_graph(collection, function_name) -> None:
try:
url_image = './static/functions_images/' + function_name + '.png'
url_image = 'static/functions_images/' + function_name + '.png'
collection.insert({
'function': function_name,
'image': url_image
})
except Exception as e:
print("En controller_database.py")
print(e)


Expand Down
3 changes: 3 additions & 0 deletions controllers/controller_graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy as np
import sympy as sym
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

from PIL import Image
Expand Down Expand Up @@ -36,6 +38,7 @@ def create_graph(self):
self.__convert_to_transparent_image(self.url_images, function_name)
success = True
except Exception as e:
print("En controller_graph.py")
print(e)

return success, function_name
Expand Down
22 changes: 17 additions & 5 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@
from pymongo import MongoClient
from controllers.controller_graph import Graph
import controllers.controller_database as controller_db
import os
import base64
from json import dumps

app = Flask(__name__)
#
# mongodb://<dbuser>:<dbpassword>@ds261479.mlab.com:61479/grafar
# connection = MongoClient("ds261479.mlab.com", 61479)
# db = connection["grafar"]
# db.authenticate("admin", "grafar123")

# Create mongo client
mongo_client = MongoClient('localhost', 27017)
mongo_client = MongoClient(os.environ['DB_URL'], int(os.environ['DB_PORT']))

# Connect to database GrafarDB
grafar_db = mongo_client.GrafarDB
grafar_db = mongo_client[os.environ['DB_NAME']]

#Authenticate
grafar_db.authenticate(os.environ['DB_USER'], os.environ['DB_PASS'])

# Connect to graphs document
graphs_collection = grafar_db.graphs

# Define URL folder to save images
url_images = '/home/jnda/PycharmProjects/Grafar/static/functions_images/'
url_images = '/app/static/functions_images/'


# root
Expand Down Expand Up @@ -60,6 +69,7 @@ def get_function():
json {"message": "Your function is 10*x+2div6","success": true}
"""
success = False
message = ''

json = request.get_json()

Expand All @@ -68,6 +78,7 @@ def get_function():
a_param = json['a']
b_param = json['b']
except Exception as e:
print("En try de server.py ")
print(e)
message = 'You should type a valid function, and the points a and b'
else:
Expand Down Expand Up @@ -100,5 +111,6 @@ def page_not_found(error):
})


if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000)
#if __name__ == "__main__":
# app.run(host="127.0.0.1", port=5000)
#