Пример #1
0
def open_deck(id, deck_name):
    column = "question"
    frame = tk.Frame(root, bg='violet', bd=4)
    frame.place(relheight=0.75, relwidth=0.9, relx=0.5, rely=0.1, anchor='n')
    label = tk.Label(frame, font=50, bg=background, fg=foreground)
    label.place(relwidth=1, relheight=0.7)
    label.config(font=(fontype, cardfontsize))
    try:
        temp = id.pop()
        number = list(map(int, temp))
        label['text'] = database.fetch(number, column)
    except:
        define_deck(deck_name, 0)
    button = tk.Button(frame,
                       text="Show Answer",
                       font=40,
                       bg=background,
                       fg=foreground,
                       command=lambda: nexttab(number, deck_name))
    button.place(relx=0.35, rely=0.75, relwidth=0.3, relheight=0.2)
    bt = tk.Button(frame,
                   text="Back",
                   font=20,
                   bg=bannerred,
                   fg="black",
                   command=lambda: maindeck())
    bt.place(relx=.75, rely=0.85, relwidth=0.16, relheight=0.1)
    root.mainloop()
Пример #2
0
def doc(id):
    conn = db.connect()
    post = db.fetch(conn, id)
    return render_template('doc.html',
                           ID=post.id,
                           TITLE=post.title,
                           TEXT=post.body)
Пример #3
0
def route_revisions(title, rev):
    title = title.replace('_', ' ')
    
    if not database.init():
        return error(app.config['db_err_title'], app.config['db_err_msg']), 503

    if not database.fetch('SELECT 1 from articles WHERE title = ?', [title]):
        return redirect('/%s' % title)

    if rev == "list":
       revisions = database.fetch_all('SELECT * FROM articles WHERE title = ?', [title])
       return render_template('revision.html', rev="list", title=title, revisions=revisions)
    elif rev != 0:
       article = database.fetch('SELECT * FROM articles WHERE title = ? AND revision = ?', [title, rev])
       return render_template('revision.html', rev=rev, title=title, content=article['content'])
    else:
       return redirect('/%s' % title)
Пример #4
0
def route_random():
    database.init()
    row = database.fetch("SELECT title FROM articles WHERE title!='Main Page' ORDER BY RANDOM() LIMIT 1")
    database.close()

    if row != None:
        title = row['title'].replace(' ', '_')
        return redirect('/' + title)
    else:
        return redirect('/')
Пример #5
0
def ratio_labels(react_type, user_attrs, times):
    if user_attrs:
        sql_attrs = ' AND ' + ' AND '.join(['users.%s="%s"' % x
                                  for x in user_attrs])
    else:
        sql_attrs = ''
    ratios = []
    for start, end in times:
        query = COUNT_QUERY % (react_type.split(":")[0] + ":Agree",
                               sql_attrs, start, end)
        num_agrees = database.fetch(query)[0][0]
        query = COUNT_QUERY % (react_type.split(":")[0] + ":Disagree",
                               sql_attrs, start, end)
        num_disagrees = database.fetch(query)[0][0]
        if num_disagrees == 0:
            ratios.append(num_agrees)
        else:
            ratios.append(num_agrees / num_disagrees)
    median = np.median(ratios)
    return [1 if x > median else 0 for x in ratios]
Пример #6
0
def route_article(title):
    title = title.replace('_', ' ')
    
    if not database.init():
        return error(app.config['db_err_title'], app.config['db_err_msg']), 503

    article =  database.fetch('SELECT * FROM articles WHERE title = ? AND revision = 0', [title])
    database.close()
    if article != None:
        return render_template('article.html', title=title, content=article['content'])
    else:
        return render_template('article.html', title=title, content='There is currently no text on this page')
Пример #7
0
def route_edit(title):
    title = title.replace('_', ' ')

    if not database.init():
        return error(app.config['s_db_title'], app.config['s_db_msg']), 503
    
    article = database.fetch('SELECT * FROM articles WHERE title = ?', [escape(title)])
    database.close()

    if article != None:
        return render_template('edit.html', title=article['title'], id=article['id'], content=article['content'])
    else:
        return render_template('edit.html', title=title, id=0, content='')
Пример #8
0
def svmlite_lines(react_type, user_attrs, label_fn, times, feats_list):
    if user_attrs:
        sql_attrs = ' AND ' + ' AND '.join(['users.%s="%s"' % x
                                  for x in user_attrs])
    else:
        sql_attrs = ''
    for (start, end), feats in zip(times, feats_list):
        if react_type == "all":
            query = COUNT_QUERY_ALL % (sql_attrs, start, end)
        else:
            query = COUNT_QUERY % (react_type, sql_attrs, start, end)
        num_reacts = database.fetch(query)[0][0]
        feat_str = ' '.join(["%s:%s" % (idx, feat) for idx, feat in feats
            + [('100', str((strptime(end, '%H:%M:%S') - strptime(start, '%H:%M:%S')).seconds))]])
        yield "%s %s\n" % (label_fn(num_reacts), feat_str)
Пример #9
0
def edit():
    id = request.form.get('id', None)
    if id == '':
        return render_template('editor.html', error_msg='please enter an ID')

    conn = db.connect()
    post = db.fetch(conn, id)
    try:
        return render_template('editor.html',
                               title=post.title,
                               body=post.body,
                               tags=post.tags)

    except AttributeError:
        return render_template('editor.html',
                               error_msg=f'no post found with ID {id}')
Пример #10
0
def counts_per_turn(react_type, user_attrs, per_second=True, curr_speaker=True):
    speakers = {'0': 'Moderator', '1': 'Romney', '2': 'Obama'}
    if user_attrs:
        user_attr_sql = ' AND ' + ' AND '.join(['users.%s="%s"' % x
                                  for x in user_attrs])
    else:
        user_attr_sql = ''
    with open(DEBATE_DATA_FNAME) as debate_data:
        reader = csv.reader(debate_data, delimiter=',', quotechar='"')
        react_counts = []
        for row in reader:
            query = BARE_COUNT_QUERY % (row[2], row[3])
            query += user_attr_sql
            if curr_speaker:
                print row
                query += ' AND reactions.reaction="%s:%s"' % (speakers[row[1]], react_type)
            react_count = database.fetch(query)[0][0]
            react_counts.append(react_count)
        return react_counts
Пример #11
0
def binned_labels(react_type, user_attrs, times):
    if user_attrs:
        sql_attrs = ' AND ' + ' AND '.join(['users.%s="%s"' % x
                                  for x in user_attrs])
    else:
        sql_attrs = ''
    react_counts = []
    for start, end in times:
        if react_type == "all":
            query = COUNT_QUERY_ALL % (sql_attrs, start, end)
        else:
            query = COUNT_QUERY % (react_type.split(":")[0] + ":Agree",
                               sql_attrs, start, end)
        #print query
        st = strptime(start, '%H:%M:%S')
        nd = strptime(end, '%H:%M:%S')
        turn_time = (nd - st).seconds + 1
        num_reacts = database.fetch(query)[0][0]
        #print num_reacts
        react_counts.append(num_reacts / turn_time)
    median = np.median(react_counts)
    return [1 if x > median else 0 for x in react_counts]
Пример #12
0
def nexttab(number, deck_name):
    column = "answer"
    frame = tk.Frame(root, bg='purple', bd=4)
    frame.place(relheight=0.75, relwidth=0.9, relx=0.5, rely=0.1, anchor='n')
    label = tk.Label(frame, font=50, bg=foreground, fg=background)
    label.place(relwidth=1, relheight=0.7)
    label.config(font=(fontype, cardfontsize))
    label['text'] = database.fetch(number, column)

    button = tk.Button(frame,
                       text="Very Easy",
                       font=40,
                       bg=bannergreen,
                       fg='black',
                       command=lambda: complete(number, 0, deck_name))
    button.place(relx=0.05, rely=0.75, relwidth=0.20, relheight=0.2)
    button = tk.Button(frame,
                       text="Easy",
                       font=40,
                       bg=bannerblue,
                       fg='black',
                       command=lambda: complete(number, 1, deck_name))
    button.place(relx=0.29, rely=0.75, relwidth=0.20, relheight=0.2)
    button = tk.Button(frame,
                       text="Medium",
                       font=40,
                       bg=banneryellow,
                       fg='black',
                       command=lambda: complete(number, 2, deck_name))
    button.place(relx=0.53, rely=0.75, relwidth=0.20, relheight=0.2)
    button = tk.Button(frame,
                       text="Hard",
                       font=40,
                       bg=bannerred,
                       fg='black',
                       command=lambda: complete(number, 3, deck_name))
    button.place(relx=0.78, rely=0.75, relwidth=0.20, relheight=0.2)
Пример #13
0
def get(key):
  return database.fetch('select * from settings where key = "' + key + '"')[0]
Пример #14
0
 def _fetch(self, query, parameters=None):
     if parameters is None:
         return database.fetch(query)
     else:
         return database.fetch(query, parameters)
Пример #15
0
def get_all_ids():
    return database.fetch('select id from torrents')
Пример #16
0
def get_ids_for_artist(artist):
    return database.fetch('select id from torrents where artist = "' + artist +
                          '"')
Пример #17
0
def exists(id, artist, album):
    query = 'select id from torrents where id = "' + str(
        id) + '" or artist = "' + artist + '" and album = "' + album + '"'
    return database.fetch(query) != []
Пример #18
0
def get_ids_for_artist(artist):
  return database.fetch('select id from torrents where artist = "' + artist + '"')
Пример #19
0
def get(key):
    return database.fetch('select * from settings where key = "' + key +
                          '"')[0]