Ejemplo n.º 1
0
 def __init__(self, _id=None, user_ids=[], messages=[], created_date=datetime.datetime.now(), name=None, last_logined=None):
     self._id = uuid.uuid4().hex if _id is None else _id
     self.user_ids = user_ids
     self.messages = messages
     self.created_date = created_date
     self.last_logined = last_logined
     id_gen_sid = shortid.ShortId()
     self.name = id_gen_sid.generate() if name is '' else name
Ejemplo n.º 2
0
def create_note(box_id):
    try:
        if request.method == 'POST':
            # getting forms
            share = request.form['inputGroupSelect01']

            # share label error handler
            try:
                share, share_only_with_users = share_bool_function(share)
            except ValueError:
                return render_template(
                    '/notes/create_note.html',
                    error_msg=
                    "You did not selected an Share label. Please select an Share label."
                )

            # getting title content and email
            title = request.form['title']
            content = request.form['content_'].strip('\n').strip('\r')
            author_email = session['email']

            # getting files and saving
            try:
                # getting files
                files = request.files.getlist('file')

                # # checking file size
                # file_size = 0
                # for file in files:
                #     file_size += file.seek(0, os.SEEK_END).tell()
                #
                # if file_size > 5e+8:
                #     flash('{ "message":"Too much files!", "type":"error" , "captaion":"File Overload Error", "icon_id": "fas fa-exclamation-triangle"}')

                # file length checker
                if len(files) > 5:
                    # flash("Too much files!")
                    flash(
                        '{ "message":"Too much files!", "type":"error" , "captaion":"File Overload Error", "icon_id": "fas fa-exclamation-triangle"}'
                    )

                    return render_template('/notes/create_note.html',
                                           title=title,
                                           content_=content,
                                           share=share)

                filenames = []
                for file in files:
                    if files and Note.allowed_file(file):
                        # create name for file
                        sid = shortid.ShortId()
                        # create path for file
                        file_path, file_extenstion = os.path.splitext(
                            file.filename)
                        filename = secure_filename(
                            sid.generate()) + file_extenstion

                        # os.chdir("static/img/file/")
                        # save file and add file to filenames list
                        file.save(os.path.join(filename))
                        filenames.append(filename)

                    # if extenstion is not supported
                    elif file is not None:
                        # flash("Sorry; your file's extension is supported.")
                        flash(
                            '{ "message":"Sorry; your file\'s extension is not supported", "type":"error" , "captaion":"File Extension Error", "icon_id": "fas fa-exclamation-triangle"}'
                        )

                        return render_template('/notes/create_note.html',
                                               title=title,
                                               content=content,
                                               share=share)
                    else:
                        filenames = []

            except:
                # file = None
                filenames = []

            # getting author nickname, label and user notes
            author_nickname = User.find_by_email(author_email).nick_name

            label = is_shared_validator(share, share_only_with_users)

            user_notes = Note.get_user_notes(session['email'])

            # if too much notes, then redirect
            if len(user_notes) > 20:
                # flash("You have the maximum amount of notes. Please delete your notes")
                flash(
                    '{ "message":"You have the maximum amount of notes. Please delete your notes", "type":"error" , "captaion":"Note Overload Error", "icon_id": "fas fa-exclamation-triangle"}'
                )

                return redirect(url_for(".user_notes", box_id=box_id))

            # saving note
            all_box_id = box_id
            note_id = uuid.uuid4().hex

            try:
                share_with_group = request.form['share_with_group']

                if share_with_group == 'on':
                    try:
                        user = User.find_by_id(session['_id'])
                        share_with_group = True
                        group = Group.find_by_id(user.group_id)
                        group.shared_notes.append({
                            'note_id': note_id,
                            'author': user._id
                        })
                        group.save_to_mongo()
                        group.update_to_elastic()
                    except:
                        # flash("You aren't in a group. Please join a group to share with group users.")
                        flash(
                            '{ "message":"You aren\'t in a group. Please join a group to share with group users.", "type":"info" , "captaion":"Group Share Error", "icon_id": "fas fa-exclamation-triangle"}'
                        )

                        return render_template('/notes/create_note.html',
                                               title=title,
                                               content=content,
                                               share=share)

                else:
                    share_with_group = False

            except werkzeug.exceptions.BadRequestKeyError:
                share_with_group = False

            else:
                share_with_group = False

            note_for_save = Note(_id=note_id,
                                 title=title,
                                 content=content,
                                 author_email=author_email,
                                 shared=share,
                                 author_nickname=author_nickname,
                                 share_only_with_users=share_only_with_users,
                                 share_label=label,
                                 file_name=filenames,
                                 box_id=all_box_id,
                                 share_with_group=share_with_group)
            note_for_save.save_to_mongo()
            note_for_save.save_to_elastic()
            if box_id is not None:
                box_for_save = Box.find_by_id(all_box_id)
                box_for_save.notes.append(note_id)
                box_for_save.save_to_mongo()
                box_for_save.update_to_elastic()

            # flash message and redirect
            # flash('Your note has successfully created.')
            flash(
                '{ "message":"Your note has successfully created.", "type":"success" , "captaion":"Note Saved", "icon_id": "far fa-save"}'
            )

            return redirect(url_for('.user_notes'))

        return render_template('/notes/create_note.html')

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(error_msg=''.join(error_msg),
                           error_location='create_note creating note')
        Error_obj.save_to_mongo()
        return render_template('base_htmls/error_page.html',
                               error_msgr='Crashed during saving your note...')
Ejemplo n.º 3
0
"""Core components for odin
"""
import os
import re
import inspect
import logging
from collections import defaultdict
from string import Template
from typing import Dict, Union, List, Tuple, Any, Optional
import yaml
import shortid
from baseline.utils import listify, is_sequence
from odin.dag import Graph

SHORT_ID = shortid.ShortId()
DEPENDENCY_KEY = 'depends'
TASK_LIST = 'tasks'
ROOT_PATH = 'ROOT_PATH'
WORK_PATH = 'WORK_PATH'
DATA_PATH = 'DATA_PATH'
RUN_PATH = 'RUN_PATH'
TASK_PATH = 'TASK_PATH'
PIPE_ID = 'PIPE_ID'
TASK_IDS = 'TASK_IDS'
TASK_ID = 'TASK_ID'
TASK_NAME = 'TASK_NAME'
K8S_NAME = re.compile(r"[a-z0-9-\.]+")
REFERENCE_KEY = re.compile(r"^\^")

LOGGER = logging.getLogger('odin')
Ejemplo n.º 4
0
def create_note():
    try:
        if request.method == 'POST':
            share = request.form['inputGroupSelect01']

            try:
                share, share_only_with_users = share_bool_function(share)
            except ValueError:
                return render_template('/notes/create_note.html',
                                       error_msg="You did not selected an Share label. Please select an Share label.")

            title = request.form['title']
            content = request.form['content'].strip('\n').strip('\r')
            author_email = session['email']
            try:
                files = request.files.getlist('file')

                if len(files) > 5:
                    flash("Too much files!")
                    return render_template('/notes/create_note.html'
                                           , title=title, content=content, share=share)

                filenames = []
                for file in files:
                    if files and Note.allowed_file(file):
                        sid = shortid.ShortId()
                        file_path, file_extenstion = os.path.splitext(file.filename)
                        filename = secure_filename(sid.generate()) + file_extenstion

                        # os.chdir("static/img/file/")
                        file.save(os.path.join(filename))
                        filenames.append(filename)

                    elif file is not None:
                        flash("Sorry; your file's extension is supported.")
                        return render_template('/notes/create_note.html'
                                               , title=title, content=content, share=share)
                    else:
                        filenames = []

            except:
                # file = None
                filenames = []

            author_nickname = User.find_by_email(author_email).nick_name

            label = is_shared_validator(share, share_only_with_users)

            user_notes = Note.get_user_notes(session['email'])

            if len(user_notes) > 20:
                flash("You have the maximum amount of notes. Please delete your notes")
                return redirect(url_for(".user_notes"))

            note_for_save = Note(title=title, content=content, author_email=author_email, shared=share,
                                 author_nickname=author_nickname, share_only_with_users=share_only_with_users,
                                 share_label=label, file_name=filenames)
            note_for_save.save_to_mongo()
            note_for_save.save_to_elastic()

            flash('Your note has successfully created.')

            return redirect(url_for('.user_notes'))

        return render_template('/notes/create_note.html')

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(error_msg=''.join(error_msg), error_location='create_note creating note')
        Error_obj.save_to_mongo()
        return render_template('error_page.html', error_msgr='Crashed during saving your note...')
Ejemplo n.º 5
0
def create_group():
    try:
        if request.method == 'GET':

            all_firends_diclist = gen_all_friends_diclist()

            return render_template('groups/create_group.html',
                                   all_firends=all_firends_diclist)

        if request.method == 'POST':
            user = User.find_by_id(session['_id'])

            name = request.form['name']
            members = request.form.getlist('members')
            members.append(user._id)
            group_img = request.files['file']

            description = request.form['description']
            share = request.form['inputGroupSelect01']
            try:

                if group_img is not None:
                    file_name, file_extenstion = os.path.splitext(
                        group_img.filename)
                    if file_extenstion not in ALLOWED_GROUP_IMG_FORMATS:
                        all_firends_diclist = gen_all_friends_diclist()
                        return render_template(
                            'groups/create_group.html',
                            all_firends=all_firends_diclist,
                            error_msg=
                            'Too much images!! Please upload just one image.',
                            name=name,
                            members=members,
                            share=share,
                            description=description)

                    # saving file
                    # create name for file
                    sid = shortid.ShortId()
                    # create path for file
                    file_path, file_extenstion = os.path.splitext(
                        group_img.filename)
                    filename = secure_filename(
                        sid.generate()) + file_extenstion

                    # os.chdir("static/img/file/")
                    # save file and add file to filenames list
                    group_img.save(os.path.join(filename))
                else:
                    filename = None
            except:
                group_img = None
                filename = None

            # saving group
            group_id = uuid.uuid4().hex

            group_for_save = Group(_id=group_id,
                                   name=name,
                                   members=[user._id],
                                   group_img_name=filename,
                                   shared=share,
                                   shared_notes=[],
                                   description=description)
            group_for_save.save_to_mongo()
            try:
                group_for_save.save_to_elastic()
            except:
                pass

            # # saving to user
            user.group_id = group_id
            user.save_to_mongo()

            # sending messages to users

            for member in members:
                message = Message(title='Do you want to join my group?',
                                  content='''
                    Join me on group {}!
                    If you want to join, please click the link below.
                '''.format(group_for_save.name),
                                  is_invtation=group_id,
                                  reciver_id=member,
                                  sender_id=user._id,
                                  sender_name=user.nick_name)
                try:
                    message.save_to_elastic()
                except:
                    pass
                message.save_to_mongo()

            # redirecting
            # flash('Successfully created group! | Sended invitations to users')
            flash(
                '{ "message":"Successfully created group! | Sended invitations to users", "type":"info" , "captaion":"Success", "icon_id": "fas fa-info-circle"}'
            )

            return redirect(url_for('groups.groups'))

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(error_msg=''.join(error_msg),
                           error_location='create_group creating group')
        Error_obj.save_to_mongo()
        return render_template(
            'base_htmls/error_page.html',
            error_msgr='Crashed during creating your group...')
Ejemplo n.º 6
0
1. vae evaluations
2. cliques
3. rate of saturation, density and volume
4. social interaction (uniform, density, frecency)
5. individual (interpolation, sampling)
6. individual (novelty preference vs no novelty preference)
"""

BATCH_SIZE = 32
TIMESTEPS = 16
MIDI_RANGE = range(24, 36)
DEPTH = len(MIDI_RANGE)
SAMPLES = 10000

sid = shortid.ShortId()
data_path = os.path.join(os.getcwd(), "data")


def is_pd(v):
    return isinstance(v, pd.DataFrame) or isinstance(v, pd.Series)


def make_entry(epoch, agent, artefact, z_mean):
    return {
        "epoch": epoch,
        "id": sid.generate(),
        "agent_id": agent.id,
        "artefact": np.argmax(artefact, axis=-1),
        "z_mean": z_mean
    }
Ejemplo n.º 7
0
 def __init__(self, config):
     self._L = getLogger()
     self.config = config
     self._shortid = shortid.ShortId()
     self.client = None
     self._connect()
Ejemplo n.º 8
0
def register_user():

    try:
        if request.method == 'POST':

            email = request.form['email']
            if email == '':
                # flash('Please type your email')
                flash(
                    '{ "message":"Please type your email", "type":"error" , "captaion":"Form Not Filled", "icon_id": "fas fa-exclamation-triangle"}'
                )

                return render_template("users/register.html")
            password = request.form['password']
            if password == '':
                # flash('Please type your password')
                flash(
                    '{ "message":"Please type your password", "type":"error" , "captaion":"Form Not Filled", "icon_id": "fas fa-exclamation-triangle"}'
                )

                return render_template("users/register.html")
            nick_name = request.form['nickname']
            file = request.files.get('file')

            if file and User.allowed_file(file):
                # create name for file
                sid = shortid.ShortId()
                # create path for file
                file_path, file_extenstion = os.path.splitext(file.filename)
                filename = secure_filename(sid.generate()) + file_extenstion

                # os.chdir("static/img/file/")
                # save file and add file to filenames list
                file.save(os.path.join(filename))

            # if extenstion is not supported
            elif file is not None:
                # flash("Sorry; your file's extension is supported.")
                flash(
                    '{ "message":"Sorry; your file\'s extension is supported.", "type":"error" , "captaion":File Extension Not Supported", "icon_id": "fas fa-exclamation-triangle"}'
                )

                return render_template("users/register.html")

            try:
                try:
                    if User.register_user(email, password, nick_name,
                                          filename):
                        user = User.find_by_email(email)
                        session['email'] = email
                        session['_id'] = user._id
                        session['pic_path'] = url_for(
                            'static', filename='img/index.jpg'
                        ) if user.picture is None else url_for(
                            'static', filename=user.picture)
                        session['group_id'] = user.group_id

                        return redirect(url_for("home"))
                except UnboundLocalError:
                    if User.register_user(email, password, nick_name):
                        user = User.find_by_email(email)
                        session['email'] = email
                        session['_id'] = user._id
                        session['pic_path'] = url_for(
                            'static', filename='img/index.jpg'
                        ) if user.picture is None else url_for(
                            'static', filename=user.picture)
                        session['group_id'] = user.group_id

                        return redirect(url_for("home"))

            except UserErrors.UserError as e:
                return e.message

        return render_template("users/register.html")

    except:
        error_msg = traceback.format_exc().split('\n')

        Error_obj = Error_(
            error_msg=''.join(error_msg),
            error_location='register_user while registering user')
        Error_obj.save_to_mongo()
        return render_template('base_htmls/error_page.html',
                               error_msgr='Crashed during registering you...')