<commit_before>from flask import g
from visual import db
from visual.utils import AutoSerialize
from visual.attrs.models import Bra, Isic, Hs, Cbo, Wld

import ast

build_ui = db.Table('apps_build_ui',
         db.Column('build_id', db.Integer,db.ForeignKey('apps_build.id')),
         db.Column('ui_id', db.Integer,db.ForeignKey('apps_ui.id'))
)

class App(db.Model, AutoSerialize):

    __tablename__ = 'apps_app'
    
    id = db.Column(db.Integer, primary_key = True)
    type = db.Column(db.String(20))
    title = db.Column(db.String(20))
    viz_whiz = db.Column(db.String(20))
    color = db.Column(db.String(7))

class Build(db.Model, AutoSerialize):

    __tablename__ = 'apps_build'
    __public__ = ('id', 'type', 'bra', 'filter1', 'filter2', 'output', 'viz_whiz', 'name', 'color', 'dataset')
    
    id = db.Column(db.Integer, primary_key = True)
    dataset = db.Column(db.String(20))
    bra = db.Column(db.String(20))
    filter1 = db.Column(db.String(20))
    filter2 = db.Column(db.String(20))
    output = db.Column(db.String(20))
    title_en = db.Column(db.String(120))
    title_pt = db.Column(db.String(120))
    app_id = db.Column(db.Integer, db.ForeignKey(App.id))
    
    ui = db.relationship('UI', secondary=build_ui, 
            backref=db.backref('Builds'), lazy='dynamic')
    app = db.relationship('App',
            backref=db.backref('Builds', lazy='dynamic'))
    
    def get_ui(self, ui_type):
        return self.ui.filter(UI.type == ui_type).first()

    def set_bra(self, bra_id):
        self.bra = []
        if bra_id == "all":
            self.bra.append(Wld.query.get("sabra"))
            self.bra[0].id = "all"
            self.bra[0].icon = "/static/img/icons/wld/wld_sabra.png"
        else:
            for i, b in enumerate(bra_id.split("+")):
                self.bra.append(Bra.query.get(b))
                self.bra[i].icon = "/static/img/icons/bra/bra_{0}.png".format(b[:2])

    def set_filter1(self, filter):
        if self.filter1 == "all":
            self.filter1 = "all"
        elif self.dataset == "rais":
            self.isic = []
            for i, f in enumerate(filter.split("+")):
                if Isic.query.get(f):
                    self.isic.append(Isic.query.get(f))
                else:
                    self.isic.append(Isic.query.get('c1410'))
        elif self.dataset == "secex":
            self.hs = []
            for i, f in enumerate(filter.split("+")):
                if Hs.query.get(f):
                    self.hs.append(Hs.query.get(f))
                else:
                    self.hs.append(Hs.query.get('178703'))
        self.filter1 = filter
    
    def set_filter2(self, filter):
        if self.filter2 == "all":
            self.filter2 = "all"
        elif self.dataset == "rais":
            self.cbo = []
            for i, f in enumerate(filter.split("+")):
                if Cbo.query.get(f):
                    self.cbo.append(Cbo.query.get(f))
                else:
                    self.cbo.append(Cbo.query.get('1210'))
        elif self.dataset == "secex":
            self.wld = []
            for i, f in enumerate(filter.split("+")):
                if Wld.query.get(f):
                    self.wld.append(Wld.query.get(f))
                else:
                    self.wld.append(Wld.query.get('aschn'))
        self.filter2 = filter
        
    '''Returns the URL for the specific build.'''
    def url(self, **kwargs):
        
        # bra = self.bra.id
        # if self.filter1 == "all": filter1 = "all"
        # else: filter1 = self.filter1.id
        # if self.filter2 == "all": filter2 = "all"
        # else: filter2 = self.filter2.id
        bra_id = "+".join([b.id for b in self.bra])
        
        url = '{0}/{1}/{2}/{3}/{4}/{5}'.format(self.app.viz_whiz, 
                self.dataset, bra_id, self.filter1, self.filter2, self.output)
        return url

    '''Returns the data URL for the specific build. This URL will return the 
    data required for building a viz of this app.
    '''
    def data_url(self, **kwargs):<commit_msg>Bug fix for build url function<commit_after>from flask import g
from visual import db
from visual.utils import AutoSerialize
from visual.attrs.models import Bra, Isic, Hs, Cbo, Wld

import ast

build_ui = db.Table('apps_build_ui',
         db.Column('build_id', db.Integer,db.ForeignKey('apps_build.id')),
         db.Column('ui_id', db.Integer,db.ForeignKey('apps_ui.id'))
)

class App(db.Model, AutoSerialize):

    __tablename__ = 'apps_app'
    
    id = db.Column(db.Integer, primary_key = True)
    type = db.Column(db.String(20))
    title = db.Column(db.String(20))
    viz_whiz = db.Column(db.String(20))
    color = db.Column(db.String(7))

class Build(db.Model, AutoSerialize):

    __tablename__ = 'apps_build'
    __public__ = ('id', 'type', 'bra', 'filter1', 'filter2', 'output', 'viz_whiz', 'name', 'color', 'dataset')
    
    id = db.Column(db.Integer, primary_key = True)
    dataset = db.Column(db.String(20))
    bra = db.Column(db.String(20))
    filter1 = db.Column(db.String(20))
    filter2 = db.Column(db.String(20))
    output = db.Column(db.String(20))
    title_en = db.Column(db.String(120))
    title_pt = db.Column(db.String(120))
    app_id = db.Column(db.Integer, db.ForeignKey(App.id))
    
    ui = db.relationship('UI', secondary=build_ui, 
            backref=db.backref('Builds'), lazy='dynamic')
    app = db.relationship('App',
            backref=db.backref('Builds', lazy='dynamic'))
    
    def get_ui(self, ui_type):
        return self.ui.filter(UI.type == ui_type).first()

    def set_bra(self, bra_id):
        self.bra = []
        if bra_id == "all":
            self.bra.append(Wld.query.get("sabra"))
            self.bra[0].id = "all"
            self.bra[0].icon = "/static/img/icons/wld/wld_sabra.png"
        else:
            for i, b in enumerate(bra_id.split("+")):
                self.bra.append(Bra.query.get(b))
                self.bra[i].icon = "/static/img/icons/bra/bra_{0}.png".format(b[:2])

    def set_filter1(self, filter):
        if self.filter1 != "all":
            if self.dataset == "rais":
                self.isic = []
                for i, f in enumerate(filter.split("+")):
                    if Isic.query.get(f):
                        self.isic.append(Isic.query.get(f))
                    else:
                        self.isic.append(Isic.query.get('c1410'))
                self.filter1 = "+".join([i.id for i in set(self.isic)])
            elif self.dataset == "secex":
                self.hs = []
                for i, f in enumerate(filter.split("+")):
                    if Hs.query.get(f):
                        self.hs.append(Hs.query.get(f))
                    else:
                        self.hs.append(Hs.query.get('178703'))
                self.filter1 = "+".join([h.id for h in set(self.hs)])
    
    def set_filter2(self, filter):
        if self.filter2 != "all":
            if self.dataset == "rais":
                self.cbo = []
                for i, f in enumerate(filter.split("+")):
                    if Cbo.query.get(f):
                        self.cbo.append(Cbo.query.get(f))
                    else:
                        self.cbo.append(Cbo.query.get('1210'))
                self.filter2 = "+".join([c.id for c in set(self.cbo)])
            elif self.dataset == "secex":
                self.wld = []
                for i, f in enumerate(filter.split("+")):
                    if Wld.query.get(f):
                        self.wld.append(Wld.query.get(f))
                    else:
                        self.wld.append(Wld.query.get('aschn'))
                self.filter2 = "+".join([w.id for w in set(self.wld)])
        
    '''Returns the URL for the specific build.'''
    def url(self, **kwargs):
        
        # bra = self.bra.id
        # if self.filter1 == "all": filter1 = "all"
        # else: filter1 = self.filter1.id
        # if self.filter2 == "all": filter2 = "all"
        # else: filter2 = self.filter2.id
        bra_id = "+".join([b.id for b in self.bra])
        
        url = '{0}/{1}/{2}/{3}/{4}/{5}'.format(self.app.viz_whiz, 
                self.dataset, bra_id, self.filter1, self.filter2, self.output)
        return url

    '''Returns the data URL for the specific build. This URL will return the 
    data required for building a viz of this app.
    '''
    def data_url(self, **kwargs):
{'fraction_non_alphanumeric': 0.15710398675026618, 'fraction_numerical': 0.01632556488820537, 'mean_word_length': 1.8952054794520548, 'pattern_counts': {'":': 18, '<': 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': '621976', 'n_tokens_mistral': 2910, 'n_tokens_neox': 2780, 'n_words': 544}