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

Deploy #4

Open
wants to merge 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
frontend/node_modules
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn api.api:flask_app
70 changes: 67 additions & 3 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,68 @@
# dashboard
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

Flask - react app
formation data scientist
## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
24 changes: 0 additions & 24 deletions api/Dockerfile

This file was deleted.

110 changes: 23 additions & 87 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
import h5py
import seaborn as sns
import os
from statsmodels.nonparametric.kde import KDEUnivariate
from flask_cors import CORS


from flask_cors import CORS
flask_app = Flask(__name__, static_folder='../build', static_url_path='/')
# flask_app = Flask(__name__,)
CORS(flask_app)

path = "api/"

@flask_app.route('/')
def index():
return flask_app.send_static_file('index.html')

# app = Flask(__name__, static_folder='../build', static_url_path='/')
app = Flask(__name__)
CORS(app)
# @app.route('/')
# def index():
# return app.send_static_file('index.html')

THR_OPTI = 0.5172413793103449

data = pickle.load(open('data_20ieme.sav', 'rb'))
data = pickle.load(open(path+'data_20ieme.sav', 'rb'))
print("data loaded")

loaded_model = pickle.load(open('model_lgbm.sav', 'rb'))
loaded_model = pickle.load(open(path+'model_lgbm.sav', 'rb'))
print("model loaded")

y_proba = loaded_model.predict_proba(data)
Expand All @@ -39,75 +42,7 @@ def predict(y_pred_proba, thr = THR_OPTI) :
y_pred = predict(y_proba)
print("y_pred calculated")

knn = pickle.load(open('knn_1_20ieme.sav', 'rb'))


# def knn(id_client) :

# path = "../bdd/"

# idx_clients = pickle.load(open(path + 'idx/idx_clients.sav', 'rb'))


# t_start = time.time()

# nbr_nmatrix = 25
# nbr_split_nmatrix = 10

# nbr_sub = nbr_nmatrix * nbr_split_nmatrix

# nsub = "numero de la sub du client"
# s_id = "numero de ligne de la sub du client"


# for tab in np.arange(nbr_sub) :
# s = pickle.load(open(path + "idx/idx_split" + str(tab) + ".sav", 'rb'))


# idx_d = np.where(s.values == id_client)[0]

# if len(idx_d) == 1 :
# # print("on a stocké dans 's' uniquement les ID client des lignes de la sub : s_id. Dimension =", np.shape(s))

# nsub = tab
# s_id = idx_d[0]

# # print("le client est dans la sub" , nsub, " à la s_id", s_id)

# s = pickle.load(open(path+ "idx/idx_split" + str(nsub) + ".sav", 'rb')) # on s = [s_id] du client

# nmatrix = int(nsub / nbr_split_nmatrix) # numero de la matrix du client
# c_id = s.index[s_id] # numero de colonne de la matrix du client

# # print( "la ligne s_id:",s_id, "de la sub", nsub , "correspond à la colonne c_id:", c_id, "de la matrice", nmatrix)

# col = idx_clients[nmatrix] # colonne matrix du client

# # print("les colonnes de la matrix du client sont de dimension", np.shape(col))
# # print("on confirme que le numéro du client est par les colonnes c_id: ", col[c_id], ", donc = au numero du client : ", id_client)
# # print("on confirme que le numéro du client est par la sub s_id: ", s.iloc[s_id])

# h5f = h5py.File(path + "h5/dist_split" + str(nsub) + ".h5",'r') # on charge la sub des distances entre les clients
# b = h5f['dist'][:]
# dist = b[s_id,:] # on selectionne la ligne de la sub du client
# h5f.close()

# # print("la ligne de la sub est de dimension ", np.shape(dist))
# # print("la distance du client avec lui même devrait être nulle : ", dist[c_id])

# idx_d_500_kkn = list(np.argpartition(dist,500))[0:500] # on selectionne les 500 clients les plus proches en distance sans ordre (dans la sub)
# idx_knn_client = np.where(idx_d_500_kkn == c_id)[0][0] # on trouve dans cette liste knn non ordonné le c_id du client (dans la sub)
# idx_d_500_kkn.pop(np.where(idx_d_500_kkn == c_id)[0][0]) # on enlève la distance du client avec lui même (0)

# # print("on a trouvé les 499 plus proches voisins du client dans la sub ", np.shape(idx_d_500_kkn))

# idx_500_kkn = col[idx_d_500_kkn]

# # print("les ID des 10 clients parmis les 499 plus proches voisins sont : \n", idx_500_kkn[:10])

# return idx_500_kkn

from statsmodels.nonparametric.kde import KDEUnivariate
knn = pickle.load(open(path+'knn_1_20ieme.sav', 'rb'))

def kde_statsmodels_u(y_data, x_grid, bandwidth=0.2, **kwargs):
"""Univariate Kernel Density Estimation with Statsmodels"""
Expand All @@ -123,12 +58,12 @@ def density(pred , feature) :
return {"x":list(x_grid),"y":list(y)}


@app.route('/dashboard')
@flask_app.route('/api/dashboard')
def get_current_pred():

idx_clients = pickle.load(open('idx_clients.sav', 'rb'))
idx_clients = pickle.load(open(path+'idx_clients.sav', 'rb'))

s = pickle.load(open("data_20ieme.sav", 'rb'))
s = pickle.load(open(path+'data_20ieme.sav', 'rb'))
nmatrix = 0
c_id = s.index[0]
col = idx_clients[nmatrix] # colonne matrix du client
Expand Down Expand Up @@ -157,7 +92,7 @@ def get_current_pred():



@app.route('/dashboard/change', methods=['POST'])
@flask_app.route('/api/dashboard/change', methods=['POST'])
def change_pred():
print("requette ID arrivée")

Expand All @@ -171,7 +106,7 @@ def change_pred():



@app.route('/dashboard/id', methods=['POST'])
@flask_app.route('/api/dashboard/id', methods=['POST'])
def my_form_post():
print("requette ID arrivée")

Expand Down Expand Up @@ -210,7 +145,8 @@ def my_form_post():
}
}

if __name__ == "__main__":
# app.run(debug=True)
app.run(host='0.0.0.0', debug=True)
# app.run(host='0.0.0.0', debug=Fa0))
# if __name__ == "__main__":
# flask_app.run(host='0.0.0.0', debug=True)

if __name__ == "__main__":
flask_app.run(host='0.0.0.0', debug=False, port=os.environ.get('PORT', 80))
15 changes: 0 additions & 15 deletions api/requirements.txt

This file was deleted.

27 changes: 27 additions & 0 deletions build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"files": {
"main.css": "/static/css/main.1dc9daea.chunk.css",
"main.js": "/static/js/main.bfe05604.chunk.js",
"main.js.map": "/static/js/main.bfe05604.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.47c836b6.js",
"runtime-main.js.map": "/static/js/runtime-main.47c836b6.js.map",
"static/css/2.11829350.chunk.css": "/static/css/2.11829350.chunk.css",
"static/js/2.d5077f88.chunk.js": "/static/js/2.d5077f88.chunk.js",
"static/js/2.d5077f88.chunk.js.map": "/static/js/2.d5077f88.chunk.js.map",
"index.html": "/index.html",
"precache-manifest.e8c00842bdd4c5d7198b21f580cc151e.js": "/precache-manifest.e8c00842bdd4c5d7198b21f580cc151e.js",
"service-worker.js": "/service-worker.js",
"static/css/2.11829350.chunk.css.map": "/static/css/2.11829350.chunk.css.map",
"static/css/main.1dc9daea.chunk.css.map": "/static/css/main.1dc9daea.chunk.css.map",
"static/js/2.d5077f88.chunk.js.LICENSE.txt": "/static/js/2.d5077f88.chunk.js.LICENSE.txt",
"static/media/logo.svg": "/static/media/logo.ee7cd8ed.svg",
"static/media/nucleo-icons.css": "/static/media/nucleo.f0b489a5.woff"
},
"entrypoints": [
"static/js/runtime-main.47c836b6.js",
"static/css/2.11829350.chunk.css",
"static/js/2.d5077f88.chunk.js",
"static/css/main.1dc9daea.chunk.css",
"static/js/main.bfe05604.chunk.js"
]
}
Binary file added build/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><link href="/static/css/2.11829350.chunk.css" rel="stylesheet"><link href="/static/css/main.1dc9daea.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,a,p=r[0],l=r[1],f=r[2],c=0,s=[];c<p.length;c++)a=p[c],Object.prototype.hasOwnProperty.call(o,a)&&o[a]&&s.push(o[a][0]),o[a]=0;for(n in l)Object.prototype.hasOwnProperty.call(l,n)&&(e[n]=l[n]);for(i&&i(r);s.length;)s.shift()();return u.push.apply(u,f||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,p=1;p<t.length;p++){var l=t[p];0!==o[l]&&(n=!1)}n&&(u.splice(r--,1),e=a(a.s=t[0]))}return e}var n={},o={1:0},u=[];function a(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,a),t.l=!0,t.exports}a.m=e,a.c=n,a.d=function(e,r,t){a.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,r){if(1&r&&(e=a(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(a.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)a.d(t,n,function(r){return e[r]}.bind(null,n));return t},a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,"a",r),r},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.p="/";var p=this["webpackJsonpdashboard-app"]=this["webpackJsonpdashboard-app"]||[],l=p.push.bind(p);p.push=r,p=p.slice();for(var f=0;f<p.length;f++)r(p[f]);var i=l;t()}([])</script><script src="/static/js/2.d5077f88.chunk.js"></script><script src="/static/js/main.bfe05604.chunk.js"></script></body></html>
Binary file added build/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions build/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
self.__precacheManifest = (self.__precacheManifest || []).concat([
{
"revision": "f2c225c8a13a6e8a57444576ff8d6764",
"revision": "7e3bdd75bf7063e2200dfe066246934c",
"url": "/index.html"
},
{
"revision": "45ba9b41387fbbab64f4",
"url": "/static/css/2.11829350.chunk.css"
},
{
"revision": "ce9e7746351e9ac1d00d",
"revision": "afd1b92e59769e40b6e0",
"url": "/static/css/main.1dc9daea.chunk.css"
},
{
Expand All @@ -20,8 +20,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/2.d5077f88.chunk.js.LICENSE.txt"
},
{
"revision": "ce9e7746351e9ac1d00d",
"url": "/static/js/main.4e7df809.chunk.js"
"revision": "afd1b92e59769e40b6e0",
"url": "/static/js/main.bfe05604.chunk.js"
},
{
"revision": "fea6a8d102fc042967ab",
Expand Down
3 changes: 3 additions & 0 deletions build/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
Loading