Beispiel #1
0
async def note(ctx, name):
    name = name.lower().replace(" ", "-")
    content = Notes(getPath(ctx)).get(name)
    if content:
        message = content
    else:
        message = f"Note “{name}” does not exist.\nUse `!notes` to get a list of available notes."

    await ctx.send(message)
Beispiel #2
0
async def notes(ctx):
    # TODO: Make this an embed so commands to read each note can be embedded in
    #       notes names (not sure that's possible)

    notes = Notes(getPath(ctx)).getAll()
    if notes:
        message = "Here are the notes available to read:\n\n"
        for name in notes.keys():
            message += f"* {name}\n"

        message += "\nUse `!note <name>` to read a note!"
    else:
        message = "There are no notes! You can add one with `!writenote <name> <content>`."

    await ctx.send(message)
Beispiel #3
0
async def deletenote(ctx, name):
    name = name.lower().replace(" ", "-")
    notes = Notes(getPath(ctx))

    if not name.replace("-", "").replace("_", "").isalpha():
        await ctx.send("Note name can only contain letters, “-” and “_”.")
        return

    if notes.delete(name):
        message = f"Note “{name}” successfully deleted!"
        print(
            f"Deleted note “{name}” on server “{ctx.guild.name}” ({ctx.guild.id})")
    else:
        message = f"Note {name} does not exist.\nUse `!notes to get a list of available notes."

    await ctx.send(message)
Beispiel #4
0
async def writenote(ctx, *, args):
    try:
        (name, content) = args.split(maxsplit=1)
    except ValueError:
        await ctx.send("You must provide a content for the note.\nUsage: `!writenote <name> <content>`")
        return

    if not name.replace("-", "").replace("_", "").isalpha():
        await ctx.send("Note name can only contain letters, “-” and “_”.")
        return

    name = name.lower().replace(" ", "-")
    content = content.strip()
    if len(name) > 30:
        await ctx.send("Note name cannot exceed 30 characters.")
        return

    # Write notes to file
    notes = Notes(getPath(ctx))
    notes.write(name, content)
    print(
        f"Wrote note “{name}” on server “{ctx.guild.name}” ({ctx.guild.id}): {content}")

    await ctx.send(f"Successfully wrote note “{name}”, use `!note {name}` to read it!")
Beispiel #5
0
from sklearn.model_selection import train_test_split
import helpers
import argparse
from sliding_window import localize_and_classify
from PIL import Image
import numpy as np
import os
import cv2

# Find paths and labels
dir_dataset = helpers.getPath()
filenames = helpers.getFilenames(dir_dataset)
labels = helpers.getLabels(dir_dataset)

# Flatten the data set
print("> ------ SVM classifier ------")
print("> Collecting Image data ...")
X, y = helpers.flattenImages(filenames, labels)

print("> Splitting train and test data ...")
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)

print("> Preprocess data ...")
X_train_HOG = helpers.SVM_preProcessing(X_train)#[0:5000])
X_test_HOG = helpers.SVM_preProcessing(X_test)#[0:2000])

print("> Creating a model ...")
# hog  pca = 70, kernel='rbf', C=5, gamma=0.16 leads to good results.
svc_clf = helpers.SVM_getModel(X_train_HOG,  y_train)#[0:6000])

# Train the classifier
import matplotlib.pyplot as plt
import helpers
import os 
import numpy as np

# Check to analyze one graph or all graphs in directory
method = input("Do you want to analyze 1 graph or all? (0 for all)\n")

# For one file
if method == '1':

    # Get path and check if is file
    path = helpers.getPath("What's the .tData file path?\n", True)
    title = os.path.basename(path).split('.')
    fileData = helpers.grabData(path)
    if(len(fileData) == 0):
        exit(0)

    # Store the data 
    groups = len(fileData)       
    tempLabels = []
    tempSearches = []
    tempTotals = []
    for data in fileData:
        tempSearches.append(data[1][0])
        tempTotals.append(data[1][1])
        tempLabels.append(data[0])

    # Plot data
    fig, ax = plt.subplots()
    index = np.arange(groups)