Skip to content

Commit 72d1ba4

Browse files
committed
Now it can import and export from csv. Also a few other improvements in making lists.
1 parent 75c74ae commit 72d1ba4

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

seatingchart/people5.xlsx

-46.3 KB
Binary file not shown.

seatingchart/people6.xlsx

8.57 KB
Binary file not shown.

seatingchart/seatingchart.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
import random
1010
import numpy as np
11+
import pandas
1112
#Make classes
1213

1314
class Guest():
@@ -55,6 +56,26 @@ def __init__(self,guestnames=None):
5556
self.guests = [Guest(name) for name in guestnames]
5657
self.guestdict = {g.get_name():g for g in self.guests}
5758

59+
def fromExcel(self, excelfile):
60+
peopledf = pandas.read_excel(excelfile)
61+
#Read in all the names
62+
allnames = set()
63+
for column in peopledf[1:]:
64+
for rownum in peopledf.index:
65+
name = peopledf.iloc[rownum][column]
66+
#print rownum, column, name
67+
if name is np.nan:
68+
continue
69+
allnames.add(name)
70+
self.guests = [Guest(name) for name in allnames]
71+
self.guestdict = {g.get_name():g for g in self.guests}
72+
73+
#Find all the friends
74+
for rownum in peopledf.index:
75+
friends = [str(name) for name in peopledf.iloc[rownum].values if name is not np.nan]
76+
[self.guestdict[friend].set_friendnames(friends) for friend in friends]
77+
78+
5879
def insert_guest(self,guest):
5980
self.guests.append(guest)
6081
self.guestdict[guest.get_name()]=guest
@@ -179,6 +200,11 @@ def print_seatingchart(self):
179200
index = self.seatdict[n]
180201
print (n,index)
181202

203+
def to_excel(self, outfile='SeatingChart.xlsx'):
204+
chartdf = pandas.DataFrame(self.chart)
205+
chartdf.index = ["Table {0}".format(i) for i in chartdf.index]
206+
chartdf.to_excel(outfile)
207+
182208

183209
class Organizer():
184210
def __init__(self,guestlist,seatingchart):

seatingchart/seatingchart.pyc

1.21 KB
Binary file not shown.

seatingchart/testseatingchart3.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,12 @@
44
import matplotlib.pyplot as plt
55
import copy
66

7-
guests = ["Antonette",
8-
"Cinda",
9-
"Nathan",
10-
"Deidra",
11-
"Merna",
12-
"Renata",
13-
"Londa",
14-
"Lila",
15-
"Kathryne",
16-
"Lieselotte",
17-
"Teofila",
18-
"Hubert",
19-
"Isadora",
20-
"Elina",
21-
"Enola",
22-
"Emile",
23-
"Brendan",
24-
"Kit",
25-
"Deetta",
26-
"Jade"
27-
]
28-
29-
guestlist = sc.GuestList(guestnames=guests)
30-
for i,g in enumerate(guests):
31-
gn = guests.pop(i)
32-
friends = random.sample(guests,10)
33-
guests.insert(i,gn)
34-
35-
guestlist.guestdict[gn].set_friendnames(friends)
36-
37-
nguests = len(guests)
7+
guestlist = sc.GuestList()
8+
guestlist.fromExcel('people6.xlsx')
9+
guestlist.print_friendlist()
10+
11+
12+
nguests = len(guestlist.guests)
3813
seatsper = 5
3914

4015
chart = sc.SeatingChart(guestlist,nguests/seatsper,seatsper)
@@ -83,6 +58,10 @@
8358
plt.xlabel="step"
8459
plt.ylabel="friendships"
8560

61+
org0.sc.to_excel('SeatingChart0.xlsx')
62+
org1.sc.to_excel('SeatingChart1.xlsx')
63+
64+
8665
plt.show()
8766

8867

0 commit comments

Comments
 (0)