예제 #1
0
 def query_one(self, line):
     line = utils.clr(str(line))
     line_pre = utils.before_first_num(line)
     #fir_num= utils.first_numbers(line)
     res = self.word_filter(line_pre)
     res.extend(utils.numbers(line))
     comm_nbs = []
     for i in range(len(res)-1):
         print(res)
         try:
             #conn = nx.all_shortest_paths(self.graph.tree_di,res[i],res[i+1])
             comm_nbs.append(list(nx.common_neighbors(self.graph.di,res[i],res[i+1])))
         except:
             print("networkx error")
             continue
         #conn = nx.all_shortest_paths(self.graph.tree_di,res[i],res[i+1])
         comm_nbs.append(list(nx.common_neighbors(self.graph.di,res[i],res[i+1])))
     result = self.common_nbs(comm_nbs)
     _result = []
     for i in result:
         if not self.check_num(self.graph.sent[i],line):
             continue
         _result.append(self.graph.sent[i])
     return _result,res
예제 #2
0
        # check to see if login information matches
        hash_pwd = hashlib.sha224(form["pwd"].value).hexdigest()
        query2 = ("SELECT email_sec, email_pres, email_vp, password "
                  "FROM secretary WHERE password = %s AND email_sec = %s "
                  "OR password = %s AND email_pres = %s OR password = %s "
                  "AND email_vp = %s")
        cursor.execute(query2, (hash_pwd, form["email"].value, hash_pwd,
                       form["email"].value, hash_pwd, form["email"].value))
        rows = cursor.fetchall()
        cursor.close()

        # Incorrect Info, request login information again
        if rows == []:
            printPage("Incorrect Info")
        else:
            numbers("You are now logged in")

if "forgot" in form:
    # Create new, random-generated password
    import uuid
    password = str(uuid.uuid4())
    password = password.replace("-", "")
    password = password[0: 7]

    # send the password through email
    import smtplib
    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    message = "New Delta Text password: " + password
    hashed_pwd = hashlib.sha224(password).hexdigest()
예제 #3
0
def sort(array):
    if len(array) < 2:
        return array
    mid = len(array) // 2
    left = sort(array[:mid])
    right = sort(array[mid:])

    merged = []
    l = 0
    r = 0

    while l < len(left) and r < len(right):
        if left[l] < right[r]:
            merged += [left[l]]
            l += 1
        else:
            merged += [right[r]]
            r += 1

    if l < len(left):
        merged += left[l:]
    if r < len(right):
        merged += right[r:]

    return merged


if __name__ == "__main__":
    array = utils.numbers()
    print(sort(array))
예제 #4
0
    reader = csv.reader(data)
    with open('cleaned/acts_cleaned.csv', 'w', encoding='utf8') as out:
        writer = csv.writer(out)
        staff_map = utils.get_staff_map()
        clips = utils.get_clip_set()
        next(reader)

        added = set()

        for row in reader:
            name = utils.lettres(row[0]).lstrip()
            clipIds = re.split("\|", row[1][1:-1])
            chars = re.split("\|", row[2][1:-1])
            orders = re.split("\|", row[3][1:-1])
            addInfos = re.split("\|", row[4][1:-1])
            size = len(clipIds)
            if name in staff_map and len(chars) == size and len(
                    orders) == size and len(addInfos) == size:
                for i in range(size):
                    if clipIds[i] in clips:
                        staffid = staff_map[name]
                        clipId = clipIds[i]
                        pair = (staffid, clipId)
                        if pair not in added:
                            cha = utils.lettres(chars[i])
                            order = utils.numbers(orders[i])
                            addInf = utils.alet(addInfos[i])
                            writer.writerow(
                                (staffid, clipId, cha, order, addInf))
                            added.add(pair)
예제 #5
0
def show_grafo():

    words = request.args.getlist('word')
    date = request.args.get('date')
    accounts = request.args.getlist('account')
    polaridad = request.args.getlist('polaridad')

    tweets = get_filtros(words, date, accounts, polaridad)

    tweets_users = get_tweets_with_its_user(tweets)
    n = [{"tweets": t, "user": u} for t, u in zip(tweets, tweets_users)]

    # usuarios de los tweets
    userIds = []
    for tweet in tweets:
        userId = tweet['userId']
        if userId not in userIds:
            userIds.append(userId)

    users = []

    for userId in userIds:
        userInfo = searchUserId(userId)
        if len(userInfo) > 0:
            userTweets = []
            for tweet in tweets:
                if userId == tweet['userId']:
                    userTweets.append(tweet['text'])
            users.append({'user': '******' + userInfo[0]['screen_name'], 'tweets': userTweets})

    users2 = []

    for user in users:
        filtered = []
        for tweet in user['tweets']:
            words_text = list(tweet.split(" "))
            filtered.append(utils.remove_stop_words(words_text))
            palabras = filtered1(filtered)
            sin_num = utils.numbers(palabras)
            sin_imag = utils.https(sin_num)
            sin_puntos = utils.signos(sin_imag)
            sin_emojis = utils.emoji(sin_puntos)
        users2.append({'name': user['user'], 'words': sin_emojis})

    users3 = []
    for i in range(len(users2)):
        user1 = users2[i]
        words = []
        for j in range(len(users2)):
            user2 = users2[j]
            if i != j:
                for word in user1['words']:
                    for word2 in user2['words']:
                        if word.lower() == word2.lower() and word.lower() not in words and word != "":
                            words.append(word.lower())

        users3.append({'name': user1['name'], 'words': words})



    return {'tweets': n, 'data': users3}
예제 #6
0
def show_frecuencia():

    words = request.args.getlist('word')
    date = request.args.get('date')
    accounts = request.args.getlist('account')
    polaridad = request.args.getlist('polaridad')

    tweets = get_filtros(words, date, accounts, polaridad)
    users = get_tweets_with_its_user(tweets)
    n = [{"tweets": t, "user": u} for t, u in zip(tweets, users)]

    words3 = []
    counts = []
    for tweet in n:
        words2 = tweet["tweets"]["text"].split(" ")
        processedWords = utils.remove_stop_words(utils.emoji(utils.signos(utils.https(utils.numbers(words2)))))

        for word in processedWords:
            if word != '':
                if (word.lower() not in words3):
                    words3.append(word.lower())
                    counts.append(1)

                else:
                    index = words3.index(word.lower())
                    counts[index] += 1

    ans = [{"_id": word, "count": count} for word, count in zip(words3, counts)]
    fd = nltk.FreqDist(counts)
    freqq = []
    ans2 = []

    for item in ans:
        num = item['count']
        t = num/np.sum(counts)
        freqq.append(t)

    prom = np.mean(freqq)
    de = np.std(freqq)
    for item in ans:
        if freqq[ans.index(item)] > prom+de and item['_id'] not in words:
            ans2.append(item)

    return {"tweets": n, "data": ans2}
예제 #7
0
sys.setrecursionlimit(8000)

algs = [bubble, insertion, merge, quick, selection, shell]
batches = [125, 250, 500]  #, 1000, 2000, 4000, 8000]
iters = 3

results = []

for i in range(iters):
    results.append({})
    for alg in algs:
        results[i].update({alg.__name__: {}})
        print(results)
        for batch in batches:
            if alg == bubble and batch > 4000:
                break  # el temps d'execució és massa llarg

            unsorted = utils.numbers(max=batch, count=batch)

            start = time.perf_counter()
            alg.sort(unsorted)
            end = time.perf_counter()
            delta = end - start
            results[i][alg.__name__][batch] = delta
            print(i, alg.__name__, batch, delta)

print(results)

with open("./data/out.json", "w") as outfile:
    json.dump(results, outfile)
예제 #8
0
import csv
import unicodedata
import re
import utils

clips = utils.get_clip_set()

with open('initial/ratings.csv', encoding="utf8") as csvfile:
    reader = csv.reader(csvfile)
    next(reader)
    with open('cleaned/ratings_cleaned.csv', 'w', encoding="utf8") as out:
        wr = csv.writer(out)
        added = set()
        for row in reader:
            if row[0] in clips:
                clipid = row[0]
                # Only keep the numbers in the "Votes" column
                only_numbers = utils.numbers(row[1])
                # Only keep the doubles in the "Rank" column
                only_double = utils.double(row[2])
                if len(only_numbers) != 0 and only_numbers.lower(
                ) != 'null' and len(only_double) != 0 and only_double.lower(
                ) != 'null' and (clipid) not in added:
                    wr.writerow((clipid, only_numbers, only_double))
                    added.add((clipid))