def toOsm(received_file):

    client = pymongo.MongoClient("mongodb://mongo:27017")
    setup_obj = setup(client)
    validate_obj = validator()

    if 'network_functions' in received_file:

        doc = setup_obj.db_descriptors["translated_nsd"]
        translated = setup_obj.translate_to_osm_nsd(received_file)

        check = validate_obj.osm_validator(translated)

        if check == "True":
            temp = doc.insert_one(translated)
            translated_ref = temp.inserted_id

    elif 'virtual_deployment_units' in received_file:

        doc = setup_obj.db_descriptors["translated_vnfd"]
        translated = setup_obj.translate_to_osm_vnfd(received_file)

        check = validate_obj.osm_validator(translated)

        if check == "True":
            temp = doc.insert_one(translated)
            translated_ref = temp.inserted_id

    return {"descriptor": translated, "VALIDATE STATUS": check}
def toSonata(received_file):

    client = pymongo.MongoClient("mongodb://mongo:27017")
    setup_obj = setup(client)
    validate_obj = validator()

    if 'vnfd:vnfd-catalog' in received_file:

        doc = setup_obj.db_descriptors["translated_vnfd"]
        translated = setup_obj.translate_to_sonata_vnfd(received_file)

        check = validate_obj.sonata_vnfd_validate(translated)

        if check == "True":
            temp = doc.insert_one(translated)
            translated_ref = temp.inserted_id

    elif 'nsd:nsd-catalog' in received_file:

        doc = setup_obj.db_descriptors["translated_nsd"]
        translated = setup_obj.translate_to_sonata_nsd(received_file)

        check = validate_obj.sonata_nsd_validate(translated)

        if check == "True":
            temp = doc.insert_one(translated)
            translated_ref = temp.inserted_id

    return {"descriptor": translated, "VALIDATE STATUS": check}
Exemple #3
0
    def validate(self):
        '''
            lists out the common and missing keys between a source descriptor and its 
            reverse translated descriptor.

        '''
        client = pymongo.MongoClient("mongodb://localhost:27017/")
        setup_obj = setup(client)

        uniques = []
        duplicates = []

        if 'virtual_deployment_units' in self.source:

            source_rev_trans = setup_obj.translate_to_sonata_vnfd(
                self.translated)
            result = pd.DataFrame(self.compare_dict(self.source,
                                                    source_rev_trans, 'root'),
                                  columns=['matched', 'missing', 'key'])
            return result

        elif 'network_functions' in self.source:

            source_rev_trans = setup_obj.translate_to_sonata_nsd(
                self.translated)
            result = pd.DataFrame(self.compare_dict(self.source,
                                                    source_rev_trans, 'root'),
                                  columns=['matched', 'missing', 'key'])
            return result

        elif 'vnfd:vnfd-catalog' in self.source:

            source_rev_trans = setup_obj.translate_to_osm_vnfd(self.translated)
            result = pd.DataFrame(self.compare_dict(self.source,
                                                    source_rev_trans, 'root'),
                                  columns=['matched', 'missing', 'key'])
            return result

        elif 'nsd:nsd-catalog' in self.source:

            source_rev_trans = setup_obj.translate_to_osm_nsd(self.translated)
            result = pd.DataFrame(self.compare_dict(self.source,
                                                    source_rev_trans, 'root'),
                                  columns=['matched', 'missing', 'key'])
            return result
def check_parameters(received_param):

    client = pymongo.MongoClient("mongodb://mongo:27017")
    set = setup(client)

    param = received_param['instruction']

    if param == "sonata_to_osm":

        rcvd_file = received_param['descriptor']
        ret_translated = toOsm(rcvd_file)

    elif param == "osm_to_sonata":

        rcvd_file = received_param['descriptor']
        ret_translated = toSonata(rcvd_file)

    return ret_translated
Exemple #5
0
Python library for the AR.Drone.

This module was tested with Python 2.6.6 and AR.Drone vanilla firmware 1.5.1.
"""

import socket
import struct
import sys
import threading
import multiprocessing

import arnetwork
import utilities

############# Setup ################
config = utilities.setup()

ARDRONE_ADDR = config['drone']['address']
ARDRONE_NAVDATA_PORT = config['drone']['navdata_port']
ARDRONE_VIDEO_PORT = config['drone']['video_port']
ARDRONE_COMMAND_PORT = config['drone']['command_port']
ARDRONE_EXT_CAM = config['drone']['external_cam']['active']
ARDRONE_EXT_CAM_PROTO = config['drone']['external_cam']['protocol']
ARDRONE_EXT_CAM_PORT = config['drone']['external_cam']['port']
ARDRONE_EXT_CAM_WIDTH = config['drone']['external_cam']['image_width']
ARDRONE_EXT_CAM_HEIGHT = config['drone']['external_cam']['image_height']


class ARDrone(object):
    """ARDrone Class.
Exemple #6
0
import robot
import utilities
import listener
import globals
import pictures
import regions

# TODO: Find a way to make the program save user files even if shell is closed


if __name__ == '__main__':
    # Ask the user how many games they want to play
    while True:
        try:
            globals.number_of_games_to_play = int(input("How many games do you want to play? "))
            if globals.number_of_games_to_play < 1 or globals.number_of_games_to_play > 100:
                raise ValueError
            break
        except ValueError:
            print("Invalid integer. The number must be in the range of 1-100.")

    # Perform setup
    utilities.setup()

    # Create listener thread
    listener.create_thread()

    # Run bot
    robot.run()
Exemple #7
0
#!/usr/bin/env python3

import utilities  # User defined module, has functions to read in data and display it properly

sequences = utilities.setup(
)  # Read in our data and return a list of three sequences

ATcontent = []  # Create a new list to hold AT content for our sequences

for seq in sequences:  # For every sequence in our list of sequences
    thisAT = 0  # Start a counter for the AT content of this sequence
    for base in seq:  # For every base in our sequence
        if base == 'A' or base == 'T':  # If the base is an 'A' or 'T'
            thisAT += 1  # Add one to our AT content counter
    thisAT = round(thisAT / len(seq) * 100.0,
                   2)  # Change our AT counter to reflect percent AT
    ATcontent.append(thisAT)  # Append the percent AT to our AT content list

utilities.showAT(
    ATcontent)  # Print the AT content to the screen all pretty-like
Exemple #8
0
def setup(args):
    utilities.setup(args)
    model = None
    with open(args.testModel, 'rb') as mod:
        model = pickle.load(mod)
    return model
Exemple #9
0
                        type=str,
                        help="Path to train data directory for training",
                        default="../train_data/")
    parser.add_argument('--trainModel',
                        type=str,
                        help="Name of model which training will produce",
                        default='model.pkl')
    parser.add_argument('-tD',
                        '--testData',
                        type=str,
                        help="Path to test image for testing",
                        default='../raw/')
    parser.add_argument('-tM',
                        '--testModel',
                        type=str,
                        help="Path to pickle model for testing",
                        default='model.pkl')
    parser.add_argument('-t',
                        '--threshold',
                        type=float,
                        default=1.2,
                        help='Face recognition threshold for facenet')
    parser.add_argument('-v', '--verbose', action='store_true')
    args = parser.parse_args()
    if (args.type == "train"):
        utilities.setup(args)
        utilities.train(args)
    else:
        model = setup(args)
        print(run(model, args.testData, args.threshold))
Exemple #10
0
 def __init__(self, base_speed=30):
     self.nano = setup()
     self.base_speed = base_speed
#!/usr/bin/env python3

import utilities  # Import user-defined module

sequences = utilities.setup()  # Setup or list of sequences

checkAT = lambda base: base == 'A' or base == 'T'  # Lambda expression to check a single base to see if we have an 'A' or a 'T'
getAT = lambda sequence: round(
    sum(map(checkAT, sequence)) / len(sequence) * 100, 2
)  # A lambda expression that maps the first lambda expression to a sequence. Since Python converts `True' to 1 and `False' to 0, we use `sum' to add up all of the `Trues', divide it by the length of the sequence, converts it to a percentage, and rounds to two decimal places
allAT = list(
    map(getAT, sequences)
)  # Map the second lambda expression to all sequences provided and make a list out of it

utilities.showAT(
    allAT
)  # Special `print' wrapper that makes the AT content all nice and pretty
#!/usr/bin/env python3

import utilities # User defined module, has functions to read in data and display it properly

sequences = utilities.setup() # Read in our data and return a list of three sequences

ATcontent = [] # Create a new list to hold AT content for our sequences

for seq in sequences: # For every sequence in our list of sequences
    thisAT = 0 # Start a counter for the AT content of this sequence
    for base in seq: # For every base in our sequence
            if base == 'A' or base == 'T': # If the base is an 'A' or 'T'
                    thisAT += 1 # Add one to our AT content counter
    thisAT = round(thisAT / len(seq) * 100.0, 2) # Change our AT counter to reflect percent AT
    ATcontent.append(thisAT) # Append the percent AT to our AT content list

utilities.showAT(ATcontent) # Print the AT content to the screen all pretty-like
Exemple #13
0
#!/usr/bin/env python3

#   Import modules from the standard Python library
import re # Import the regex module, this is for something later on

#   Import user defined modules
import utilities

#   Setup our data and get some translation tables
header, sequence, seq50 = utilities.setup()
nucleotide_table, protein_dictionary = utilities.make_trans()

#   We have a fasta file containing a region of chromosome 10 of Zea mays
#   There are several things that this code will do once complete

print("The first 50 nucleotides of this FASTA sequence are:")
print(seq50)
print("\n")

#   First, the sequence is in lowercase; convert the sequence to all uppercase and print off the first 50 nucleotides
#       Use the upper method of the string `sequence' to do this; store this as the variable sequence
#       Remember: Python starts counting at 0 and slices are partially inclusive

# Use the upper method to change the sequence in to uppercase

print("The first 50 nucleotides in upper case are:")
# Print the first 50 nucleotides of the sequence in uppercase
print("\n")


#   Second, is to get the length of the sequence using the `len()' function
#!/usr/bin/env python3

import utilities # Import user-defined module

sequences = utilities.setup() # Setup or list of sequences

checkAT = lambda base : base == 'A' or base == 'T' # Lambda expression to check a single base to see if we have an 'A' or a 'T'
getAT = lambda sequence : round(sum(map(checkAT, sequence))/len(sequence)*100, 2) # A lambda expression that maps the first lambda expression to a sequence. Since Python converts `True' to 1 and `False' to 0, we use `sum' to add up all of the `Trues', divide it by the length of the sequence, converts it to a percentage, and rounds to two decimal places
allAT = list(map(getAT, sequences)) # Map the second lambda expression to all sequences provided and make a list out of it

utilities.showAT(allAT) # Special `print' wrapper that makes the AT content all nice and pretty
Exemple #15
0
                'Thank you! I quite enjoy your company as well.',
                'That just made my day. I hope yours goes well too.',
                'It\'s very nice to be appreciated. Let\'s do our best!'
            ]))
    if python_pattern.match(message.content):
        await message.channel.send(
            file=discord.File('./emotions/happy.png', 'happy.png'))
        await message.channel.send(
            "I am also quite pleased at the good work he did in my absence.")
    if forsyth_pattern.match(message.content) and str(
            message.author) == 'codefreak8#5021':
        await message.channel.send(
            file=discord.File('./emotions/upset.png', 'upset.png'))
        await message.channel.send("Sure you do, Code.")
    if forsyth_pattern.match(message.content):
        await message.channel.send(
            file=discord.File('./emotions/happy.png', 'happy.png'))
        await message.channel.send(
            "I am sure could spare some orbs for him, then.")
    await bot.process_commands(message)


token = os.environ.get('TOKEN', default=None)
if token is None:
    token = open('./token').read().replace('\n', '')

utilities.setup(bot)
dl.setup(bot)

bot.run(token)
Exemple #16
0
 def __init__(self, base_speed):
     self.nano = setup()
     self.motor = Motor(nano=self.nano, base_speed=base_speed)
     self.lcd = LCD()