Exemple #1
0
def main( ):
    global db_
    global titles_, abstract_
    global data_

    cur = db_.cursor( dictionary = True )

    cur.execute( 'SELECT title, description FROM talks' )
    for a in cur.fetchall( ):
        data_.append( '<br> %s </br>' % a[ 'title' ] + '<br>' 
                + strip_image( a['description'] ) )

    cur.execute( 'SELECT title, abstract FROM annual_work_seminars' )
    for a in cur.fetchall( ):
        data_.append( '<br> %s </br>' % a[ 'title' ] + '<br>' + strip_image(
            a['abstract'] ) 
            )

    with open( '/tmp/_sample.html', 'w' ) as f:
        f.write( ' '.join( data_ ) )
        
    aws, awsf = html2other.tomd( '/tmp/_sample.html' )
    aws = aws.replace( r'\\', '' )
    words = set( re.findall( r'\w+', aws ) )
    with open( '_words', 'w' ) as f:
        f.write( '\n'.join( words ) )

    with open( '/tmp/data.txt', 'w' ) as f:
        f.write( aws )
Exemple #2
0
def main():
    global db_
    global titles_, abstract_
    cur = db_.cursor(dictionary=True)
    cur.execute('SELECT title, abstract FROM annual_work_seminars')
    for a in cur.fetchall():
        aws_.append('<br> %s </br>' % a['title'] + '<br>' + a['abstract'])

    aws = html2other.tomd(' '.join(aws_))
    with open('/tmp/aws.txt', 'w') as f:
        f.write(aws)
Exemple #3
0
def commit_schedule(schedule):
    global db_
    cur = db_.cursor()
    for date in sorted(schedule):
        for s in schedule[date]:
            query = """
                INSERT INTO aws_temp_schedule (speaker, date) VALUES ('{0}', '{1}')
                ON DUPLICATE KEY UPDATE date='{1}'
                """.format(s['speaker'], date)
            cur.execute(query)
    db_.commit()
    print('[INFO] Committed to database')
Exemple #4
0
def commit_schedule(schedule):
    global db_
    cur = db_.cursor()
    _logger.info('Committing computed schedules ')
    for date in sorted(schedule):
        for speaker in schedule[date]:
            query = """
                INSERT INTO aws_temp_schedule (speaker, date) VALUES ('{0}', '{1}') 
                ON DUPLICATE KEY UPDATE date='{1}'
                """.format(speaker, date)
            cur.execute(query)
    db_.commit()
    _logger.info("Committed to database")
Exemple #5
0
def get_data():
    global db_
    try:
        cur = db_.cursor(dictionary=True)
    except Exception as e:
        print('''If complain is about dictionary keyword. Install 
        https://pypi.python.org/pypi/mysql-connector-python-rf/2.2.2
        using easy_install''')
        quit()
    init(cur)

    # Entries in this table are usually in future.
    cur.execute('SELECT * FROM upcoming_aws')
    for a in cur.fetchall():
        aws_[a['speaker']].append(a)
        upcoming_aws_[a['speaker'].lower()] = a['date']
        # Keep the number of slots occupied at this day.
        upcoming_aws_slots_[a['date']].append(a['speaker'])

    # Now get all the previous AWSs happened so far.
    cur.execute('SELECT * FROM annual_work_seminars')
    for a in cur.fetchall():
        aws_[a['speaker'].lower()].append(a)

    for a in aws_:
        # Sort a list in place.
        aws_[a].sort(key=lambda x: x['date'])
        # print( a, [ x['date'] for x in aws_[a] ] )

    # Select all aws scheduling requests which have been approved.
    cur.execute("SELECT * FROM aws_scheduling_request WHERE status='APPROVED'")
    for a in cur.fetchall():
        aws_scheduling_requests_[a['speaker'].lower()] = a

    # Now pepare output file.
    speakers = speaker_data()
    slots = slots_data()

    graph = nx.DiGraph()
    graph.add_node('source')
    graph.add_node('sink')
    for s in speakers:
        graph.add_node(s, **speakers[s])
        graph.add_edge('source', s, weight=0, capacity=1, cost=0)

    for date, i in slots:
        graph.add_node((date, i), date='%s' % date, index=i)
        graph.add_edge((date, i), 'sink', weight=0, capacity=1, cost=0)

    return graph
Exemple #6
0
def getAllAWSPlusUpcoming():
    global db_

    # cur = db_.cursor( cursor_class = MySQLCursorDict )
    try:
        cur = db_.cursor(dictionary=True)
    except Exception as e:
        print('''If complain is about dictionary keyword. Install 
        https://pypi.python.org/pypi/mysql-connector-python-rf/2.2.2
        using easy_install''')
        quit()

    init(cur)

    # Entries in this table are usually in future.
    cur.execute('SELECT * FROM upcoming_aws')
    for a in cur.fetchall():
        aws_[a['speaker']].append(a)
        upcoming_aws_[a['speaker'].lower()] = a['date']
        # Keep the number of slots occupied at this day.
        upcoming_aws_slots_[a['date']].append(a['speaker'])

    # Now get all the previous AWSs happened so far.
    cur.execute('SELECT * FROM annual_work_seminars')
    for a in cur.fetchall():
        aws_[a['speaker'].lower()].append(a)

    for a in aws_:
        # Sort a list in place.
        aws_[a].sort(key=lambda x: x['date'])
        # print( a, [ x['date'] for x in aws_[a] ] )

    # Select all aws scheduling requests which have been approved.
    cur.execute("SELECT * FROM aws_scheduling_request WHERE status='APPROVED'")
    for a in cur.fetchall():
        aws_scheduling_requests_[a['speaker'].lower()] = a
def init():
    global g_
    global entries_
    global max_weight_
    cur = db_.cursor(dictionary=True)

    g_.add_node('SOURCE')
    g_.add_node('SINK')

    cur.execute("SELECT * FROM upcoming_course_schedule WHERE status='VALID'")
    for row in cur:
        entries_.append(row)
        slots_.add(row['slot'])
        venues_.add(row['venue'])
        courses_.add(row['course_id'])
        if int(row['weight']) > max_weight_:
            max_weight_ = int(row['weight']) + 1

    # SOURCE to slot.
    for slot, venue in itertools.product(slots_, venues_):
        print('Slot %s and venue %s' % (slot, venue))
        key = slot + ':' + venue
        g_.add_node(key)
        g_.add_edge('SOURCE', key, capacity=1)

    #  To sink
    for c in courses_:
        print('[INFO] Course is %s' % c)
        g_.add_node(c)
        g_.add_edge(c, 'SINK', capacity=1)

    # Now SLOT to COURSE
    for e in entries_:
        venue, slot = e['venue'], e['slot']
        key = slot + ':' + venue
        g_.add_edge(key,
                    e['course_id'],
                    capacity=100,
                    weight=max_weight_ - int(e['weight']))

    print('[INFO] Max Weight is %d' % max_weight_)
    assignments = {}
    solution = nx.min_cost_flow(g_, 'SOURCE', 'SINK')
    for k in solution:
        if k in ['SOURCE', 'SINK']:
            continue
        vs = solution[k]
        for v in vs:
            if v == 'SINK':
                continue
            assignments[v] = k.split(':')

    # Remove all previous assignments.
    cur.execute("""
        UPDATE upcoming_course_schedule
        SET alloted_slot=NULL AND alloted_venue=NULL
        """)
    db_.commit()

    for k in assignments:
        slot, venue = assignments[k]
        query = """
                UPDATE upcoming_course_schedule
            SET alloted_slot='{s}',alloted_venue='{v}'
                WHERE
            course_id='{c}' AND slot='{s}'
                AND venue='{v}'""".format(s=slot, v=venue, c=k)
        cur.execute(query)
    db_.commit()
Exemple #8
0
def getAllAWSPlusUpcoming():
    global db_
    # cur = db_.cursor( cursor_class = MySQLCursorDict )
    try:
        cur = db_.cursor(dictionary=True)
    except Exception as e:
        print(e)
        print('''If complain is about dictionary keyword. Install
        https://pypi.python.org/pypi/mysql-connector-python-rf/2.2.2
        using easy_install''')
        quit()

    init(cur)

    # Entries in this table are usually in future.
    cur.execute('SELECT * FROM upcoming_aws')
    for a in cur.fetchall():
        aws_[a['speaker']].append(a)
        upcoming_aws_[a['speaker'].lower()] = a['date']
        # Keep the number of slots occupied at this day.
        upcoming_aws_slots_[a['date']].append(a['speaker'])

    # Now get all the previous AWSs happened so far. Also fetch the
    # specialization of student depending on what student has specified or by
    # reading PI.
    cur.execute('SELECT * FROM annual_work_seminars')
    for a in cur.fetchall():
        # If this speaker is not eligible anymore ignore.
        if a['speaker'] not in speakers_:
            continue

        aws_[a['speaker'].lower()].append(a)
        # Also get the specialization by reading the supervisor_1 .
        pi = a['supervisor_1']
        if not pi:
            continue
        cur.execute("SELECT specialization FROM faculty WHERE email='%s'" % pi)
        spec = cur.fetchone()
        if spec:
            specialization = spec.get('specialization', 'UNSPECIFIED')
            if specialization and specialization != 'UNSPECIFIED':
                speakersSpecialization_[a['speaker']] = spec['specialization']

    for a in aws_:
        # Sort a list in place.
        aws_[a].sort(key=lambda x: x['date'])
        # print( a, [ x['date'] for x in aws_[a] ] )

    # Select all aws scheduling requests which have been approved.
    cur.execute("SELECT * FROM aws_scheduling_request WHERE status='APPROVED'")
    for a in cur.fetchall():
        aws_scheduling_requests_[a['speaker'].lower()] = a

    # Get specialization of each student. If no specified, fetch the
    # specialization of current PI.
    # IMP: This will overwrite the specialization fetched from previous AWS. It
    # is required.
    for st in speakers_:
        # If  this speaker has given AWS in less than 6 months, do not count her
        # when computing frequencies.
        prevAWSDate = getPrevisousAWS(cur, st)
        #if prevAWSDate is not None:
        #    if diffInDays( prevAWSDate, datetime.date.today( ) ) < 200:
        #        _logger.warn( 'Not counting %s. Recently given AWS' % st )
        #        continue

        cur.execute("SELECT specialization FROM logins WHERE login='******'" % st)
        a = cur.fetchone()
        if not a['specialization']:
            # Ok. Not specified; use faculty specialization.
            piOrHost = speakers_[st]['pi_or_host']

            if piOrHost:
                cur.execute(
                    "SELECT specialization FROM faculty WHERE email='%s'" %
                    piOrHost)
                a = cur.fetchone()

        if a is not None and a['specialization']:
            speakersSpecialization_[st] = a['specialization']

    ## Compute the frequencies of specialization.
    ## Print specialization
    _logger.debug('Total speakers %d' % len(speakersSpecialization_))
    freq = Counter(speakersSpecialization_.values())
    for k in freq:
        specializationFreqs_[k] = 1.0 * freq[k] / sum(freq.values())

    _logger.info(specializationFreqs_)
    print(specializationFreqs_)
Exemple #9
0
def dbTime( d ):
    return d.strftime( '%H:%M' )

def overlapping( venueA, venueB ):
    overlapping = 0
    for e1 in venueA:
        e1st = e1['start_time']
        e1et = e1['end_time']
        for e2 in filter( lambda x: x['date'] == e1['date'], venueB):
            e2st = e2['start_time']
            e2et = e2['end_time']
            if e1et < e2st or e1st > e2et:
                pass
            else:
                overlapping += 1
    return overlapping

cur = db_.cursor( dictionary = True )
cur.execute( 'SELECT * FROM events WHERE status="VALID" AND class!="CLASS"' )
entries = [ ]
venues_ = set( )
for row in cur.fetchall( ):
    entries.append( row )
    venues_.add( row[ 'venue' ] )

print( 'Total %d entries' % len( entries ) )

malgova = filter( lambda x:'gova' in x['venue'], entries )
lh2 = filter( lambda x:'LH1' in x['venue'], entries )
print( 'Total overlapping %d' % overlapping(malgova, lh2) )