Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • MaitresNageurs/README/LabelsTower
  • perus/LabelsTower
  • DeletedUser/LabelsTower
  • chamont/LabelsTower
  • erichard/LabelsTower
5 results
Show changes
Showing
with 436 additions and 0 deletions
#!/usr/bin/env bash
# This ensures that we are in this script directory,
# even if we call it from another one.
SCRIPT_NAME=${BASH_SOURCE[0]}
cd `dirname ${SCRIPT_NAME}`
# Flask opère sur le port 5000
docker run -it --rm -p 5000:5000 -v $PWD/..:/work -w /work --env LT_CFG="${LT_CFG}" labelstower:externals $*
#!/usr/bin/env bash
# This ensures that we are in this script directory,
# even if we call it from another one.
SCRIPT_NAME=${BASH_SOURCE[0]}
cd `dirname ${SCRIPT_NAME}`
# Flask opère sur le port 5000
docker run -it --rm -p 5000:5000 -v $PWD/../test:/work -w /work --env LT_CFG="${LT_CFG}" labelstower:latest $*
\ No newline at end of file
,erichard,nb-erichard,30.01.2020 13:50,file:///home/erichard/.config/libreoffice/4;
\ No newline at end of file
File added
File added
File added
File added
File added
File added
File added
from flask import Blueprint
bp = Blueprint('sort', __name__)
from . import routes
import os
from typing import Dict, List
from .request_db import send_query_to_db
from . import bp
if(os.environ["LABELSTOWER_USER_OPTION"]=="true"):
from .sqlStmtUserOption import queries, FORBIDEN_LABEL_ONLY, ALL_LABEL_TYPE
else:
from .sqlStmt import queries, FORBIDEN_LABEL_ONLY, ALL_LABEL_TYPE
def get_selected_elements(id_mandatory_labels: int, id_forbiden_labels: str, number_of_mandatory_labels: str) -> List[Dict[int, str]] :
"""
Return a set of elements which wear mandatory labels and don't wear forbiden labels.
:param id_mandatory_labels: str
:param id_forbiden_labels: str
:param number_of_mandatory_labels: int
:return: List[Dict[int, str]]
EXEMPLE
-------
>>> print(get_selected_elements("","",0)) # si aucun labels n'est interdit ou obligatoire
[{'id': 4, 'element_name': 'peugeot, 2000'}, {'id': 3, 'element_name': 'renault, 2000'}, {'id': 2, 'element_name': 'renault, bleu, 2000'}, {'id': 1, 'element_name': 'renault, rouge, 2000'}]
>>> print(get_selected_elements("1,2","5,9",2)) # si la voiture doit-être bleu
[{'id': 4, 'element_name': 'peugeot, 2000'}]
>>> print(get_selected_elements("5","",1))
[{'id': 3, 'element_name': 'renault, 2000'}, {'id': 2, 'element_name': 'renault, bleu, 2000'}, {'id': 1, 'element_name': 'renault, rouge, 2000'}]
>>> print(get_selected_elements("","5",0))
[{'id': 4, 'element_name': 'peugeot, 2000'}]
"""
#query slightly vary if number_of_mandatory_labels > 0 or not
if(number_of_mandatory_labels):
query = queries[ALL_LABEL_TYPE].format(id_mandatory_labels, id_forbiden_labels, number_of_mandatory_labels)
else:
query = queries[FORBIDEN_LABEL_ONLY].format(id_forbiden_labels)
selected_elements = send_query_to_db(query)
return selected_elements
def get_discriminating_labels(selected_elements: List[Dict[int, str]]) -> List[Dict[int, str]] :
"""
Return all labels associated to selected elements except non discrminating
:param elements: list[Dict[str, str]]
:return: list[Dict[int, str]]
EXEMPLE
-------
>>> get_discriminating_labels([{"id":2,"name":"renault, bleu, 2000"}, {"id":1,"name":"renault, rouge, 2000"}])
[{'id': 8, 'label_name': 'rouge'}, {'id': 9, 'label_name': 'bleu'}]
>>> get_discriminating_labels([])
[]
"""
id_selected_elements: str = get_ids(selected_elements)
number_of_selected_elements = len(selected_elements)
# select labels of selected elements and delete labels commun to all elements
query = '''
SELECT
LABEL.id
, label_name
FROM
ELEMENT
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id=ELEMENT_LABEL.id_element
INNER JOIN
LABEL
ON ELEMENT_LABEL.id_label=LABEL.id
WHERE
id_element IN ({})
GROUP BY id_label
HAVING COUNT(*) < {}
'''.format(id_selected_elements, number_of_selected_elements)
discriminating_labels = send_query_to_db(query)
return discriminating_labels
def get_high_discriminating_labels(discriminating_labels: List[Dict[int, str]]) -> List[Dict[int, str]] :
"""
Return a set of new labels to continue your selection with it
:param elements: list[Dict[str, str]]
:return: list[Dict[int, str]]
EXEMPLE
-------
>>> get_high_discriminating_labels([{"id":7, "name":"couleur"}, {"id":8, "name":"rouge"}, {"id":9, "name":"bleu"}])
[{'id': 7, 'label_name': 'couleur'}]
"""
id_discriminating_labels = get_ids(discriminating_labels)
# delete all childrens of discriminating labels set
query = '''
SELECT
*
FROM (
SELECT
id,
label_name
FROM
LABEL
WHERE
LABEL.id IN({})
)
WHERE
id NOT IN (
SELECT
B.id AS id_fils
FROM (
SELECT
*
FROM
LABEL
WHERE
id IN ({})
) AS A,
LABEL AS B
WHERE
A.id=B.father_id
)
'''.format(id_discriminating_labels, id_discriminating_labels)
labels = send_query_to_db(query)
return labels
def get_ids(objects: List[Dict[int, str]]) -> str :
"""
Return all ids of the object's set
:param objects: list[Dict[str, str]]
:param attribut: str
:return: str
EXEMPLE
-------
>>> print(get_ids([{"id":1, "name":"a"},{"id":2, "name":"b"}]))
1,2
>>> print(get_ids([]))
<BLANKLINE>
"""
objects_ids = ""
for object in objects:
objects_ids += str(object["id"]) + ","
#remove last extra comma
return objects_ids[0:-1]
def get_user_selection(number_of_mandatory_labels: int, optional1: str, optional2: str) -> tuple :
'''
Return the right values of id_mandatory_labels and id_forbiden_labels when optional2 is missing.
It is necessary because optional1 could be id_mandatory_labels or id_forbiden_labels.
:param number_of_mandatory_labels: int
:param optional1: str
:param optional2: str
:return:
'''
if int(number_of_mandatory_labels):
id_mandatory_labels = optional1
id_forbiden_labels = optional2
else:
id_mandatory_labels = optional2
id_forbiden_labels = optional1
return id_mandatory_labels, id_forbiden_labels
from typing import Dict, List
from . import bp
def send_query_to_db(query: str) -> List[Dict[int, str]] :
'''
Return the result of the query send to the database
:param query: str
:return: List[Dict[int, str]]
'''
result = []
stmt = bp.db.text(query)
response = bp.db.session.execute(stmt)
for row in response:
record = {}
for index in range(len(row)):
record.update({str(row.keys()[index]):row[index]})
result.append(record)
return result
\ No newline at end of file
from typing import Dict, List
import json
from .getter import get_selected_elements, get_discriminating_labels, get_high_discriminating_labels, get_user_selection
from . import bp
#URLs call to update labels and elements along researchs
@bp.route('/search/<int:number_of_mandatory_labels>', defaults={'optional1':'', 'optional2':''})
@bp.route('/search/<int:number_of_mandatory_labels>/<string:optional1>', defaults={'optional2':''})
@bp.route('/search/<int:number_of_mandatory_labels>/<string:optional1>/<string:optional2>')
def search(number_of_mandatory_labels: int, optional1: str, optional2: str) -> List[List[Dict[int, str]]] :
'''
Return updated lists of selected elements and high discriminating labels useful to continu research
:param number_of_mandatory_labels: int
:param optional1: str
:param optional2: str
:return: List[List[Dict[int, str]]]
'''
id_mandatory_labels, id_forbiden_labels = get_user_selection(number_of_mandatory_labels, optional1, optional2)
selected_elements = get_selected_elements(id_mandatory_labels, id_forbiden_labels, number_of_mandatory_labels)
high_discriminating_labels = get_high_discriminating_labels(get_discriminating_labels(selected_elements))
result = [selected_elements, high_discriminating_labels]
return json.dumps(result)
queries =[
'''SELECT
ELEMENT.*
FROM
ELEMENT
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id=ELEMENT_LABEL.id_element
WHERE
id_label IN ({})
AND
id_element NOT IN (
SELECT
id_element
FROM
ELEMENT
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id=ELEMENT_LABEL.id_element
WHERE
id_label IN ({}))
GROUP BY id_element
HAVING COUNT(*) = {}
Order BY element_name''',
'''
SELECT
ELEMENT.*
FROM
ELEMENT
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id = ELEMENT_LABEL.id_element
WHERE
id_element NOT IN (
SELECT
id_element
FROM
ELEMENT
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id = ELEMENT_LABEL.id_element
WHERE id_label IN ({}) )
GROUP BY ELEMENT.id
ORDER BY element_name ASC
'''
]
ALL_LABEL_TYPE=0
FORBIDEN_LABEL_ONLY=1
\ No newline at end of file
queries =[
'''SELECT
ELEMENT.*, USER.username
FROM
USER
INNER JOIN
ELEMENT
ON USER.id=ELEMENT.user_id
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id=ELEMENT_LABEL.id_element
WHERE
id_label IN ({})
AND
id_element NOT IN (
SELECT
id_element
FROM
ELEMENT
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id=ELEMENT_LABEL.id_element
WHERE
id_label IN ({}))
GROUP BY id_element
HAVING COUNT(*) = {}
Order BY element_name''',
'''
SELECT
ELEMENT.*, USER.username
FROM
USER
INNER JOIN
ELEMENT
ON USER.id=ELEMENT.user_id
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id=ELEMENT_LABEL.id_element
WHERE
id_element NOT IN (
SELECT
id_element
FROM
ELEMENT
INNER JOIN
ELEMENT_LABEL
ON ELEMENT.id = ELEMENT_LABEL.id_element
WHERE id_label IN ({}) )
GROUP BY ELEMENT.id
ORDER BY element_name ASC
'''
]
ALL_LABEL_TYPE=0
FORBIDEN_LABEL_ONLY=1
\ No newline at end of file
import os
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
db = SQLAlchemy()
class CustomFlask(Flask):
jinja_options = Flask.jinja_options.copy()
jinja_options.update(dict(
variable_start_string='[[',
variable_end_string=']]',
))
def create_app():
text_component = {"project_name": "LabelsTower",
"Label": "Label(s)"
}
app = CustomFlask(__name__)
CORS(app)
app.config.from_object(os.environ['LABELSTOWER_ENV'])
db.init_app(app)
from labelstower import bp as bp_labels
bp_labels.db = db
app.register_blueprint(bp_labels, url_prefix='/sort')
@app.route('/')
@app.route('/browse')
def home():
return render_template('browse.html', txt=text_component)
return app
class ConfigCodingPool():
SQLALCHEMY_DATABASE_URI = 'sqlite:///../instance/CodingPool.sqlite'
SQLALCHEMY_TRACK_MODIFICATIONS = False
class ConfigVoiture():
SQLALCHEMY_DATABASE_URI = 'sqlite:///../instance/Voiture.sqlite'
SQLALCHEMY_TRACK_MODIFICATIONS = False
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from . import db
element_label = db.Table('Element_Label', db.Model.metadata,
db.Column('id_element', db.Integer, db.ForeignKey('element.id')),
db.Column('id_label', db.Integer, db.ForeignKey('label.id'))
)
class Element(db.Model):
id = db.Column(db.INTEGER, primary_key=True)
element_name = db.Column(db.String(50), unique=True, nullable=False)
labels = db.relationship(
"Label",
secondary=element_label,
back_populates="elements")
class Label(db.Model):
id = db.Column(db.INTEGER, primary_key=True)
label_name = db.Column(db.String(50), unique=True, nullable=False)
father_id = db.Column(db.INTEGER, db.ForeignKey('label.id'))
children = db.relationship("Label",
backref=db.backref('parent', remote_side=[id])
)
aliases = db.relationship('Alias', back_populates='label')
elements = db.relationship(
"Element",
secondary=element_label,
back_populates="labels")
class Alias(db.Model):
alias_name = db.Column(db.String(100), primary_key=True)
id_label = db.Column(db.INTEGER, db.ForeignKey('label.id'), nullable=False)
label = db.relationship('Label', back_populates='aliases')
Programmation, Coding
Langages, Languages, Langage, Language
C++, CPP, C Plus Plus
Python
Data Science
Science des données, Big Data, Données massives
Génie Logiciel, Software Engineering
Git
Gitlab
Documentation
Notebooks, Notebook
Jupyter
Base de données, Databases, Base de donnée, Database
Interfaces Homme-Machine, Interface Homme-Machine, GUI, Graphic User Interfaces, Graphic User Interface
Exploitation, Administration, ASR, Administration Systèmes et Réseaux, Administration Système et Réseau
Integration Continue, Continuous Integration
Conteneurs, Conteneur, Containers, Container
Docker
Orchestration
Kubernates
Bureautique, Desktop Tools, Desktop Tool, Office