def Notifier(url):
    # start counting the time
    begin_time = datetime.datetime.now()

    soup = utility.getSoup(url)
    # send an email to let the user know that everything is working in order
    message = "You have started the Drexel Course Availability program. You will receive updates on {} {} every {} hours.".format(
        utility.getData("Subject Code", soup),
        utility.getData("Course Number", soup), utility.NOTIFY_IN)
    utility.sendMessage("Course Availability Email", message)
    print("Checking for available seats every {} seconds...".format(
        utility.CHECK_EVERY))
    while True:
        soup = utility.getSoup(url)

        course = utility.getData("Subject Code", soup) + " " + \
            utility.getData("Course Number", soup)
        status = utility.getData("Enroll", soup)

        message = "\nStatus of " + course + ": " + status
        if status == "CLOSED":
            print("Status {}: {}".format(course, status))
            print()
        else:
            message += " of {} seats filled.\n\nRegister at {}".format(
                utility.getData("Max Enroll", soup), utility.REG_LINK)
            subject = "Seats for {} Available".format(course)
            print(message)
            utility.sendMessage(subject, message)
            break
        reset_time = updateNotification(begin_time, message, course)
        if reset_time:
            begin_time = datetime.datetime.now()

        sleep(utility.CHECK_EVERY)
コード例 #2
0

def costFunction(Y_Predicted, Y_Real):
    error = np.average(-Y_Real * (np.log(Y_Predicted)) -
                       (1 - Y_Real) * np.log(1 - Y_Predicted))
    return error


def optimiseTheta(X, Theta, Y_Real, Y_Predicted):
    X = np.transpose(X)
    e = Y_Real - Y_Predicted
    Theta += ALPHA * np.dot(X, e)
    return Theta


train_x, train_y = ut.getData(TRAIN_DIR)
train_x = np.array(train_x, np.float32)
train_y = np.array(train_y, np.float32)
train_x = ut.regulariseData(train_x)
train_x = ut.appendones(train_x)
theta = np.zeros((train_x.shape[1], 1))
theta = np.array(theta, np.float32)

for i in range(Num_Epoch):
    hypothesis = getHypothesis(theta, train_x)
    error = costFunction(hypothesis, train_y)
    theta = optimiseTheta(train_x, theta, train_y, hypothesis)
    print("Epoch = {} Error = {}".format(i, error))

print("Training Complete")
コード例 #3
0
def socketListening(UDP_IP, packet, addr):
    # Socket listenting
    print("Socket listening addr", addr)
    end = False

    # Getting packet and address of sender
    nextPacket = packet

    newSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    # try:
    dataId = utility.getPacketID(packet)

    readyPort = 0

    # Looking for port to bind
    if (not port_pool):
        print("Cannot bind socket")
    else:
        readyPort = port_pool.pop(0)
        print(readyPort)
        address = (UDP_IP, readyPort)
        print(address)
        newSock.bind(address)
        print("Created port on:", readyPort)

    nextAddr = addr

    # Processing file name
    fileName = utility.getData(packet)
    print("File name = ", fileName)

    checksum = utility.getChecksum(nextPacket)
    packetArray = bytearray(nextPacket)
    packetArray[5] = 0x00
    packetArray[6] = 0x00

    # Sending ACK and agreed port
    clientPort = (readyPort).to_bytes(2, byteorder='big')
    packet = utility.createPacketWithoutCheckSum(0x01, dataId, 0, clientPort)
    if (utility.countCheckSum(packetArray) == checksum):
        print("Sending packet to:", nextAddr)
        newSock.sendto(bytes(packet), nextAddr)
        print("Package return sent")
    else:
        print("Count checksum = ", utility.countCheckSum(packetArray))
        print("Checksum incorrect")

    nextPacket, nextAddr = newSock.recvfrom(utility.MAX_PACKET_SIZE)
    if (utility.getPacketType(nextPacket) == 2):
        end = True

    print(fileName)
    fileName = "received/" + fileName.decode("utf-8")
    if (os.path.exists(fileName)):
        os.remove(fileName)

    file = open(fileName, 'ab')
    copiedFile = bytearray()

    if utility.getPacketType(nextPacket) == 0:

        while not end:
            checksum = utility.getChecksum(nextPacket)
            packetArray = bytearray(nextPacket)
            packetArray[5] = 0x00
            packetArray[6] = 0x00

            # Sending ACK if file truly get
            if (utility.countCheckSum(packetArray) == checksum):
                newSock.sendto(bytes(utility.returnACK(nextPacket)), nextAddr)
                copiedFile += utility.getData(nextPacket)

            else:
                print("Count checksum = ", utility.countCheckSum(packetArray))
                print("Checksum incorrect")

            nextPacket, nextAddr = newSock.recvfrom(utility.MAX_PACKET_SIZE)
            if (len(copiedFile) >= 1000000):
                file.write(bytes(copiedFile))
                copiedFile = bytearray()

            if (utility.getPacketType(nextPacket) == 2):
                end = True

    end = False
    while not end:
        checksum = utility.getChecksum(nextPacket)
        packetArray = bytearray(nextPacket)
        packetArray[5] = 0x00
        packetArray[6] = 0x00

        # Sending ACK if file truly get
        if (utility.countCheckSum(packetArray) == checksum):
            copiedFile += utility.getData(nextPacket)
            end = True
        else:
            print("Count checksum = ", utility.countCheckSum(packetArray))
            print("Checksum incorrect")

    # Kirim FIN-ACK ke sender
    finale = utility.returnACK(nextPacket)
    newSock.sendto(bytes(finale), nextAddr)

    file.write(bytes(copiedFile))
    file.close()

    if readyPort != 0:
        port_pool.append(readyPort)

    # except:
    #     print("Error. Can't listen to the packet")

    # finally:
    #     print()
    #     newSock.close()

    return 0
from tabulate import tabulate


def getTimeAndDays(soup):
    table_data = soup.select("td")
    for td in table_data:
        if td.get_text()[-2:] == "pm" or td.get_text()[-2:] == "am":
            return td.get_text() + " - " + td.findNext('td').get_text()
    return None


url = course_url_finder.find()
soup = utility.getSoup(url)

class_details = [
    ["CRN ", utility.getData("CRN", soup)],
    ["Section ", utility.getData("Section", soup)],
    ["Credits ", utility.getData("Credits", soup)],
    ["Title ", utility.getData("Title", soup)],
    ["Campus ", utility.getData("Campus", soup)],
    ["Instructor ", utility.getData("Instructor(s)", soup)],
    ["Instruction Type ",
     utility.getData("Instruction Type", soup)],
    ["Instruction Method ",
     utility.getData("Instruction Method", soup)],
    ["Max Enroll ", utility.getData("Max Enroll", soup)],
    ["Enroll ", utility.getData("Enroll", soup)],
    ["Time and Days ", getTimeAndDays(soup)],
]

print(tabulate(class_details))
コード例 #5
0
from knn_classification import KNNClassification
from svm_classification import SVMClassification
from utility import getData
import numpy as np
from sklearn.model_selection import train_test_split

if __name__ == "__main__":
    x1 = getData("Dataset/train_images.mat")
    x2 = getData("Dataset/test_images.mat")
    y1 = getData("Dataset/train_labels.mat")
    y2 = getData("Dataset/test_labels.mat")
    FullImages = np.concatenate((x1, x2))
    FullLabels = np.concatenate((y1, y2))
    train_images, test_images, train_labels, test_labels = train_test_split(
        FullImages, FullLabels, test_size=1000, random_state=42)
    KNNClassification(train_images, train_labels, test_images, test_labels, 30,
                      2, 'new')
    SVMClassification(train_images, train_labels, test_images, test_labels,
                      'linear', 'new')
def main():
    X, Y = my_util.getData()
    model = ANN([500, 300])
    model.fit(X, Y)
コード例 #7
0
from utility import load_SVM, getData
from sklearn.metrics import accuracy_score, f1_score, recall_score, precision_score

if __name__ == "__main__":
    # train_images = getData("Dataset\\train_images.mat")
    # train_labels = getData("Dataset\\train_labels.mat")
    test_images = getData("Dataset/test_images.mat")
    test_labels = getData("Dataset/test_labels.mat")
    model = load_SVM()
    y_pred = model.predict(test_images)

    print "Precision"
    print precision_score(test_labels, y_pred, average='weighted')
    print "Recall"
    print recall_score(test_labels, y_pred, average='weighted')
コード例 #8
0
def sendFile(arr_file, UDP_IP, UDP_PORT, dataId):

    # Splitting files into packets
    dataArray = utility.fileSplitting(arr_file)
    manyPacket = len(dataArray)
    print(manyPacket)

    # Initial package sending... Give name
    fileName = ntpath.basename(arr_file)
    print("Trying to send packet")

    #try:
    # Binding socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.settimeout(5)
    i = 0
    while i < 20:
        try:
            address = (UDP_IP, 5021 + i + dataId)
            print("Trying to bind to", address)
            sock.bind(address)
            break
        except:
            i += 5

    if i >= 20:
        print("Socket is full. Unable to send file:", (dataId + 1))

    print("Socket is set")

    i = 0
    while i < 5:
        try:
            # Sending file name
            packet = createPacket(TYPE_DATA, dataId, 0,
                                  bytearray(fileName, "utf-8"))
            message = sendPacket(TYPE_DATA, packet, sock, (UDP_IP, UDP_PORT))
            target_port = utility.getData(message)
            target_port = int(target_port[0]) * 256 + int(target_port[1])
            break
        except:
            print("Socket timeout")
            print("Cannot get response from the server regarding target port")
            time.sleep(2)
            i += 1

    if i < 5:
        print("Received target port:", target_port)
    else:
        print("Receiver doesn't give port for communication")
        return 0

    # Initial call to print 0% progress
    utility.printProgressBar(0,
                             manyPacket,
                             prefix='Progress:',
                             suffix='Complete',
                             length=50)

    i = 0
    while (i < len(dataArray) - 1):
        try:
            packet = createPacket(TYPE_DATA, dataId, i, dataArray[i])
            sendPacket(TYPE_DATA, packet, sock, (UDP_IP, target_port))
            # Update Progress Bar
            time.sleep(0.1)
            utility.printProgressBar(i + 1,
                                     manyPacket,
                                     prefix='Progress:',
                                     suffix='Complete',
                                     length=50)
            i += 1
        except:
            print("Socket timeout")
            print("Error package sending at id =", dataId, "and sequence =", i,
                  " -- Sending package again")
            time.sleep(1)

    end = False
    while not end:
        try:
            packet = createPacket(TYPE_FIN, dataId, (len(dataArray) - 1),
                                  dataArray[len(dataArray) - 1])
            sendPacket(TYPE_FIN, packet, sock, (UDP_IP, target_port))
            # Update Progress Bar
            time.sleep(0.1)
            utility.printProgressBar(i + 1,
                                     manyPacket,
                                     prefix='Progress:',
                                     suffix='Complete',
                                     length=50)
            end = True
        except:
            print("Socket timeout")
            print("Error package sending at id =", dataId, "and sequence =",
                  (len(dataArray) - 1), " -- Sending package again")
            time.sleep(1)

    sock.close()