Example #1
0
def lookForGroup():
	db.addGroup(txt1.get())	
	core.groupLookout(txt1.get())
	# txtArea.insert('1.0', db.listGroups())
	# txt1.delete(0, 'end')
	lbl4.configure(text=str(db.stats(0)[0]))
	lbl5.configure(text=str(db.stats(1)[0]))
	lbl6.configure(text=str(db.stats(2)[0]))
Example #2
0
 def stats(self, _=None):
     log_api_call('stats')
     results = get_results()
     stats = {
         'db_stats' : db.stats(),
         'api_stats' : get_api_call_stats()
     }
     results['stats'] = stats
     return seal_results(results)
Example #3
0
def make_playlist(artist, title, hours):
    hours = int(hours)

    stats = db.stats(artist, title)
    start = stats['first']

    print stats

    # At first we make a basic assumption that a song is 4 minutes long
    songs_per_hour = 60.0/4

    number_years = 2015 - int(start[:4])

    if number_years > hours:
        actual_hours = number_years
    else:
        actual_hours = hours

    available_slots = actual_hours * songs_per_hour

    print "actual hours %s avail slots %s" % (actual_hours, available_slots)

    # first start with the first year -> end of that year
    allsongs = songs_for_year(start)
    # then go one per year until the last year
    allsongs = []
    lastyear = 2015
    year = int(start[:4])
    while year <= lastyear:
        print "songs for", year
        allsongs.extend(songs_for_year("%s-01-01" % year))
        year += 1

    # We now have too many songs. See how many we need to throw away
    remove_prob = float(available_slots)/len(allsongs)
    print "removing with prob of", remove_prob

    songs = []
    lastsong = None
    for s in allsongs:
        if random.random() < remove_prob and s != lastsong:
            songs.append(s)
            lastsong = s

    return actual_hours, songs
Example #4
0
 def do_astats(self, line):
     ''' report connectivity stats for artist '''
     aid = self.asearch(line)
     if aid:
         db.stats(aid)
Example #5
0
def secondSearch():
	core.lookAllGroups()
	lbl4.configure(text=str(db.stats(0)[0]))
	lbl5.configure(text=str(db.stats(1)[0]))
	lbl6.configure(text=str(db.stats(2)[0]))
Example #6
0
import tkinter
from tkinter import *
from tkinter import scrolledtext
import db, core
import asyncio
top = tkinter.Tk()

top.title("Telegrama")

db.createTable()

lbl1 = Label(top, text = "Total Users: ")
lbl2 = Label(top, text = "Added Users: ")
lbl3 = Label(top, text = "Left Users: ")

lbl4 = Label(top, text = str(db.stats(0)[0]))
lbl5 = Label(top, text = str(db.stats(1)[0]))
lbl6 = Label(top, text = str(db.stats(2)[0]))

lbl1.grid(column=0, row=0)
lbl2.grid(column=0, row=1)
lbl3.grid(column=0, row=2)

lbl4.grid(column=1, row=0)
lbl5.grid(column=1, row=1)
lbl6.grid(column=1, row=2)

lbl7 = Label(top, text = "Name of the group/channel: " )
lbl7.grid(column=0, row=4)

txt1 = Entry(top, width = 20)
Example #7
0
def update_stats(action, student):
    logger.info("update_stats({},{})".format(action, student))
    return stats(action, student)
Example #8
0
def cmd(args):
    '''
	Main function in shell to launch process:
	if --download: take the config settings: execute [download, clean, init, insert, stats]
	if no arguments: execute [init, insert, stats]   
	'''
    ### STEPS/STEP: init and populate db

    logger.info(args)
    status = True
    msg = ""
    ## STEPS is True: create the steps: [init, insert]
    if args.steps is True:
        logger.info("STEPS option is activated: execute only the steps")
        ## STEPS is True and download is False: create the steps: [init, insert]
        ## from files/clean
        if args.download is not False:
            logger.info("with --download")
            # logger.info("- arguments {}".format(args))
            logger.info("create_steps(): download, clean, init, insert")
            status, msg = create_steps()
            return status, msg
        else:
            logger.info("create_steps(): init, insert")
            logger.info(
                "create_steps(): init from files in {}, insert from files in {}"
                .format(args.dirs["ref"], args.dirs["to"]))
            logger.info("remove download and clean")
            steps = STEPS
            # removed_steps = ["download"]
            removed_steps = ["download", "clean"]
            for del_s in removed_steps:
                steps.remove(del_s)
            for step in steps:
                status, msg = create_step(step)
                if status is False:
                    logger.critical("STEP {}() is {}. {}".format(
                        step, status, msg))
                    break
            return status, msg
    # STEP: specify the step between 'download,clean,init,insert' accept multiple steps coma separated
    elif args.step is not None:
        logger.info(
            "STEP option is activated: execute only the steps mentionned")
        for step in args.step.split(","):
            logger.info("STEP {}()".format(args.step))
            status, msg = create_step(step.strip())
            if status is False:
                logger.critical("STEP {}() is {}. {}".format(
                    step, status, msg))
                break
        return status, msg

    ### STATS : generate stats
    elif args.stats in ["create", "delete", "update"]:
        logger.info("STATS option is activated: only {} all stats".format(
            args.stats))
        logger.info("STATS stats({},{})".format(args.stats, args.student))
        if args.stats == "create":
            status, msg = stats(args.stats, args.student)
        elif args.stats == "delete":
            status, msg = stats(args.stats, args.student)
        else:
            #update
            stats("delete", args.student)
            status, msg = stats("create", args.student)
        return status, msg
    # STAT: specify the stat between 'activity, tasks, skills, progression' multiple stats accepted coma separated
    elif args.stat is not None:
        logger.info(
            "STAT option is activated. Only create specified stats {}".format(
                args.stats))
        for stat_name in args.stat.split(","):
            logger.info("STAT {}({})".format(stat_name.strip(), args.student))
            stat(stat_name, action="create", student=args.student)
        return status, msg
    ### TABLES: generate TABLES for STATS create delete or update
    elif args.tables in ["create", "delete", "update"]:
        logger.info("TABLES option is activated. {} all the tables".format(
            args.tables))
        status, msg = tables(action=args.tables, student=args.student)
        return status, msg
    #TABLE specify the table between 'day,chapter,lesson,...', multiple tables accepteds  coma sperated
    elif args.table is not None:
        logger.info(
            "TABLE option is activated. Create only the table: {}".format(
                args.table))
        table_names = args.table.split(",")
        for tablename in table_names:
            logger.info("TABLE({},{}) option is activated".format(
                tablename.strip(), args.student))
            status, msg = table(tablename,
                                action="create",
                                student=args.student,
                                required_table=None)
        return status, msg

    ### COMPLETE SCRIPT
    elif args.download is not False:
        logger.info(
            "Complete execution with download: download, clean, init, insert, stats"
        )
        create_steps()
        status, msg = stats("create", args.student)
        return satus, msg
    else:
        steps = STEPS
        logger.info("No arguments in cmd: falling back to settinngs.json")
        if config["FILES_SERVER"]["activate"] is False:
            # raw directory provided by user

            raw_data_dir = config["FILES_SERVER"]["dir"]

            # if raw_directory provided by user doesn't exists
            if not dir_exists(raw_data_dir) or dir_empty(raw_data_dir):
                # fall back to default CLEAN_DIR
                if not dir_exists(CLEAN_DIR) or dir_empty(CLEAN_DIR):
                    # trying to get default RAW_DIR
                    if not dir_exists(RAW_DIR) or dir_empty(RAW_DIR):
                        msg = "No download option activated and no data found in both provided dir: {} and RAW dir: {}".format(
                            raw_data_dir, RAW_DIR)
                        logger.critical(msg)
                        return False, msg
                    else:
                        steps.remove("download")
                else:
                    steps.remove("download")
                    steps.remove("clean")
            else:
                RAW_DIR = raw_data_dir
                steps.remove("download")
                if not dir_exists(CLEAN_DIR):
                    os.makedirs(CLEAN_DIR)
        logger.info("Execute: {}".format(", ".join(steps)))
        create_steps(steps)
        status, msg = stats("create", args.student)
        return status, msg