Esempio n. 1
0
def main():

    path = './data/'

    # 1. Read data
    session_meta_map, session_message_map = import_data(path,
                                                        filter_mark=True,
                                                        print_mark=False)

    # 2.1 Statistics: Ratings
    # analyze_student_rating_distribution(session_meta_map, session_message_map)

    # 2.2 Statistics: Dialogue length
    # analyze_dialogue_duration_distribution(session_message_map)
    # analyze_dialogue_num_utterances_distribution(session_message_map)
    # analyze_dialogue_word_distribution(session_message_map)
    # analyze_dialogue_unique_word_distribution(session_message_map)

    # 2.3 Statistics: Activeness
    # analyze_tutor_utterances_fraction_distribution(session_message_map)
    # analyze_tutor_words_fraction_distribution(session_message_map)
    # analyze_tutor_new_words_fraction_distribution(session_message_map)

    # 2.4 Statistics: Platform experience
    # analyze_tutor_platform_exeperience_distribution(session_meta_map, session_message_map, 'tutor')
    # analyze_tutor_platform_exeperience_distribution(session_meta_map, session_message_map, 'student')

    # 3. Check dialogue examples
    # retrieve_dialogue_examples(session_meta_map, session_message_map)

    # 4. Generate frequent words/nouns
    # generate_word_frequency_map(session_message_map, path)
    generate_noun_frequency_map(session_message_map, path)
def main():

    path = './data/'

    # Read data
    session_meta_map, session_message_map = import_data(path,
                                                        filter_mark=True,
                                                        print_mark=False)

    # Retrieve failure/success groups
    def retrieve_session_group(session_meta_map, session_message_map, ratings):
        session_group = dict()
        session_id_set = set(session_message_map.keys())
        for session_id in session_id_set:
            student_rating = int(
                session_meta_map[session_id]['student_rating'])
            if student_rating in ratings:
                session_group[session_id] = dict()
                session_group[session_id]['student_rating'] = student_rating
        print("Group size is:\t%d" % len(session_group.keys()))
        return session_group

    failure_group = retrieve_session_group(session_meta_map,
                                           session_message_map, [1, 2])
    success_group = retrieve_session_group(session_meta_map,
                                           session_message_map, [4, 5])

    # Testing hypotheses
    '''
    test_hypothesis_efforts(session_message_map, failure_group, success_group)
    test_hypothesis_informativeness(session_message_map, failure_group, success_group, path)
    test_hypothesis_responsiveness(session_meta_map, session_message_map, failure_group, success_group)
    test_hypothesis_entrainment(session_message_map, failure_group, success_group, path)
    test_hypothesis_complexity(session_message_map, failure_group, success_group)
    test_hypothesis_questions(session_message_map, failure_group, success_group)
    test_hypothesis_sentiment(session_message_map, failure_group, success_group)
    '''
    test_hypothesis_platform_experience(session_meta_map, session_message_map,
                                        failure_group, success_group)
# In[3]:

label_names = [
    'no', 'yes', 'on', 'off', 'down', 'up', 'left', 'right', 'go', 'wow'
]

# In[5]:

import numpy as np
import functions as f

# In[6]:

X_train, y_train, X_test, y_test, fs = f.import_data(100,
                                                     10,
                                                     label_names=label_names)

# In[7]:

print('X_train: ', X_train.shape[0], X_train.shape[1])
print('y_train', y_train.shape[0])
print('X_test', X_test.shape[0], X_test.shape[1])
print('y_test', y_test.shape[0])

# In[8]:
"""execute this code!!!"""
np.savez_compressed('data100-10.npz',
                    X_train=X_train,
                    y_train=y_train,
                    X_test=X_test,
Esempio n. 4
0
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    func.add_score(message.author.id, 1, 1, fdata)

    # ----------------------------------------
    #               BALANCE
    # ----------------------------------------
    if message.content.startswith(PREFIX +
                                  'b') or message.content.startswith(PREFIX +
                                                                     '$'):
        target = message.author

        if len(message.mentions) > 0:
            if len(message.mentions) > 1:
                await client.send_message(
                    message.channel,
                    "Whoah, dude! One person at a time, please!")
                asyncio.sleep(2)
                await client.send_message(
                    message.channel,
                    "Showing you the results for {}...".format(
                        message.mentions[0]))
            target = message.mentions[0]
            print('{} has requested the balance of {}.'.format(
                message.author, message.mentions[0]))
        else:
            print('{} has requested the balance of themselves.'.format(
                message.author))

        await client.send_message(
            message.channel, func.make_balance(target.id, fdata, femoji,
                                               target))
        return

    # ----------------------------------------
    #               MARKET
    # ----------------------------------------
    if message.content.startswith(PREFIX + 'm'):

        # When a specific emoji has been chosen.
        if len(message.content.split(' ')) > 1:

            emoji = message.content.split(' ')[1]

            if func.isvalid(emoji, femoji) == True:
                await client.send_message(
                    message.channel, func.make_market_branch(emoji, fmarket))
            else:
                await client.send_message(
                    message.channel,
                    "I am terribly sorry! I couldn't recognize the emoji `{}`."
                    .format(emoji))

            return

        await client.send_message(message.channel,
                                  func.make_complete_market(femoji, fmarket))

    # ----------------------------------------
    #               BUY STUFF
    # ----------------------------------------
    if message.content.startswith('!bu'):

        message_table = message.content.split(' ')

        # Find all the valid emojis. If not, end with syntax error.
        if len(message_table) != 3:

            await client.send_message(
                message.channel,
                "**Invalid syntax:**\n\n`!buy <emoji> <amount>`.\n\nExample: `!buy {} 1`"
                .format(func.import_data(femoji)[0][0]))
            return

        if func.check_for_int(message_table[1]) == True and func.isvalid(
                message_table[2], femoji) == True:
            if int(message_table[1]) <= 0 or int(message_table[1]) > 1000000:
                await client.send_message(
                    message.channel,
                    "I'm sorry, your sell value is out of bounds! Please choose a reasonable amount."
                )
                return

            if func.count(message.author.id, 1, fdata) < int(message_table[1]):
                await client.send_message(
                    message.channel,
                    "I'm sorry! You do not have enough money to make this deal!"
                )
                return

            msg, person, amount = func.buy_something(message.author,
                                                     message_table[2],
                                                     int(message_table[1]),
                                                     femoji, fmarket, fdata)
            if person != '0':
                victim = await client.get_user_info(person)
                await client.send_message(
                    client.get_channel("438260494743109633"),
                    ":moneybag: **{}** bought {} from **{}** for the price of {} coins!"
                    .format(message.author, message_table[2], victim, amount))
                print("{} bought {} from {} for the price of {} coins!".format(
                    message.author, message_table[2], victim, amount))
            await client.send_message(message.channel, msg)
            return

        if func.check_for_int(message_table[2]) == True and func.isvalid(
                message_table[1], femoji) == True:
            if int(message_table[2]) <= 0 or int(message_table[2]) > 1000000:
                await client.send_message(
                    message.channel,
                    "I'm sorry, your sell value is out of bounds! Please choose a reasonable amount."
                )
                return

            if func.count(message.author.id, 1, fdata) < int(message_table[2]):
                await client.send_message(
                    message.channel,
                    "I'm sorry! You do not have enough money to make this deal!"
                )
                return

            msg, person, amount = func.buy_something(message.author,
                                                     message_table[1],
                                                     int(message_table[2]),
                                                     femoji, fmarket, fdata)
            if person != '0':
                victim = await client.get_user_info(person)
                await client.send_message(
                    client.get_channel("438260494743109633"),
                    ":moneybag: **{}** bought {} from **{}** for the price of {} coins!"
                    .format(message.author, message_table[1], victim, amount))
                print("{} bought {} from {} for the price of {} coins!".format(
                    message.author, message_table[1], victim, amount))
            await client.send_message(message.channel, msg)
            return

        await client.send_message(
            message.channel,
            "**Invalid syntax:**\n\n`!buy <emoji> <amount>`.\n\nExample: `!buy {} 1`"
            .format(func.import_data(femoji)[0][0]))
        return

    # ----------------------------------------
    #               SELL STUFF
    # ----------------------------------------
    if message.content.startswith('!s'):

        message_table = message.content.split(' ')

        # Find all the valid emojis. If not, end with syntax error.
        if len(message_table) != 3:

            await client.send_message(
                message.channel,
                "**Invalid syntax:**\n\n`!sell <emoji> <amount>`.\n\nExample: `!sell {} 100`"
                .format(func.import_data(femoji)[0][0]))
            return

        if func.check_for_int(message_table[1]) == True and func.isvalid(
                message_table[2], femoji) == True:
            if int(message_table[1]) <= 0 or int(message_table[1]) > 1000000:
                await client.send_message(
                    message.channel,
                    "I'm sorry, your sell value is out of bounds! Please choose a reasonable amount."
                )
                return

            if func.count(message.author.id,
                          func.position(message_table[2], femoji), fdata) < 1:
                await client.send_message(
                    message.channel,
                    "I'm sorry! You do not have the {} at your disposal to make this deal!"
                    .format(message_table[2]))
                return

            msg, person, amount = func.sell_something(message.author,
                                                      message_table[2],
                                                      int(message_table[1]),
                                                      femoji, fmarket, fdata)
            if person != '0':
                victim = await client.get_user_info(person)
                await client.send_message(
                    client.get_channel("438260494743109633"),
                    ":money_with_wings: **{}** sold {} to **{}** for {} coins!"
                    .format(message.author, message_table[2], victim, amount))
                print("{} sold {} to {} for {} coins!".format(
                    message.author, message_table[2], victim, amount))
            await client.send_message(message.channel, msg)
            return

        if func.check_for_int(message_table[2]) == True and func.isvalid(
                message_table[1], femoji) == True:
            if int(message_table[2]) <= 0 or int(message_table[2]) > 1000000:
                await client.send_message(
                    message.channel,
                    "I'm sorry, your sell value is out of bounds! Please choose a reasonable amount."
                )
                return

            if func.count(message.author.id,
                          func.position(message_table[1], femoji), fdata) < 1:
                await client.send_message(
                    message.channel,
                    "I'm sorry! You do not have the {} at your disposal to make this deal!"
                    .format(message_table[1]))
                return

            msg, person, amount = func.sell_something(message.author,
                                                      message_table[1],
                                                      int(message_table[2]),
                                                      femoji, fmarket, fdata)
            if person != '0':
                victim = await client.get_user_info(person)
                await client.send_message(
                    client.get_channel("438260494743109633"),
                    ":money_with_wings: **{}** sold {} to **{}** for {} coins!"
                    .format(message.author, message_table[1], victim, amount))
                print("{} sold {} to {} for the price of {} coins!".format(
                    message.author, message_table[1], victim, amount))
            await client.send_message(message.channel, msg)
            return

        await client.send_message(
            message.channel,
            "**Invalid syntax:**\n\n`!sell <emoji> <amount>`.\n\nExample: `!sell {} 100`"
            .format(func.import_data(femoji)[0][0]))
        return

    if message.content.startswith('!r'):

        if len(message.content.split(' ')) > 1:

            emoji = message.content.split(' ')[1]

            if func.isvalid(emoji, femoji) == True:

                await client.send_message(
                    message.channel,
                    'Are you sure you want to retract all offers and requests of the emoji {}?\nType `Yes` to confirm, or type `No` to cancel.'
                )
                response = await client.wait_for_message(author=message.author)

                if response.content.startswith(
                        'Y') or response.content.startswith('y'):
                    msg = func.retract_emoji(message.author, emoji, fmarket,
                                             femoji, fdata)
                    if msg != '':
                        await client.send_message(message.channel, msg)
                    await client.send_message(
                        message.channel, "{} has been cleared!".format(emoji))
                    await asyncio.sleep(1)
                    return

                await client.send_message(message.channel,
                                          "Retraction canceled.")
                return

        await client.send_message(
            message.channel,
            'Are you sure you want to retract all offers and requests on the *WHOLE* market?\nType `Yes` to confirm, or type `No` to cancel.'
        )
        response = await client.wait_for_message(author=message.author)

        if response.content.startswith('Y') or response.content.startswith(
                'y'):
            for emoji in func.import_data(femoji):
                msg = func.retract_emoji(message.author, emoji[0], fmarket,
                                         femoji, fdata)
                if msg != '':
                    await client.send_message(message.channel, msg)
                await client.send_message(
                    message.channel, "{} has been cleared!".format(emoji[0]))
                await asyncio.sleep(1)

            await client.send_message(message.channel,
                                      "All emojis have been cleared!")
            return

        await client.send_message(message.channel, "Retraction canceled.")
        return
Esempio n. 5
0
if args.verbose:
    if args.bert_path != None:
        logging.info(
            f"* loaded a bert model from {args.bert_path} and its tokenizer")
        if args.load_from:
            logging.info(f"* loaded a bert params from {args.load_from}")
    else:
        logging.info(f"* loaded {args.bert_model} model and its tokenizer")

# load data
if args.verbose:
    logging.info(f"loading data from {args.data_path}")
emo_mapping_e2i = {e: i for i, e in enumerate(emotions)}
target_emotion_idx = emo_mapping_e2i[args.target_emotion]
data, src_data, tgt_data = import_data(args.data_path, args.source,
                                       args.target, args.emotion,
                                       target_emotion_idx, tokenizer,
                                       args.max_len)
src_train, src_dev, src_test = src_data
tgt_train, tgt_dev, tgt_test = tgt_data

if args.few_shot:
    few_shot_train = import_fewshot_data(data[args.target], args.num_few_shot,
                                         target_emotion_idx, tokenizer)

# define loss functions
loss_fn_class = CrossEntropyLoss()
loss_fn_class_noreduce = CrossEntropyLoss(reduction="none")
loss_fn_domain = CrossEntropyLoss()
loss_fn_domain_joint = BCELoss()

# start training
Esempio n. 6
0
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    if int(message.author.id) not in authorized:
        func.add_score(message.author.id,1,1,fliving)

    # Makes sure the player is still alive or at least signed up (we do not want to give any spoilers!)
    if func.is_still_alive(message.author,fdata) and not int(message.author.id) in authorized:
        return

    if message.server == client.get_server("436257067573968908") and not message.channel == client.get_channel(play_zone) and message.content.startswith('!') and not int(message.author.id) in authorized:
        answer = await client.send_message(message.channel,"Wrong channel, buddy! Please go to <#{}> or to my DMs to play with the bot.".format(play_zone))
        await asyncio.sleep(10)
        await client.delete_message(answer)
        return

    # ----------------------------------------
    #               HELP
    # ----------------------------------------
    if message.content.startswith('!h') and not (message.channel == client.get_channel(game_log) or message.channel == client.get_channel(stock_market)):
        msg = ''
        args = message.content.split(' ')

        if len(args) == 1:
            msg += '`!balance` - View the balance of a user\n'
            msg += '`!buy` - Buy certain items'
            msg += '`!description` - View the meaning of all emojis\n'
            msg += '`!market` - View the market\n'
            msg += "`!retract` - Retract certain offers or requests you've made\n"
            msg += '`!sell` - Sell certain items\n'
            if int(message.author.id) in authorized:
                msg += '\n\n**Admin commands:**\n'
                msg += '`!kill` - Kill a player, effectively allowing them to participate on the market.\n'
                msg += '`!redeem` - Redeem a coin and make it invalid\n'
            msg += '\n To view the specific documentation of a command, please type `!help <command>`.'

        elif args[1].startswith('ba'):
            msg += '`!balance` - View your own balance.\n'
            msg += '`!balance <user>` - View the balance of a specific user. The user is a mention.'
        elif args[1].startswith('bu'):
            msg += '`!buy <emoji> <amount>` - Buy a certain emoji for a certain amount.'
        elif args[1].startswith('d'):
            msg += '`!description` - Get an explanation of what certain emojis mean.\n'
            msg += 'If a desciption reads **Player coin**, that means that the emoji is redeemed when the corresponding player dies.'
        elif args[1].startswith('m'):
            msg += '`!market` - See an overview of the whole market.\n'
            msg += '`!market <emoji> - See an overview of the market of a specific emoji. Make sure the emoji exists on the market.`'
        elif args[1].startswith('ret'):
            msg += "`!retract` - Retract all offers and requests you've made on the whole market.\n"
            msg += "`!retract` - Retract all offers and requests you've made on a specific emoji."
        elif args[1].startswith('s'):
            msg += '`!sell <emoji> <amount>` - Sell a certain emoji for a certain amount.'
        elif args[1].startswith('k'):
            if int(message.author.id) in authorized:
                msg += '`!kill <user> <emoji> <amount>` - Kill a user that got voted out by `<amount>` players. The user had `<emoji>` as their emoji in the game.'
            else:
                msg += "You're not even an admin! Why bother looking up this command?"
        elif args[1].startswith('red'):
            if int(message.author.id) in authorized:
                msg += '`!redeem <emoji> <amount>` - Remove a given emoji from the market, and pay all users a given amount for each emoji they had left.'
            else:
                msg += "You're not even an admin! Why bother looking up this command?"
        else:
            msg += "I am terribly sorry! I did not understand what command you meant to type!\n"
            msg += "Please type `!help` for help."

        await client.send_message(message.channel,msg)



    # ----------------------------------------
    #               DESCRIPTION
    # ----------------------------------------
    if message.content.startswith('!d'):
        await client.send_message(message.channel,func.show_desc(femoji))

    # ----------------------------------------
    #               KILL FUNCTION
    # ----------------------------------------
    if int(message.author.id) in authorized and message.content.startswith('!kill') and len(message.mentions) > 0:

        if len(message.content.split(' ')) != 4:
            await client.send_message(message.channel,"**Invalid syntax:**\n\n`!kill <player> <emoji> <amount>`.\n\nExample: `!kill @Randium#6521 😏 12`")
            return


        currency = message.content.split(' ')[2]
        amount = message.content.split(' ')[3]

        if not func.check_for_int(amount):
            await client.send_message(message.channel,"**ERROR:** Invalid amount!")
            return

        amount = int(amount)
        victim = message.mentions[0]

        if int(victim.id) in authorized:
            await client.send_message(message.channel,"I am terribly sorry, but I can't kill an admin! That'd be treason.")
            return

        await client.send_message(client.get_channel(bot_spam),"Are you sure you want to kill <@{}>?\nPlease type `Yes` to confirm.".format(victim.id))

        if func.isvalid(currency,femoji):
            await client.send_message(client.get_channel(bot_spam),"Careful! The emoji you gave up is still valid! You can override by typing `Yes`, but I would advise saying `No`!")
            await client.send_message(client.get_channel(bot_spam),"You can override emojis by typing `!redeem {} <amount>`.".format(currency))

        response = await client.wait_for_message(author = message.author,channel = client.get_channel(bot_spam))

        if not response.content[0] in ['y', 'Y']:
            await client.send_message(response.channel,"Kill function canceled.")
            return

        msg, money = func.kill(victim,fdata,fliving,femoji)
        await client.send_message(client.get_channel(bot_spam),msg)
        if msg[-1] == '!':
            msg = "Hey there, buddy! It seems like you have died!\n"
            msg += "Though the game may be over for you as a living player, it will still be very interesting for you while you're dead!"
            msg += " How so? Well, it is time to use your knowledge about the game to become the richest ghost of all!\n"
            msg += "Players weren't allowed to use the :ghost: emoji as their avatar. Why not? Because that emoji now has a meaning to the dead - it's ectoplasm."
            msg += " The money of the dead.\n\n"
            msg += "See, every player, every team has a type of coin. When a player dies, their coins will be exchanged for money."
            msg += " For example, when you died, your {} coin was exchanged for money.".format(currency)
            msg += " How much? Well, in total, {} players voted to kill you, so every player gained {} ectoplasm for each {} coin they had.\n\n".format(amount,100*amount,currency)
            msg += "Because of your activity, you will gain {} ectoplasm and 10 of every coin as a starter pack.".format(money)
            msg += " Buy and sell these coins on the market to get rich! The player who has the most ectoplasm at the end of the game, wins a special victory badge! Enjoy!"
            await client.send_message(victim,msg)
            await client.send_message(client.get_channel(game_log),"<@{}> has been killed.".format(victim.id))
        return

    # ----------------------------------------
    #               REDEEM COINS
    # ----------------------------------------
    if int(message.author.id) in authorized and message.content.startswith('!red'):
        if len(message.content.split(' ')) != 3:
            await client.send_message(message.channel,"**Invalid syntax:**\n\n`!redeem <emoji> <amount>`.\n\nExample: `!redeem 😏 12`")
            return

        currency = message.content.split(' ')[1]
        amount = message.content.split(' ')[2]

        if not func.check_for_int(amount) or not func.isvalid(currency,femoji):
            await client.send_message(message.channel,"**Invalid syntax:**\n\n`!redeem <emoji> <amount>`.\n\nExample: `!redeem 😏 12`")
            return

        amount = int(amount)

        await client.send_message(client.get_channel(bot_spam),"Are you sure you want to exchange the {} coin for {} ectoplasm?\nPlease type `Yes` to confirm.".format(currency,amount))

        response = await client.wait_for_message(author = message.author,channel = client.get_channel(bot_spam))

        if not response.content[0] in ['y', 'Y']:
            await client.send_message(response.channel,"Money redeem function canceled.")
            return

        score_table = func.import_data(fdata)

        for user in score_table:
            target = await client.get_user_info(user[0])
            user_amount = user[func.position(currency,femoji)]

            func.retract_emoji(target,currency,fmarket,femoji,fdata)

            user[1] = int(user[1]) + amount * int(user_amount)
            if int(user_amount) > 0:
                await client.send_message(target,"The emoji {} has been redeemed for {} ectoplasm! You had {} emojis, meaning that you gained {} coins.".format(currency,amount,user_amount,int(user_amount)*amount))
            user[func.position(currency,femoji)] = 0

        func.save(score_table,fdata)

        emojis = func.import_data(femoji)
        emojis[func.position(currency,femoji)-2][0] = 'N'
        func.save(emojis,femoji)

        await client.send_message(client.get_channel(game_log),"The emoji {} has been redeemed for {} ectoplasm.".format(currency,amount))
        print("The emoji {} has been cleared succesfully.".format(currency))
        await client.send_message(client.get_channel(bot_spam),"The emoji {} has been succesfully redeemed for {} per emoji!".format(currency,amount))
        return

    # ----------------------------------------
    #               BALANCE
    # ----------------------------------------
    if message.content.startswith('!ba'):
        target = message.author

        if len(message.mentions) > 0:
            if len(message.mentions) > 1:
                await client.send_message(message.channel,"Whoah, dude! One person at a time, please!")
                asyncio.sleep(2)
                await client.send_message(message.channel,"Showing you the results for {}...".format(message.mentions[0]))
            target = message.mentions[0]
            print('{} has requested the balance of {}.'.format(message.author,message.mentions[0]))
        else:
            print('{} has requested the balance of themselves.'.format(message.author))

        await client.send_message(message.channel,func.make_balance(target.id,fdata,femoji,target))
        return

    # ----------------------------------------
    #               MARKET
    # ----------------------------------------
    if message.content.startswith('!m'):

        # When a specific emoji has been chosen.
        if len(message.content.split(' ')) > 1:

            emoji = message.content.split(' ')[1]

            if func.isvalid(emoji,femoji) == True:
                await client.send_message(message.channel,func.make_market_branch(emoji,fmarket))
            else:
                await client.send_message(message.channel,"I am terribly sorry! I couldn't recognize the emoji `{}`.".format(emoji))

            return

        await client.send_message(message.channel,func.make_complete_market(femoji,fmarket))

    # ----------------------------------------
    #               BUY STUFF
    # ----------------------------------------
    if message.content.startswith('!bu'):

        message_table = message.content.split(' ')

        # Find all the valid emojis. If not, end with syntax error.
        if len(message_table) != 3:

            await client.send_message(message.channel,"**Invalid syntax:**\n\n`!buy <emoji> <amount>`.\n\nExample: `!buy {} 1`".format(func.import_data(femoji)[0][0]))
            return

        if func.check_for_int(message_table[1]) == True and func.isvalid(message_table[2],femoji) == True:
            if int(message_table[1]) <= 0 or int(message_table[1]) > 1000000:
                await client.send_message(message.channel,"I'm sorry, your sell value is out of bounds! Please choose a reasonable amount.")
                return

            if func.count(message.author.id,1,fdata) < int(message_table[1]):
                await client.send_message(message.channel,"I'm sorry! You do not have enough money to make this deal!")
                return

            msg, person, amount = func.buy_something(message.author,message_table[2],int(message_table[1]),femoji,fmarket,fdata)
            if person != '0':
                victim = await client.get_user_info(person)
                await client.send_message(client.get_channel(stock_market),":moneybag: **{}** bought {} from **{}** for the price of {} coins!".format(message.author,message_table[2],victim,amount))
                print("{} bought {} from {} for the price of {} coins!".format(message.author,message_table[2],victim,amount))
            await client.send_message(message.channel,msg)
            return

        if func.check_for_int(message_table[2]) == True and func.isvalid(message_table[1],femoji) == True:
            if int(message_table[2]) <= 0 or int(message_table[2]) > 1000000:
                await client.send_message(message.channel,"I'm sorry, your sell value is out of bounds! Please choose a reasonable amount.")
                return

            if func.count(message.author.id,1,fdata) < int(message_table[2]):
                await client.send_message(message.channel,"I'm sorry! You do not have enough money to make this deal!")
                return

            msg, person, amount = func.buy_something(message.author,message_table[1],int(message_table[2]),femoji,fmarket,fdata)
            if person != '0':
                victim = await client.get_user_info(person)
                await client.send_message(client.get_channel(stock_market),":moneybag: **{}** bought {} from **{}** for the price of {} coins!".format(message.author,message_table[1],victim,amount))
                print("{} bought {} from {} for the price of {} coins!".format(message.author,message_table[1],victim,amount))
            await client.send_message(message.channel,msg)
            return

        await client.send_message(message.channel,"**Invalid syntax:**\n\n`!buy <emoji> <amount>`.\n\nExample: `!buy {} 1`".format(func.import_data(femoji)[0][0]))
        return

    # ----------------------------------------
    #               SELL STUFF
    # ----------------------------------------
    if message.content.startswith('!s'):

        message_table = message.content.split(' ')

        # Find all the valid emojis. If not, end with syntax error.
        if len(message_table) != 3:

            await client.send_message(message.channel,"**Invalid syntax:**\n\n`!sell <emoji> <amount>`.\n\nExample: `!sell {} 100`".format(func.import_data(femoji)[0][0]))
            return

        if func.check_for_int(message_table[1]) == True and func.isvalid(message_table[2],femoji) == True:
            if int(message_table[1]) <= 0 or int(message_table[1]) > 1000000:
                await client.send_message(message.channel,"I'm sorry, your sell value is out of bounds! Please choose a reasonable amount.")
                return

            if func.count(message.author.id,func.position(message_table[2],femoji),fdata) < 1:
                await client.send_message(message.channel,"I'm sorry! You do not have the {} at your disposal to make this deal!".format(message_table[2]))
                return

            msg, person, amount = func.sell_something(message.author,message_table[2],int(message_table[1]),femoji,fmarket,fdata)
            if person != '0':
                victim = await client.get_user_info(person)
                await client.send_message(client.get_channel(stock_market),":money_with_wings: **{}** sold {} to **{}** for {} coins!".format(message.author,message_table[2],victim,amount))
                print("{} sold {} to {} for {} coins!".format(message.author,message_table[2],victim,amount))
            await client.send_message(message.channel,msg)
            return

        if func.check_for_int(message_table[2]) == True and func.isvalid(message_table[1],femoji) == True:
            if int(message_table[2]) <= 0 or int(message_table[2]) > 1000000:
                await client.send_message(message.channel,"I'm sorry, your sell value is out of bounds! Please choose a reasonable amount.")
                return

            if func.count(message.author.id,func.position(message_table[1],femoji),fdata) < 1:
                await client.send_message(message.channel,"I'm sorry! You do not have the {} at your disposal to make this deal!".format(message_table[1]))
                return

            msg, person, amount = func.sell_something(message.author,message_table[1],int(message_table[2]),femoji,fmarket,fdata)
            if person != '0':
                victim = await client.get_user_info(person)
                await client.send_message(client.get_channel(stock_market),":money_with_wings: **{}** sold {} to **{}** for {} coins!".format(message.author,message_table[1],victim,amount))
                print("{} sold {} to {} for the price of {} coins!".format(message.author,message_table[1],victim,amount))
            await client.send_message(message.channel,msg)
            return

        await client.send_message(message.channel,"**Invalid syntax:**\n\n`!sell <emoji> <amount>`.\n\nExample: `!sell {} 100`".format(func.import_data(femoji)[0][0]))
        return
    # ----------------------------------------
    #               RETRACT
    # ----------------------------------------

    if message.content.startswith('!ret'):

        if len(message.content.split(' ')) > 1:

            emoji = message.content.split(' ')[1]

            if func.isvalid(emoji,femoji) == True:

                await client.send_message(message.channel,'Are you sure you want to retract all offers and requests of the emoji {}?\nType `Yes` to confirm, or type `No` to cancel.')
                response = await client.wait_for_message(author = message.author)

                if response.content.startswith('Y') or response.content.startswith('y'):
                    msg = func.retract_emoji(message.author,emoji,fmarket,femoji,fdata)
                    if msg != '':
                        await client.send_message(message.channel,msg)
                    await client.send_message(message.channel,"{} has been cleared!".format(emoji))
                    await asyncio.sleep(1)
                    return

                await client.send_message(message.channel,"Retraction canceled.")
                return

        await client.send_message(message.channel,'Are you sure you want to retract all offers and requests on the *WHOLE* market?\nType `Yes` to confirm, or type `No` to cancel.')
        response = await client.wait_for_message(author = message.author)

        if response.content.startswith('Y') or response.content.startswith('y'):
            for emoji in func.import_data(femoji):
                msg = func.retract_emoji(message.author,emoji[0],fmarket,femoji,fdata)
                if msg != '':
                    await client.send_message(message.channel,msg)
                await client.send_message(message.channel,"{} has been cleared!".format(emoji[0]))
                await asyncio.sleep(1)

            await client.send_message(message.channel,"All emojis have been cleared!")
            return

        await client.send_message(message.channel,"Retraction canceled.")
        return
Esempio n. 7
0
count = 0
mun, state = {}, {}

# columns to name vars from CSV files
columns = ["locale","locale_type","codigo","life_ex_1991","life_ex_2000",\
           "life_ex_2010","inf_mortality_1991","inf_mortality_2000",\
           "inf_mortality_2010","MHDI_1991","MHDI_2000","MHDI_2010",\
           "MHDI_income_1991","MHDI_income_2000","MHDI_income_2010",\
           "MHDI_life_ex_1991","MHDI_life_ex_2000","MHDI_life_ex_2010",\
           "MHDI_education_1991","MHDI_education_2000","MHDI_education_2010",\
           "education_1991","education_2000","education_2010","income_1991",\
           "income_2000","income_2010"]

columns_small = ["locale","locale_type","codigo","life_ex_2000","life_ex_2010",\
                 "inf_mortality_2000","inf_mortality_2010","MHDI_2000","MHDI_2010",\
                 "MHDI_income_2000","MHDI_income_2010","MHDI_life_ex_2000",\
                 "MHDI_life_ex_2010","MHDI_education_2000","MHDI_education_2010",\
                 "education_2000","education_2010","income_2000","income_2010"]

# use data from 1991, 2000, 2010
# cities  = functions.import_data("data_cities.csv", columns, 5567)
# states = functions.import_data("data_states.csv", columns, 29)

# use data from 2000, 2010
# MAs     = functions.import_data("data_metro_areas.csv", columns_small, 22)
# regions = functions.import_data("data_regional_divisions.csv", columns_small, 187)
HDUs = functions.import_data("data_human_development_units.csv", columns_small,
                             11125)

chdir("/home/cree/workspace/econometrics/")
Esempio n. 8
0
from datetime import datetime, timedelta
import numpy as np
import functions as fn

test_date1 = datetime(year=2020, month=7, day=2)
test_date2 = datetime(year=2020, month=7, day=3)
df = fn.import_data(test_date1, test_date2, reduced=True)
print(df)
fn.generate_html_code_last_measured_data()
fn.output_htmldiv_single_graph(df, 'Temperature1')
fn.output_htmldiv_single_graph(df, 'Temperature2')

fn.create_html_page('html_output/index.html',
                    fn.name_htmldiv_single_graph(df, 'Temperature1'),
                    fn.name_htmldiv_single_graph(df, 'Temperature2'))
Esempio n. 9
0
    worldFiles, rainbowFiles, littleFiles
]
N_movements = len(folders)
N_ROW = 130  #mean_value(folders)
# nomi dei joint ordinati (saranno le colonne del dataset)
'''
jointName = ['SpineBase_x', 'SpineBase_y', 'SpineBase_z', 'SpineMid_x', 'SpineMid_y', 'SpineMid_z', 'Neck_x', 'Neck_y','Neck_z',
             'Head_x', 'Head_y', 'Head_z', 'ShoulderLeft_x', 'ShoulderLeft_y', 'ShoulderLeft_z', 'ElbowLeft',
             'WristLeft', 'HandLeft', 'ShoulderRight', 'ElbowRight', 'WristRight',
             'HandRight', 'HipLeft', 'KneeLeft', 'AnkleLeft', 'FootLeft',
             'HipRight', 'KneeRight', 'AnkleRight', 'FootRight', 'SpineShoulder',
             'HandTipLeft', 'ThumbLeft', 'HandTipRight', 'ThumbRight'] '''

# popolo il dataset prendendo i valori dai file
(datasetTrain, datasetTest, labelsTrain,
 labelsTest) = functions.import_data(folders, N_ROW)

#labelsTrain = [random.randint(0, 3) for i in len(labelsTrain)]
# effettuo i reshape necessari per darli in input alla rete neurale
Y_train = np_utils.to_categorical(labelsTrain)
Y_test = np_utils.to_categorical(labelsTest)

#model, score, pred = conv_model(datasetTrain, labelsTrain, datasetTest, labelsTest, N_ROW)
#ac = []

# model, score, pred = lstm_model(datasetTrain, labelsTrain, datasetTest, labelsTest, N_ROW, len(folders))
model = Sequential()

model.add(
    LSTM(64,
         input_shape=(N_ROW, 75),
Esempio n. 10
0
import pandas as pd
import numpy as np
from os import chdir
import functions

#improvements: change variable names to be more intuitive

chdir("/home/cree/Downloads/br_econ/")

count = 0
mun, state = {}, {}

mun = functions.import_data("mun")
state = functions.import_data("state")

chdir("/home/cree/workspace/econometrics/")

# municipal dataframes
mun_renda = functions.data_prep(mun.get('mun/Renda_municipios - Renda familiar - per capita - media.csv'))
mun_ensino = functions.data_prep(mun.get('mun/mun_media_anos_de_estudos_25_anos_+_todos.csv'))
mun_saude = mun.get('mun/mun_Mortalidade infantil (por mil nascidos vivos)_1970-2000.csv')
mun_populacao_censo  = functions.data_prep(mun.get('mun/populacao_municipal.csv'))
mun_renda_2, mun_ensino_2 = mun_renda.ix[3:].copy(),mun_ensino.ix[3:].copy()
mun_renda, mun_ensino = mun_renda.ix[:3],mun_ensino.ix[:3]

#state dataframes
state_renda = functions.data_prep(state.get('state/estado_Renda domiciliar per capita - media_1976 - 2014.csv'))
state_ensino = functions.data_prep(state.get('state/Anos de estudo - media - pessoas 25 anos e mais - 1981 - 2014.csv'))
state_ensino_mulheres = functions.data_prep(state.get('state/Anos de estudo - media - pessoas 25 anos e mais - mulheres 1981 -2014.csv'))
state_populacao_anual = functions.data_prep(state.get('state/populcao_estado_1980-2014.csv'))
state_populacao_censo = state.get('state/populacao_residente_estado_1970-2000.csv')
import functions as f

org_list = f.import_org_names()

for org in org_list:
    print(org)
    G, ess = f.import_data(org, 1)
    f.grapher(org, f.calc_centralities(G, org, 1), 5, ess)
    print(org)
Esempio n. 12
0
def main():
    
    path = './data/'
    
    # 1. Read data
    session_meta_map, session_message_map = import_data(path, filter_mark=True, print_mark=False)
Esempio n. 13
0
                    help='set the training batch size')
parser.add_argument('--hidden_units',
                    default=500,
                    type=int,
                    help='set the number of hidden units')
parser.add_argument('--epochs',
                    default=4,
                    type=int,
                    help='set the number of epochs to train for')
parser.add_argument('--gpu', action='store_true', help='train on a GPU')

# Get the args
args = parser.parse_args()

# Get some data ready for a PyTorch model
train_data, val_data, test_data, class_to_idx = functions.import_data(
    args.data_directory, args.batch_size, args.arch)

# Present the user settings for review
print()
print("Data Directory: {}".format(args.data_directory))
print("Save Directory: {}".format(args.save_dir))
print("Use GPU: {}".format(args.gpu))
print("PyTorch Architecture: {}".format(args.arch))
print()
print("<" + "-" * 10, "Hyperparameters", "-" * 10 + ">")
print("Hidden Units: {}".format(args.hidden_units))
print("Learning Rate: {}".format(args.learning_rate))
print("Epochs: {}".format(args.epochs))
print("Batch Size: {}".format(args.batch_size))
print()
#Calculates the centralities for all the organisms and stores it in centrality_data/org_name.cent
import functions as f

org_list = f.import_org_names()

for org_name in org_list:
    G, ess = f.import_data(org_name, 1)
    dicshs = f.calc_centralities(G, org_name, 1)
Esempio n. 15
0
# Calculates the p values for all the centralities and stores it in p_val_data/org_name.pval
import numpy as np 
import networkx as nx 
import random as rd 
import functions as f

#Modifiable variables
org_name=208963
string_version=1
niter=1000

string_location=f.string_version_data(string_version)[0]
G,ess=f.import_data(org_name,string_version)
dicshs=f.calc_centralities(G,org_name,string_version)
trimmed_G=f.trim_graph(G)
p_vals_mean={}
p_vals_med={}
P={}

for name in dicshs.keys():
	p_vals_mean[name]=0
	p_vals_med[name]=0
	P[name]=[]

print("\nCalculating p values")
for name,dic in dicshs.items():
	# print(name)
	P=[]
	c,sig=0,[]
	# print('Lenght of dic: %d'%(len(dic.keys())))
	for node in G.nodes():