diff --git a/app/__pycache__/labelsTower.cpython-35.pyc b/app/__pycache__/labelsTower.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bb39b7f6674656d0723fc14fd520a9deed132c2b Binary files /dev/null and b/app/__pycache__/labelsTower.cpython-35.pyc differ diff --git a/app/__pycache__/sql_request.cpython-35.pyc b/app/__pycache__/sql_request.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4849a9cd134dac57625c6c75b7840a3f4efb5e5d Binary files /dev/null and b/app/__pycache__/sql_request.cpython-35.pyc differ diff --git a/app/__pycache__/tuto.cpython-35.pyc b/app/__pycache__/tuto.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6f25c4371850f1e9c1259f9a15df44cce554f8d9 Binary files /dev/null and b/app/__pycache__/tuto.cpython-35.pyc differ diff --git a/app/__pycache__/update_labels.cpython-35.pyc b/app/__pycache__/update_labels.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cdda45a3f7e97501541df7db0cfe056dec2af501 Binary files /dev/null and b/app/__pycache__/update_labels.cpython-35.pyc differ diff --git a/app/bdd_for_labels.db b/app/bdd_for_labels.db new file mode 100644 index 0000000000000000000000000000000000000000..dbaf72ad3b77c331b00748c706a0e4b812f3f345 Binary files /dev/null and b/app/bdd_for_labels.db differ diff --git a/app/createBdd.sql b/app/createBdd.sql new file mode 100644 index 0000000000000000000000000000000000000000..7b657e62f9dc90baa158a1c9b0a041557452833f --- /dev/null +++ b/app/createBdd.sql @@ -0,0 +1,37 @@ +/*CREATE DATABASE labels_tower CHARACTER SET 'utf8'; +USE labels_tower;*/ + +CREATE TABLE IF NOT EXISTS tutos ( + link VARCHAR(200) NOT NULL, + author_mail UNSIGNED MEDIUM INT, + date DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS labels ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR(100) NOT NULL, + father_id UNISGNED MEDIUM INT DEFAULT NULL +); + +CREATE TABLE IF NOT EXISTS tutos_labels ( + link VARCHAR(200) NOT NULL, + id_label UNSIGNED MEDIUM INT +); + +CREATE TABLE IF NOT EXISTS alias ( + id_label UNSIGNED MEDIUM INT, + name VARCHAR(100) NOT NULL +); + +CREATE TABLE IF NOT EXISTS votes ( + link VARCHAR(200) NOT NULL, + mark TINYINT, + author_mail VARCHAR(100) +); + +CREATE TABLE IF NOT EXISTS comments ( + link VARCHAR(200) NOT NULL, + message VARCHAR(500), + author_mail VARCHAR(100), + date DATETIME DEFAULT CURRENT_TIMESTAMP +); diff --git a/app/labels b/app/labels new file mode 100644 index 0000000000000000000000000000000000000000..e09f93da07354e5c106e199749d3a556de57a9f4 --- /dev/null +++ b/app/labels @@ -0,0 +1,40 @@ +Calcul + Vectorisation + Profilage + Gpu, Gpgpu, accélérateur(s), co-processeur(s) + Data Science, Big Data, Science des données + Calcul Intensif, Hpc + Machine Learning, Apprentissage, Deep Learning +Controle-Commande-Acquisition +Enseignement + Creation Plongeons + Notebooks +Génie Logiciel + Construction, Build, Make + Documentation + Test + Gestion de versions, Version, Versions + Git + test1 + test2 + test3 + Gitlab + Integration Continue + Deploiement + Gestion de paquets +Interfaces Homme-Machine, Ihm, Gui +Langages + Cpp, C++, Cplusplus + Go + Python + Ada + Scala +Programmation + Orientée Objet, Orientée Objets, OO, objet, objets + Fonctionnelle +Virtualisation + Docker + Singularity + Jupyter +Administration + Orchestration diff --git a/app/labelsTower.py b/app/labelsTower.py new file mode 100644 index 0000000000000000000000000000000000000000..d53c7961fe67dc2b5263e1e1697ec548b7834ec1 --- /dev/null +++ b/app/labelsTower.py @@ -0,0 +1,41 @@ +import sqlite3 +from update_labels import * +from sql_request import * +from flask import Flask, request, render_template, jsonify +app = Flask(__name__) + +@app.route('/') +def home(): + return 'Home' + +@app.route('/get_datas/<string:name>') +def get_datas(name): + '''Return labels table or alias table for Ajax. + ''' + if (name == 'labels'): + return (jsonify(send_sql_request('SELECT * FROM labels'))) + elif (name == 'alias'): + return (jsonify(send_sql_request('SELECT * from alias'))) + return 'Error' + +@app.route('/manage_labels', methods=['GET', 'POST']) +def manage_labels(): + '''For manage all labels and alias register in database. + (Add new labels and alias actually) + ''' + if request.method == 'GET': + res = send_sql_request('SELECT * FROM labels') + return render_template('manage_labels.html', labels=res) + else: + update_labels(request.form['alias_input']) + return render_template('manage_labels.html', labels=request.form['alias_input'], success="Succès de l'envoie") + +@app.route('/print_labels') +def print_labels(): + '''Print labels like a tree. ex : + L> Virtualisation + L> Docker + L>Singularity + L> Others + ''' + return render_template('print_labels.html') diff --git a/app/sql_request.py b/app/sql_request.py new file mode 100644 index 0000000000000000000000000000000000000000..94b6d473f01b92f889e52fa2bf17a7c4cc12960c --- /dev/null +++ b/app/sql_request.py @@ -0,0 +1,16 @@ +import sqlite3 + +def send_sql_request(request, fetchall = 1): + '''Execute sql request on bdd_for_labels database. + If second parameter is 0 return one line of the response + else return all lines. + ''' + conn = sqlite3.connect('app/bdd_for_labels.db') + c = conn.cursor() + c.execute(request) + conn.commit() + if (fetchall == 1): + res = c.fetchall() + else: + res = c.fetchone() + return (res) diff --git a/app/templates/manage_labels.html b/app/templates/manage_labels.html new file mode 100644 index 0000000000000000000000000000000000000000..575a38b6b4cba7043b849c1f7b9648bbee69bf05 --- /dev/null +++ b/app/templates/manage_labels.html @@ -0,0 +1,22 @@ +<html> + <head> + <title>Manage Labels</title> + <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> + </head> + + <body> + <p>{{ success }}</p> + <div id='input_zone'> + <form action="" method="POST"> + <textarea class="text" type="text" name="alias_input" cols="60" rows="40">{{ labels }}</textarea> + <br> + <input type="submit" value="Envoyer"/> + </form> + </div> + </body> + + <script> + + </script> + +</html> diff --git a/app/templates/print_labels.html b/app/templates/print_labels.html new file mode 100644 index 0000000000000000000000000000000000000000..b477e8179565ac9f2ac929246597ccf4af97e2e3 --- /dev/null +++ b/app/templates/print_labels.html @@ -0,0 +1,101 @@ +<html> + <head> + <title>Print labels</title> + <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> + </head> + + <body> + <ul id="tuto"> + <li v-for="(value, index) in fruits" @click="getFruit(index)"> + {{ index }} => {{ value }} + </li> + </ul> + + <!---<div> + <div id="test" v-for="value in labels" @click="clickLabel()"> + {{ value }} + </div> + </div>--> + </body> + + <script> + + function request(address) { + var xhr = new XMLHttpRequest(); + /*xhr.onreadystatechange = function () { + //if (xhr.readyState == 4) + //alert("reponse = " + xhr.responseText); + };*/ + xhr.open("GET", "http://127.0.0.1:5000/"+address, false); + xhr.send(); + return (xhr.responseText); + }; + + //add \t to the child in function + function print_elem(txt, nb_tabs) { + var new_msg = ""; + for (var i = 0; i < nb_tabs; i++) + new_msg += '\t'; + new_msg += txt; + console.log(nb_tabs + new_msg); + } + + //print the tab that represent labels with theirs childs + function print_tab(tab, nb_tabs) { + for (var i = 0; tab[i]; i++) { + if (Array.isArray(tab[i - 1])) + nb_tabs--; + if (Array.isArray(tab[i])) { + nb_tabs++; + print_tab(tab[i], nb_tabs) + } else + print_elem(tab[i], nb_tabs); + } + } + + var tab = ['addition', 'soustraction', 'complexe', ['c1', 'c2', ['lol1', 'lol2'], 'c3'], 'easy', ['un', ['deux', ['trois', ['quatre']]]], 'ok']; + var labels_tab = JSON.parse(request("get_datas/labels")) + var labels_list = [] + + for (var i = 0; labels_tab[i]; i++) { + if (labels_tab[i][2] == null) + labels_list.push(labels_tab[i][0]) + } + + console.log(labels_tab) + console.log('\n================\n', labels_list) + console.log(labels_tab[0][2]) + //crrer l'espece de liste sur la gaucje + //print_tab(tab, 0); + + /*new Vue({ + el: '#test', + data: { + labels: ['a', 'b', 'c'] + }, + methods: { + clickLabel: function() { + alert("clique"); + } + } + });*/ + + new Vue({ + el: '#tuto', + data: { + fruits: [ + 'pomme', + 'cerise', + 'abricot' + ] + }, + methods: { + getFruit: function(index) { + alert('Je suis ' + this.fruits[index]); + } + } + }); + + </script> + +</html> diff --git a/app/update_labels.py b/app/update_labels.py new file mode 100644 index 0000000000000000000000000000000000000000..708deddf2ac50f06bd947deabd731d0f35ce798d --- /dev/null +++ b/app/update_labels.py @@ -0,0 +1,152 @@ +'''Take user input and send labels and alias in database if they don't exist. +''' + +import sqlite3 +from sql_request import * +conn = sqlite3.connect('app/bdd_for_labels.db', check_same_thread=False) +c = conn.cursor() + +def get_file_content(filename): + '''For tests. Read file that contain user input. + ''' + my_file = open(filename, "r") + content = my_file.read() + content = content.split('\n') + my_file.close() + return (content) + +def put_labels_in_db(content, labels_table): + '''Send all labels contained in content if it doesn't exist + in labels table (in DB). If label line contain alias, just the + first alias is send. executemany() requiere 2D array. It's why + label is put in intermediate array 'inter'. + ''' + labels_name = [] + for line in content: + inter = [] + line = line.replace("\t", '') + line = line.split(',') + inter.append(line[0]) + if (is_in_labels_table(line[0], labels_table) != 1): + labels_name.append(inter) + c.executemany("INSERT INTO labels(name) VALUES(?)", labels_name) + conn.commit() + +def get_labels_table(): + '''Retrieve all the content in 'labels' from DB. + ''' + c.execute('SELECT * FROM labels') + all_table = c.fetchall() + return (all_table) + +def get_tab_alias_name(): + '''Select all alias in DB + ''' + c.execute('SELECT name FROM alias') + all_table = c.fetchall() + return (all_table) + +def is_in_labels_table(name, labels_table): + '''Return 1 if name is in 'labels' table or 0 if not. + ''' + name = name.lower() + for label in labels_table: + inter = label[1] + inter = inter.lower() + if (inter == name): + return (1) + return (0) + +def is_an_alias(name, tab_alias_name): + '''Return 1 if name is in 'alias' table or 0 if not. + ''' + name = name.lower() + for alias in tab_alias_name: + inter = alias[0] + inter = inter.lower() + if (inter == name): + return (1) + return (0) + +def is_alias_or_label(name, labels_table, tab_alias_name): + '''Return 1 if name is a label or and alias. + ''' + if (is_in_labels_table(name, labels_table) == 1): + return (1) + if (is_an_alias(name, tab_alias_name) == 1): + return (1) + return (0) + + +def get_last_element(tab): + '''Retrive the last element from the pile 'tab' because pop() + delete the last element when is it return. + ''' + for case in tab: + result = case + return (case) + +def get_father_id(father_name, labels_table): + '''Return the ID of an label stock in 'labels' table. + This ID will be send in 'father' column of the child. + ''' + for label in labels_table: + if (label[1] == father_name): + return (label[0]) + return (-1) + +def update_alias(content, labels_table, tab_alias_name): + '''Check the user input and add alias in alias tab if it's not + a label or an alias. + ''' + label_alias = [] + for line in content: + line = line.replace("\t", '') + line = line.replace(", ", ',') + line = line.split(',') + label = line[0] + line.remove(line[0]) + for alias in line: + inter = [] + if (is_alias_or_label(alias, labels_table, tab_alias_name) != 1): + inter.append(get_father_id(label, labels_table)) + inter.append(alias) + label_alias.append(inter) + c.executemany("INSERT INTO alias(id_label, name) VALUES(?, ?)", label_alias) + conn.commit() + +def update_father_id_in_db(content, labels_table): + '''Get the user input and with the number of '\t' behind label + dermine if the label is a father or a child. + If it's a child, the id of his father is send in his + 'father_id' column. + ''' + father_pile = ['no_father'] + prece = '' + for line in content: + line_alias = line.split(',') + label = line_alias[0] + if (line.count('\t') > prece.count('\t')): + father_pile.append(prece.replace("\t", '')) + if (line.count('\t') < prece.count('\t')): + nb_tour = prece.count('\t') - line.count('\t') + for i in range(0, nb_tour): + father_pile.pop() + father_name = get_last_element(father_pile) + father_id = get_father_id(father_name, labels_table) + if (father_id != -1): + c.execute('UPDATE labels SET father_id = ? WHERE name = ?', (father_id, label.replace("\t", ''))) + conn.commit() + prece = label + +def update_labels(content): + '''Get the user input and add new lables in 'labels' table of DB. + ''' + #content = get_file_content("labels") + content = content.split('\r\n') + labels_table = get_labels_table() + tab_alias_name = get_tab_alias_name() + put_labels_in_db(content, labels_table) + labels_table = get_labels_table() + update_father_id_in_db(content, labels_table) + update_alias(content, labels_table, tab_alias_name)