Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5ca81fc
Clean backend folder && create protobuf script to compile and install…
Sep 20, 2020
d84ee34
structure backend folder and implement GreeterService
Sep 20, 2020
e5fd953
Add grpc-web to web/
Sep 21, 2020
01f06d3
Front-end uses envoy as a proxy
Sep 22, 2020
daca785
move envoy proxy to backend
Sep 22, 2020
f64efc8
Add computer loopback interface as grpc client ip address
Sep 22, 2020
70f5a5e
remove false comment aboute proxy port
Sep 22, 2020
610d1a4
add instructions for grpc installation in readme
Sep 23, 2020
af1e663
test
abelfodil Sep 25, 2020
15e2504
Merge branch 'master' of https://github.com/PolyCortex/polydodo into …
Sep 25, 2020
5771002
Remove useless install script && fix package name
Sep 25, 2020
db5fc68
Merge branch 'grpc' of https://github.com/PolyCortex/polydodo into mo…
Sep 25, 2020
1cdb13f
Apply suggestions from code review
Sep 29, 2020
909cc16
fix conflict
abelfodil Oct 1, 2020
055ca94
Enhance vscode xp
abelfodil Oct 1, 2020
75bbc98
Fix python app
abelfodil Oct 1, 2020
353196b
add host environment variable for grpc
Oct 1, 2020
1c9efab
Merge branch 'mock-python-back-end' of https://github.com/PolyCortex/…
Oct 1, 2020
dc53aa0
Add envoy to docker
abelfodil Oct 1, 2020
8f523ae
Fix prettier format
abelfodil Oct 1, 2020
2298cb7
Verbose logs
abelfodil Oct 1, 2020
4ff6391
Downgrade java
abelfodil Oct 1, 2020
413f3a2
update readme
abelfodil Oct 1, 2020
207c7c0
Fix web pipeline
abelfodil Oct 1, 2020
8afe68c
rename folders
abelfodil Oct 1, 2020
4ba3a74
Merge branch 'mock-python-back-end' of https://github.com/PolyCortex/…
Oct 1, 2020
d10f5ff
Attempt to fix web
abelfodil Oct 1, 2020
a1c2355
Remove verbose
abelfodil Oct 1, 2020
7053f03
Change ignorePatterns for evrything in protos/ folder
Oct 1, 2020
27d3211
Merge branch 'mock-python-back-end' of https://github.com/PolyCortex/…
Oct 1, 2020
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
File renamed without changes.
4 changes: 2 additions & 2 deletions .github/workflows/mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "12.x"
java-version: "8.x"
- uses: subosito/flutter-action@v1
- uses: abelfodil/protoc-action@v1
with:
enable-dart: true

- run: protoc --proto_path=protos protos/* --dart_out=mobile/lib/protos
- run: protoc --proto_path=protos protos/* --dart_out=grpc:mobile/lib/protos
working-directory: .

- run: flutter pub get
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: abelfodil/protoc-action@v1
- run: protoc --proto_path=protos protos/* --js_out=web/src/protos
with:
enable-grpc-web: true
- run: protoc protos/* --js_out=import_style=commonjs:web/src --grpc-web_out=import_style=commonjs,mode=grpcwebtext:web/src
- run: yarn --cwd web install
- run: yarn --cwd web build
- uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion .vscode/.prettierrc.yaml → .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
trailingComma: 'all'
trailingComma: "all"
tabWidth: 2
semi: true
singleQuote: true
Expand Down
13 changes: 0 additions & 13 deletions .vscode/extensions.json

This file was deleted.

21 changes: 0 additions & 21 deletions .vscode/settings.json

This file was deleted.

14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This projects aims to offer a comprehensive guide to **record polysomnographic E
- Install `gRPC` package from your distribution's package manager
- Install `protoc` compiler

### Yarn
### Web

- Install Yarn package manager
- `yarn global add protoc-gen-grpc-web`
Expand All @@ -18,7 +18,9 @@ This projects aims to offer a comprehensive guide to **record polysomnographic E
### Python

- Install Python 3 and pip
- Run `pip install -r requirements.txt`
- Consider using `venv` to create a virtual environment
- Install gRPC using a package manager or by compiling the [source code](https://github.com/grpc/grpc)
- Create a simlink named `protoc-gen-grpc_python` to `grpc_python_plugin` using `ln -nsf $(which grpc_python_plugin) /some/where/in/your/path/protoc-gen-grpc_python`

### Flutter

Expand All @@ -33,7 +35,13 @@ This projects aims to offer a comprehensive guide to **record polysomnographic E

## Dev workflow

- Open root folder on VS Code
- Open workspace `polydodo.code-workspace`
- Install node modules by running `yarn install --cwd web`
- Fetch Flutter dependencies through the `Flutter` extension
- Compile all protos through `proto3` extension

## Running the server locally

- [Login](https://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages#authenticating-with-a-personal-access-token) to Github Docker registry
- `docker pull docker.pkg.github.com/polycortex/polydodo/backend:latest`
- `docker run -p 8080:8080 docker.pkg.github.com/polycortex/polydodo/backend:latest`
4 changes: 3 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.venv/
.venv/
.vscode/
__pycache__/
15 changes: 11 additions & 4 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ FROM namely/protoc-all as generator
WORKDIR /
COPY protos protos
COPY backend backend
RUN protoc --proto_path=protos protos/* --python_out=backend/protos
RUN ln $(which grpc_python_plugin) /usr/bin/protoc-gen-grpc_python
RUN protoc protos/* --python_out=backend --grpc_python_out=backend

FROM python
FROM envoyproxy/envoy:v1.15-latest
RUN apt-get update \
&& apt-get -y install python3-pip \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /tmp/* /var/tmp/* \
&& rm -rf /var/lib/apt/lists/*
COPY --from=generator /backend /backend
WORKDIR /backend
RUN pip install -r requirements.txt --no-cache-dir
ENTRYPOINT ["python", "app.py"]
RUN pip3 install -r requirements.txt --no-cache-dir
CMD "./start.sh"
82 changes: 38 additions & 44 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
from flask import Flask, render_template, url_for, request, redirect
import os
from resampling import convert_csv_to_raw
from werkzeug.utils import secure_filename

ALLOWED_EXTENSIONS = {'csv'}

def allowed_filename(filename):
if not '.' in filename:
print('No extension in filename')
return False

ext = filename.rsplit('.', 1)[1]
if ext.lower() in ALLOWED_EXTENSIONS:
return True
else:
print('That file extension is not allowed')
return False


app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/upload-csv', methods =['GET','POST'])
def upload_csv():
if request.method == 'POST':
if request.files:
csv = request.files['csv']

if csv.filename =='':
print('No filename or no selected file')
return redirect(request.url)

if allowed_filename(csv.filename):
filename = secure_filename(csv.filename) #useless si on save pas le fichier je crois
print(csv)
convert_csv_to_raw(csv)
return redirect(request.url)

return render_template('upload_csv.html')
# Copyright 2015 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Python implementation of the GRPC helloworld.Greeter server."""

from concurrent import futures
import logging

import grpc

from protos import helloworld_pb2
from protos import helloworld_pb2_grpc


class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)


def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:9090')
server.start()
server.wait_for_termination()


if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
logging.basicConfig()
serve()
40 changes: 40 additions & 0 deletions backend/envoy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Taken from https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 8080 }
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route:
cluster: greeter_service
max_grpc_timeout: 0s
cors:
allow_origin_string_match:
- prefix: "*"
allow_methods: GET, PUT, DELETE, POST, OPTIONS
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
max_age: "1728000"
expose_headers: custom-header-1,grpc-status,grpc-message
http_filters:
- name: envoy.grpc_web
- name: envoy.cors
- name: envoy.router
clusters:
- name: greeter_service
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
hosts: [{ socket_address: { address: 0.0.0.0, port_value: 9090 } }]
97 changes: 0 additions & 97 deletions backend/erreur_test.csv

This file was deleted.

20 changes: 20 additions & 0 deletions backend/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Backend

This backend holds a GRPC server that classify OpenBCI raw EEG data into sleep stages.

## How to run

I you are running the front-end, you'll need to build the dockerfile to get the Envoy proxy.

> docker build -t polydodo-web .

> docker run -d -p 8080:8080 -p 9090:9090 --network=host polydodo-web

To start the server:

> python backend/app.py

## Get requirements:

> python -m venv .venv
> python -m pip install -r requirements.txt
17 changes: 1 addition & 16 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
click==7.1.1
Flask==1.1.1
Flask-SQLAlchemy==2.4.1
itsdangerous==1.1.0
Jinja2==2.11.1
MarkupSafe==1.1.1
mne==0.19.2
numpy==1.18.2
pandas==1.0.3
pandas-schema==0.3.5
python-dateutil==2.8.1
pytz==2019.3
scipy==1.4.1
Comment thread
abelfodil marked this conversation as resolved.
six==1.14.0
SQLAlchemy==1.3.15
Werkzeug==1.0.0
grpcio==1.32.0
protobuf==3.13.0
Loading