+ -

Pages

Wednesday, July 11, 2012

Resolver


# I have to write an app that does the following via input/output of csv:
#0.first thing you have to do is move the excel files into a sqlite3 data base
#1.<priority> Identify type 1 clashes and type 2 clashes resolves type 1 clashes.
# 2.<priority> resolves type 2 clashes.
# 3.<priority> tasks should be distributed evenly within the same institute (no randoms)
# 4.<optional> doesn't assign teams taks to NON-teams.<-optional
# 5.<optional> assigns correct taskes to teams.
# 6.
# Helper: if times are different, no clashes happen.
# Helper: for clashes, either switch task or reschedule trainee.
# Helper:csv.writer
# Helper: to caputre a csv.reader: x=list(reader)
# Helper: a fast way to do this: data=list(csv.reader(open(file)))
# Helper: filtering has to go like this TC>major>date>time> resolve clash t1 or t2
# TODO: get_data has to take arguments (badge,name..etc) and return the proper data
# REFACTORING: To increase speed isolate the data that requires modification and work on those only instead of doing an operation on the whole data set.

import csv, sqlite3


#first create a connection
conn = sqlite3.connect(":memory:") #unless this is ":memory:" this database will be created in your CWD which is the resolver folder

#second create a cursor object
c = conn.cursor()

#third exeCute! <<-THE THREE Cs connect, cursor, exeCute
c.execute("create table test (badge integer, name text, course_code text, test_date text, time text)")

reader = csv.reader(open("table2.csv", "r"))
for badge, name, course_code, test_date, time in reader:
  c.execute('INSERT INTO test (badge, name, course_code, test_date, time) VALUES (?,?,?,?,?)', (badge, name, course_code, test_date, time))

c.execute('select count(*) from test')
#c.execute("select badge, course_code='NWO103', test_date, time, count(*) from test group by course_code, test_date having count(*)>1")


for data in c:
    print(data)

conn.commit()
c.close()
5 Khalid's Python Journal: Resolver # I have to write an app that does the following via input/output of csv: #0.first thing you have to do is move the excel files into a sq...

No comments:

Post a Comment

< >