<commit_before>from flask import Flask, render_template, request, flash, redirect, url_for, jsonify
from flask_dropzone import Dropzone
from datetime import datetime
import json
from natsort import  natsorted, ns
import os
from loadClusters import *
#from script_fcs import *

app = Flask(__name__, static_folder="static")
dropzone = Dropzone(app)

# get the current folder
app.config['UPLOADED_PATH'] = os.getcwd()

# essa variável serve pra gente não ter que ficar rodando
# o servidor de novo toda hora
# por via das dúvidas dá um export nela tbm
DEBUG = True

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

@app.route('/', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        if(request.form['name'] == 'dataset'):
            print("request dataset")
            id = str(datetime.now().strftime('%d-%m-%Y/%H:%M:%S'))
            dir = '/uploaded-data/' + id

            if not os.path.exists(app.config['UPLOADED_PATH'] + dir):
                os.makedirs(app.config['UPLOADED_PATH'] + dir)

            for f in request.files.getlist('file'):
                print("request files: ", request.files)
                f.save(os.path.join(app.config['UPLOADED_PATH'] + dir, f.filename))

            datasetlocation = app.config['UPLOADED_PATH'] + dir + '/' + f.filename
            # lê número de objetos do dataset
            with open(datasetlocation) as f:
                numObj = sum(1 for _ in f)-1

            print("esse é um teste que eu gostaria de não estar fazendo às 3 da manhã")
            # caso 1: rodar os algoritmos em cima do dataset
            if(request.form['partition'] == 'no'):
                print("request.form['partition'] == 'no'")
                newdirectory = False
                if not os.path.exists(app.config['UPLOADED_PATH'] + '/algResult/'):
                    os.makedirs(app.config['UPLOADED_PATH'] + '/algResult/')
                    newdirectory = True

                if(newdirectory):
                    os.makedirs(app.config['UPLOADED_PATH'] + '/algResult/' + 'results-1/')
                    resultfolder = app.config['UPLOADED_PATH'] + '/algResult/' + 'results-1/'
                else:
                    # ordena as pastas e pega o número da última pra saber qual o
                    # número da pasta nova
                    root, dirs, files = next(os.walk(app.config['UPLOADED_PATH'] + '/algResult/'))
                    # natsorted serve para ordenar 10+
                    newdir = int((natsorted(dirs)[-1]).split("-")[1]) + 1
                    os.makedirs(app.config['UPLOADED_PATH'] + '/algResult/' + 'results-' + str(newdir))
                    # pasta para adicionar resultados tanto do clustering quanto do mocle
                    tail = 'algResult/' + 'results-' + str(newdir)
                    resultfolder = app.config['UPLOADED_PATH'] + tail

                if(request.form['basicSelected'] == 'yes' and request.form['mocleSelected'] == 'yes'):
                    print("CLUSTERING AND MOCLE SELECTED")
                    minK = int(request.form['minKBasic'])
                    maxK = int(request.form['maxKBasic'])

                    # crossover E ou P
                    tipoDistBasic = request.form['tipoDistBasic']
                    # algorithms (1, 2, 3, 4, 5, 6, 7)
                    # se composto, vem com virgula
                    alg = request.form['alg'].split(',')
                    print("alg", alg)
                    if len(alg) > 1:
                        for algnumber in alg:
                            print("algnumber: ", algnumber)
                            clustering(tipoDistBasic, numObj, minK, maxK, datasetlocation, resultfolder, int(algnumber))
                    else:
                        clustering(tipoDistBasic, numObj, minK, maxK, datasetlocation, resultfolder, int(alg[0]))

                    # crossover
                    # tratar: se M = 1 ou se B = 2
                    if(request.form['tipoDistMocle'] == 'M'):
                        crossover = 1
                    else:
                        crossover = 2
                    numGen = int(request.form['numGen'])
                    nearNeigh = int(request.form['nearNeigh'])
                    minK = int(request.form['minKMocle'])
                    maxK = int(request.form['maxKMocle'])
                    mocle(crossover, minK, maxK, datasetlocation, resultfolder + '/AllParts', resultfolder, datasetlocation, nearNeigh, numGen)
                # conferir no loadClusters como o caminho tá sendo pegado
            print("RESULT FOLDER GENERATE BASIC PARTITIONS: {}".format(resultfolder))
            loadCluster(tail)<commit_msg>ajuste pro caso de seleção apenas dos algoritmos básicos<commit_after>from flask import Flask, render_template, request, flash, redirect, url_for, jsonify
from flask_dropzone import Dropzone
from datetime import datetime
import json
from natsort import  natsorted, ns
import os
from loadClusters import *
#from script_fcs import *

app = Flask(__name__, static_folder="static")
dropzone = Dropzone(app)

# get the current folder
app.config['UPLOADED_PATH'] = os.getcwd()

# essa variável serve pra gente não ter que ficar rodando
# o servidor de novo toda hora
# por via das dúvidas dá um export nela tbm
DEBUG = True

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

@app.route('/', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        if(request.form['name'] == 'dataset'):
            print("request dataset")
            id = str(datetime.now().strftime('%d-%m-%Y/%H:%M:%S'))
            dir = '/uploaded-data/' + id

            if not os.path.exists(app.config['UPLOADED_PATH'] + dir):
                os.makedirs(app.config['UPLOADED_PATH'] + dir)

            for f in request.files.getlist('file'):
                print("request files: ", request.files)
                f.save(os.path.join(app.config['UPLOADED_PATH'] + dir, f.filename))

            datasetlocation = app.config['UPLOADED_PATH'] + dir + '/' + f.filename
            # lê número de objetos do dataset
            with open(datasetlocation) as f:
                numObj = sum(1 for _ in f)-1

            print("esse é um teste que eu gostaria de não estar fazendo às 3 da manhã")
            # caso 1: rodar os algoritmos em cima do dataset
            if(request.form['partition'] == 'no'):
                print("request.form['partition'] == 'no'")
                newdirectory = False
                if not os.path.exists(app.config['UPLOADED_PATH'] + '/algResult/'):
                    os.makedirs(app.config['UPLOADED_PATH'] + '/algResult/')
                    newdirectory = True

                if(newdirectory):
                    os.makedirs(app.config['UPLOADED_PATH'] + '/algResult/' + 'results-1/')
                    resultfolder = app.config['UPLOADED_PATH'] + '/algResult/' + 'results-1/'
                else:
                    # ordena as pastas e pega o número da última pra saber qual o
                    # número da pasta nova
                    root, dirs, files = next(os.walk(app.config['UPLOADED_PATH'] + '/algResult/'))
                    # natsorted serve para ordenar 10+
                    newdir = int((natsorted(dirs)[-1]).split("-")[1]) + 1
                    os.makedirs(app.config['UPLOADED_PATH'] + '/algResult/' + 'results-' + str(newdir))
                    # pasta para adicionar resultados tanto do clustering quanto do mocle
                    tail = 'algResult/' + 'results-' + str(newdir)
                    resultfolder = app.config['UPLOADED_PATH'] + tail

                if(request.form['basicSelected'] == 'yes' ):
                    print("CLUSTERING AND MOCLE SELECTED")
                    minK = int(request.form['minKBasic'])
                    maxK = int(request.form['maxKBasic'])

                    # crossover E ou P
                    tipoDistBasic = request.form['tipoDistBasic']
                    # algorithms (1, 2, 3, 4, 5, 6, 7)
                    # se composto, vem com virgula
                    alg = request.form['alg'].split(',')
                    print("alg", alg)
                    if len(alg) > 1:
                        for algnumber in alg:
                            print("algnumber: ", algnumber)
                            clustering(tipoDistBasic, numObj, minK, maxK, datasetlocation, resultfolder, int(algnumber))
                    else:
                        clustering(tipoDistBasic, numObj, minK, maxK, datasetlocation, resultfolder, int(alg[0]))

                elif(request.form['mocleSelected'] == 'yes'):
                    # crossover
                    # tratar: se M = 1 ou se B = 2
                    if(request.form['tipoDistMocle'] == 'M'):
                        crossover = 1
                    else:
                        crossover = 2
                    numGen = int(request.form['numGen'])
                    nearNeigh = int(request.form['nearNeigh'])
                    minK = int(request.form['minKMocle'])
                    maxK = int(request.form['maxKMocle'])
                    mocle(crossover, minK, maxK, datasetlocation, resultfolder + '/AllParts', resultfolder, datasetlocation, nearNeigh, numGen)
                # conferir no loadClusters como o caminho tá sendo pegado
            print("RESULT FOLDER GENERATE BASIC PARTITIONS: {}".format(resultfolder))
            loadCluster(tail)
{'fraction_non_alphanumeric': 0.11854745064921356, 'fraction_numerical': 0.005067032619022485, 'mean_word_length': 1.8121104185218166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2379518', 'n_tokens_mistral': 2827, 'n_tokens_neox': 2654, 'n_words': 678}