Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
Trèfle
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Open source
Trèfle
Commits
ad4b3d61
Commit
ad4b3d61
authored
Jun 08, 2018
by
Yohan Boniface
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Naive "simulate" explorer view
parent
451a17f5
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
3771 additions
and
3431 deletions
+3771
-3431
features/steps/steps.py
features/steps/steps.py
+1
-2
remote/__main__.py
remote/__main__.py
+26
-2
remote/trefle.service
remote/trefle.service
+1
-0
trefle/api.py
trefle/api.py
+19
-5
trefle/bin.py
trefle/bin.py
+4
-3
trefle/core.py
trefle/core.py
+1
-1
trefle/debugging.py
trefle/debugging.py
+3
-3
trefle/explorer/app.css
trefle/explorer/app.css
+62
-1
trefle/explorer/components/navbar.tag.html
trefle/explorer/components/navbar.tag.html
+3
-2
trefle/explorer/components/rule.tag.html
trefle/explorer/components/rule.tag.html
+25
-0
trefle/explorer/components/rules.tag.html
trefle/explorer/components/rules.tag.html
+1
-55
trefle/explorer/components/schema.tag.html
trefle/explorer/components/schema.tag.html
+1
-0
trefle/explorer/components/simulate.tag.html
trefle/explorer/components/simulate.tag.html
+95
-0
trefle/explorer/index.html
trefle/explorer/index.html
+4
-0
trefle/explorer/vendor/riot/riot+compiler.js
trefle/explorer/vendor/riot/riot+compiler.js
+3525
-3357
No files found.
features/steps/steps.py
View file @
ad4b3d61
...
...
@@ -53,8 +53,7 @@ def given_set_false(context, key):
@
when
(
'je demande un calcul de financement'
)
@
async_run_until_complete
async
def
when_simulate
(
context
):
context
.
passed
=
[
f
for
f
in
await
simulate
(
**
context
.
data
)
if
f
.
get
(
'eligible'
)]
context
.
passed
=
[
f
for
f
in
await
simulate
(
context
.
data
)
if
f
[
'eligible'
]]
@
then
(
r
"il y a (?P<expected>\d+) financements? proposés?"
)
...
...
remote/__main__.py
View file @
ad4b3d61
import
os
import
sys
from
io
import
StringIO
import
urllib.request
...
...
@@ -137,13 +140,34 @@ def ssh_keys():
@
minicli
.
cli
def
access_logs
():
"""See the nginx access logs."""
run
(
'tail -F /var/log/nginx/access.log'
)
with
sudo
():
run
(
'tail -F /var/log/nginx/access.log'
)
@
minicli
.
cli
def
error_logs
():
"""See the nginx error logs."""
run
(
'tail -F /var/log/nginx/error.log'
)
with
sudo
():
run
(
'tail -F /var/log/nginx/error.log'
)
@
minicli
.
cli
def
upload_env
():
"""Upload environment vars to the server.
Use those to deal with info not commitable.
"""
keys
=
[
'LBF_CHARMAP'
]
content
=
''
for
key
in
keys
:
try
:
content
+=
'{}={}
\n
'
.
format
(
key
,
os
.
environ
[
key
])
except
KeyError
as
e
:
sys
.
exit
(
'The {} environment variable does not exist.'
.
format
(
e
))
path
=
'/srv/trefle/env'
if
exists
(
path
):
run
(
f
'cat
{
path
}
'
)
put
(
StringIO
(
content
),
path
)
@
minicli
.
wrap
...
...
remote/trefle.service
View file @
ad4b3d61
...
...
@@ -7,6 +7,7 @@ Type=simple
User
=
trefle
ExecStart
=
/srv/trefle/venv/bin/gunicorn trefle.api:app --config gunicorn.conf
WorkingDirectory
=
/srv/trefle/
EnvironmentFile
=
/srv/trefle/env
Restart
=
always
RestartSec
=
5
StandardOutput
=
journal
...
...
trefle/api.py
View file @
ad4b3d61
import
logging
import
pkg_resources
from
http
import
HTTPStatus
from
pathlib
import
Path
from
roll
import
Roll
,
HttpError
from
roll
import
HttpError
,
Roll
from
roll.extensions
import
cors
from
.config
import
RAW_RULES
,
SCHEMA
from
.core
import
simulate
from
.debugging
import
data_from_lbf_url
,
make_feature
from
.openapis
import
OPENAPI
from
.config
import
SCHEMA
,
RAW_RULES
logger
=
logging
.
getLogger
(
'trefle'
)
logger
.
setLevel
(
logging
.
DEBUG
)
...
...
@@ -39,8 +39,9 @@ async def json_error_response(request, response, error):
@
app
.
route
(
'/financement'
,
methods
=
[
'POST'
])
async
def
simulate_
(
request
,
response
):
context
=
request
.
json
try
:
financements
=
await
simulate
(
**
request
.
json
)
financements
=
await
simulate
(
context
)
except
ValueError
as
err
:
raise
HttpError
(
HTTPStatus
.
UNPROCESSABLE_ENTITY
,
err
.
args
[
0
])
...
...
@@ -49,7 +50,15 @@ async def simulate_(request, response):
financements
=
[
f
for
f
in
financements
if
f
[
'eligible'
]
==
eligible
]
for
tag
in
request
.
query
.
list
(
'tags'
,
[]):
financements
=
[
f
for
f
in
financements
if
tag
in
f
[
'tags'
]]
response
.
json
=
{
'financements'
:
financements
}
body
=
{
'financements'
:
financements
}
del
context
[
'financements'
]
if
request
.
query
.
bool
(
'context'
,
False
):
body
[
'context'
]
=
{
k
:
{
'label'
:
SCHEMA
[
k
][
'label'
],
'value'
:
v
}
for
k
,
v
in
context
.
items
()
if
k
in
SCHEMA
and
'label'
in
SCHEMA
[
k
]}
if
request
.
query
.
bool
(
'scenario'
,
False
):
body
[
'scenario'
]
=
make_feature
(
context
,
financements
)
response
.
json
=
body
@
app
.
route
(
'/schema'
)
...
...
@@ -65,3 +74,8 @@ async def explore_schema(request, response):
@
app
.
route
(
'/explore/rules'
)
async
def
explore_rules
(
request
,
response
):
response
.
json
=
RAW_RULES
@
app
.
route
(
'/explore/decode-lbf-url'
)
async
def
decode_lbf_url
(
request
,
response
):
response
.
json
=
data_from_lbf_url
(
request
.
query
.
get
(
'url'
))
trefle/bin.py
View file @
ad4b3d61
...
...
@@ -3,7 +3,7 @@ from pathlib import Path
import
ujson
as
json
from
minicli
import
cli
,
run
from
roll.extensions
import
simple_server
,
static
from
roll.extensions
import
simple_server
,
static
,
traceback
from
.api
import
app
from
.config
import
ELIGIBILITE
,
MODALITES
,
SCHEMA
...
...
@@ -42,7 +42,7 @@ async def cli_simulate(*args, data: json.loads={}, url=None, trace=False,
"""
flatten
(
data
)
if
url
:
data
=
await
data_from_lbf_url
(
url
)
data
=
data_from_lbf_url
(
url
)
if
args
:
data
.
update
(
parse_args
(
args
))
if
'formation.numero'
in
data
:
...
...
@@ -68,7 +68,7 @@ async def cli_simulate(*args, data: json.loads={}, url=None, trace=False,
# We already processed the formation, prevent to process it twice.
del
data
[
'formation.numero'
]
start
=
time
.
perf_counter
()
financements
=
await
simulate
(
**
data
)
financements
=
await
simulate
(
data
)
duration
=
(
time
.
perf_counter
()
-
start
)
print
(
'*'
*
105
)
eligibles
=
[
f
for
f
in
financements
if
f
[
'eligible'
]]
...
...
@@ -131,6 +131,7 @@ def serve():
"""Run a web server (for development only)."""
# Debug only.
static
(
app
,
'/explorer/'
,
Path
(
__file__
).
parent
/
'explorer'
)
trac