<commit_before>import os, inspect
from datetime import datetime
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand

app = inspect.getmodule(inspect.stack()[1][0]).app
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)

class Users(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False, unique=True)
    screen_name = db.Column(db.String(255), nullable=False)
    icon_path = db.Column(db.String(2047), nullable=True, default=None)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    bio = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    twitter_id = db.Column(db.String(255), nullable=True, default=None)

    def __init__(self, name, screen_name):
        self.screen_name = screen_name
        self.name = name
        self.created_at = datetime.now()

class Rhythms(db.Model):
    __tablename__ = 'rhythms'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    data = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    tag = db.Column(db.String(2047), nullable=True, default=None)
    desc = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    media_path = db.Column(db.String(255), nullable=True, default=None)

class Chords(db.Model):
    __tablename__ = 'chords'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    data = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    tag = db.Column(db.String(2047), nullable=True, default=None)
    desc = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    media_path = db.Column(db.String(255), nullable=True, default=None)

class Accoms(db.Model):
    __tablename__ = 'accoms'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    data = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    tag = db.Column(db.String(2047), nullable=True, default=None)
    desc = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    media_path = db.Column(db.String(255), nullable=True, default=None)

class Drums(db.Model):
    __tablename__ = 'drums'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    data = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    tag = db.Column(db.String(2047), nullable=True, default=None)
    desc = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    media_path = db.Column(db.String(255), nullable=True, default=None)

class Musics(db.Model):
    __tablename__ = 'musics'
    id = db.Column(db.Integer, primary_key=True)<commit_msg>Add init db script<commit_after>import os, inspect, json
from datetime import datetime
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand

import melete.chord as Chord
import melete.rhythm as Rhythm

app = inspect.getmodule(inspect.stack()[1][0]).app
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)

@manager.command
def seed():
    "Import system data"

    admin = Users('admin', 'admin')
    db.session.add(admin)
    db.session.commit()

    pat = [[], [0], [0, 96], [0, 48, 96], [0, 48, 96, 144]]
    tree = Rhythm.RhythmTree(48, 1, Rhythm.TimeSignature(4, 2), pat)
    rhythm = Rhythms('Rhythm 1', json.dumps(tree.to_dict()), admin.id)

    f7 = Chord.Chord.from_name('FM7')
    gd7 = Chord.Chord.from_name('G7')
    em7 = Chord.Chord.from_name('Em7')
    am = Chord.Chord.from_name('Am')
    prog = Chord.ChordProg(48, 4, [(f7, 0), (gd7, 192), (em7, 384), (am, 576)])
    chord = Chords('Chord 1', json.dumps(prog.to_dict()), admin.id)

    db.session.add(rhythm)
    db.session.add(chord)
    db.session.commit()

class Users(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False, unique=True)
    screen_name = db.Column(db.String(255), nullable=False)
    icon_path = db.Column(db.String(2047), nullable=True, default=None)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    bio = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    twitter_id = db.Column(db.String(255), nullable=True, default=None)

    def __init__(self, name, screen_name):
        self.screen_name = screen_name
        self.name = name
        self.created_at = datetime.now()

class Rhythms(db.Model):
    __tablename__ = 'rhythms'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    data = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    tag = db.Column(db.String(2047), nullable=True, default=None)
    desc = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    media_path = db.Column(db.String(255), nullable=True, default=None)

    def __init__(self, name, data, user_id):
        self.name = name
        self.data = data
        self.user_id = user_id

class Chords(db.Model):
    __tablename__ = 'chords'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    data = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    tag = db.Column(db.String(2047), nullable=True, default=None)
    desc = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    media_path = db.Column(db.String(255), nullable=True, default=None)

    def __init__(self, name, data, user_id):
        self.name = name
        self.data = data
        self.user_id = user_id

class Accoms(db.Model):
    __tablename__ = 'accoms'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    data = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    tag = db.Column(db.String(2047), nullable=True, default=None)
    desc = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    media_path = db.Column(db.String(255), nullable=True, default=None)

class Drums(db.Model):
    __tablename__ = 'drums'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    data = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=None)
    tag = db.Column(db.String(2047), nullable=True, default=None)
    desc = db.Column(db.String(1023), nullable=True, default=None)
    status = db.Column(db.String(255), nullable=True, default=None)
    media_path = db.Column(db.String(255), nullable=True, default=None)

class Musics(db.Model):
    __tablename__ = 'musics'
    id = db.Column(db.Integer, primary_key=True)
{'fraction_non_alphanumeric': 0.1492767370168366, 'fraction_numerical': 0.026796300687692672, 'mean_word_length': 4.386334610472542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6226198', 'n_tokens_mistral': 3169, 'n_tokens_neox': 2999, 'n_words': 553}