Example #1
0
def integrate_new_events(sid):
	max_sched_id, max_elec_id, num_elections = _get_schedule_stats(sid)

	# Will remove events that no longer have a schedule ID with them
	new_next = []
	for e in next[sid]:
		if e.is_election and db.c.fetch_var("SELECT elec_id FROM r4_elections WHERE elec_id = %s" % e.id):
			new_next.append(e)
		elif db.c.fetch_var("SELECT sched_id FROM r4_schedule WHERE sched_id = %s" % e.id):
			new_next.append(e)
	next[sid] = new_next

	# This is the line of code that loads in any upcoming events
	unused_sched_id = db.c.fetch_list("SELECT sched_id FROM r4_schedule WHERE sid = %s AND sched_id > %s AND sched_used = FALSE AND sched_start <= %s ORDER BY sched_start", (sid, max_sched_id, int(time.time()) + 86400))
	for sched_id in unused_sched_id:
		e = event.load_by_id(sched_id)
		if not e:
			log.warn("schedule", "Unused event ID %s was None." % sched_id)
		else:
			next[sid].append(e)

	# Step 4: Insert "priority elections" ahead of anything else
	priority_elec_ids = db.c.fetch_list("SELECT elec_id FROM r4_elections WHERE sid = %s AND elec_id > %s AND elec_priority = TRUE ORDER BY elec_id DESC", (sid, max_elec_id))
	for elec_id in priority_elec_ids:
		e = playlist.Election.load_by_id(elec_id)
		# The client, through the API, sets start times, so we don't have to worry about where in the array it goes.  The sorter will take care of it.
		next[sid].append(e)
		if e.id > max_elec_id:
			max_elec_id = e.id
		num_elections += 1
		e.set_priority(False)

	return (max_sched_id, max_elec_id, num_elections)
Example #2
0
def integrate_new_events(sid):
	max_sched_id = 0
	max_elec_id = 0
	num_elections = 0
	for event in next[sid]:
		if event.is_election:
			num_elections += 1
			if event.id > max_elec_id:
				max_elec_id = event.id
		elif not event.is_election and event.id > max_sched_id:
			max_sched_id = event.id
	unused_sched_id = db.c.fetch_list("SELECT sched_id FROM r4_schedule WHERE sid = %s AND sched_id > %s AND sched_used = FALSE AND sched_start <= %s ORDER BY sched_start", (sid, max_sched_id, time.time() + 86400))
	for sched_id in unused_sched_id:
		next[sid].append(event.load_by_id(sched_id))
		
	# Step 4: Insert "priority elections" ahead of anything else
	priority_elec_ids = db.c.fetch_list("SELECT elec_id FROM r4_elections WHERE sid = %s AND elec_id > %s AND elec_priority = TRUE ORDER BY elec_id DESC", (sid, max_elec_id))
	for elec_id in priority_elec_ids:
		event = playlist.Election.load_by_id(elec_id)
		# The client, through the API, sets start times, so we don't have to worry about where in the array it goes.  The sorter will take care of it.
		next[sid].append(event)
		if event.id > max_elec_id:
			max_elec_id = event.id
		num_elections += 1
		event.set_priority(False)
		
	return (max_sched_id, max_elec_id, num_elections)
Example #3
0
def integrate_new_events(sid):
    max_sched_id, max_elec_id, num_elections = _get_schedule_stats(sid)

    # Will remove events that no longer have a schedule ID with them
    new_next = []
    for e in next[sid]:
        if e.is_election and db.c.fetch_var(
                "SELECT elec_id FROM r4_elections WHERE elec_id = %s" % e.id):
            new_next.append(e)
        elif db.c.fetch_var(
                "SELECT sched_id FROM r4_schedule WHERE sched_id = %s" % e.id):
            new_next.append(e)
    next[sid] = new_next

    # This is the line of code that loads in any upcoming events
    unused_sched_id = db.c.fetch_list(
        "SELECT sched_id FROM r4_schedule WHERE sid = %s AND sched_id > %s AND sched_used = FALSE AND sched_start <= %s ORDER BY sched_start",
        (sid, max_sched_id, int(time.time()) + 86400))
    for sched_id in unused_sched_id:
        e = event.load_by_id(sched_id)
        if not e:
            log.warn("schedule", "Unused event ID %s was None." % sched_id)
        else:
            next[sid].append(e)

    # Step 4: Insert "priority elections" ahead of anything else
    priority_elec_ids = db.c.fetch_list(
        "SELECT elec_id FROM r4_elections WHERE sid = %s AND elec_id > %s AND elec_priority = TRUE ORDER BY elec_id DESC",
        (sid, max_elec_id))
    for elec_id in priority_elec_ids:
        e = playlist.Election.load_by_id(elec_id)
        # The client, through the API, sets start times, so we don't have to worry about where in the array it goes.  The sorter will take care of it.
        next[sid].append(e)
        if e.id > max_elec_id:
            max_elec_id = e.id
        num_elections += 1
        e.set_priority(False)

    return (max_sched_id, max_elec_id, num_elections)