Skip to content

Commit e8396bb

Browse files
committed
added main method and a readme
1 parent 03847dc commit e8396bb

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

Diff for: seatingchart/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Seating Chart readme
2+
3+
This program creates a seating chart from a list of guests and the friendships between the guests.
4+
5+
Usage from the terminal:
6+
$ python -m seatingchart.seatingchart <excelfilein> <excelfileout>

Diff for: seatingchart/example/testseatingchart3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
org = sc.Organizer(guestlist, chart)
2020
org0 = sc.Organizer(guestlist, chart0)
2121
# Seat everyone
22-
org.seatguests()
22+
org.seatguestsfriends()
2323

2424
print "The final seating chart"
2525
chart.print_seatingchart()

Diff for: seatingchart/seatingchart.py

+60-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import random
22
import numpy as np
33
import pandas
4+
import matplotlib.pyplot as plt
45

56
"""
67
This simple program will try to sort out a seating chart from a list of
@@ -139,6 +140,9 @@ def pick_friend_of(self, guestname):
139140

140141
def seat_guest(self, guestname):
141142
n = guestname
143+
if len(self.open) == 0:
144+
print "No more seats!"
145+
return
142146
seatindex = self.open.pop(random.randrange(len(self.open)))
143147
self.chart[seatindex[0]][seatindex[1]] = n
144148

@@ -148,19 +152,18 @@ def seat_guest(self, guestname):
148152
self.toseat.remove(n)
149153

150154
def seat_guest_here(self, guestname, index):
151-
n = guestname
152155
# check if the seat is open
153156
if self.open.count(index) == 0:
154157
print "the seat is already filled!!"
155158
return None
156159
else:
157160
self.open.remove(index)
158-
self.chart[index[0]][index[1]] = n
161+
self.chart[index[0]][index[1]] = guestname
159162

160163
# update the seatdict, and seated
161-
self.seated.append(n)
162-
self.seatdict[n] = index
163-
self.toseat.remove(n)
164+
self.seated.append(guestname)
165+
self.seatdict[guestname] = index
166+
self.toseat.remove(guestname)
164167

165168
def seat_guestfriend(self, guestname, friendname):
166169
"""
@@ -355,3 +358,55 @@ def metropolisstep(self, temp=0.1):
355358
else:
356359
print "it's temporarily worse but keep it"
357360
return friendcount1
361+
362+
def main(excelfilein,excelfileout):
363+
guestlist = GuestList()
364+
guestlist.fromExcel(excelfilein)
365+
guestlist.print_friendlist()
366+
367+
368+
nguests = len(guestlist.guests)
369+
print nguests
370+
seatsper = 8
371+
print nguests/seatsper
372+
373+
chart = SeatingChart(guestlist, nguests/seatsper+1, seatsper)
374+
org = Organizer(guestlist, chart)
375+
# Seat everyone
376+
print "Seat guests with a friend"
377+
org.seatguestsfriends()
378+
print "now do Metropolis algorithim to increase friendships"
379+
count0 = org.friendcount()
380+
nsteps = 1000
381+
friendsT1 = np.zeros(nsteps)
382+
steps = np.arange(nsteps)
383+
for i in steps:
384+
print i
385+
friendsT1[i] = org.metropolisstep(temp=0.01)
386+
count1 = org.friendcount()
387+
print "Metropolis algorithm added {0} friends".format(count1-count0)
388+
print "export seating chart to an excel file"
389+
plt.plot(steps, friendsT1, label='T1')
390+
plt.xlabel = "step"
391+
plt.ylabel = "friendships"
392+
plt.show()
393+
org.sc.to_excel(excelfileout)
394+
395+
396+
if __name__ == '__main__':
397+
import sys
398+
umesg = "python -m seatingchart.seatingchar excelfilein (excelfileout)"
399+
if len(sys.argv) > 1:
400+
# print 'nothing here'
401+
if len(sys.argv) > 2:
402+
excelfilein = sys.argv[1]
403+
excelfileout = sys.argv[2]
404+
main(excelfilein, excelfileout)
405+
else:
406+
excelfilein = sys.argv[1]
407+
excelfileout = excelfilein[:-5]+"out"+excelfilein[-5:]
408+
main(excelfilein, excelfileout)
409+
else:
410+
print umesg
411+
412+

Diff for: seatingchart/seatingchart.pyc

1.07 KB
Binary file not shown.

0 commit comments

Comments
 (0)