-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkingCopy.cs
275 lines (229 loc) · 8.26 KB
/
WorkingCopy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class test
{
static void Main()
{
string fileName = "yolo";
Console.WriteLine(" creating new course from {0}", fileName);
Course course = new Course( fileName );
Console.WriteLine ( "done" );
//#YOLO#FOREACH
foreach( Section sec in course.sections )
{
foreach( TimeSlot tSlot in sec.timeSlot )
Console.WriteLine( "{0}, {1}, {2}, {3}, {4}", tSlot.Day, tSlot.Instructor, tSlot.StartTime, tSlot.Length, tSlot.Location) ;
}
}
}
class Course
{
//Declares an array of undefined length which will be determined later
public Section[] sections;
public Course(string fileName)
{
StreamReader sr = new StreamReader( fileName + ".txt" );
string currentLine = sr.ReadLine();
int sectionCount = 0;
// Counts the number of sections in the file
while( !sr.EndOfStream )
{
if( currentLine.Contains( "Section" ) )
sectionCount++;
currentLine = sr.ReadLine();
}
sections = new Section[ sectionCount ];
// Go back to beginning of stream
sr.DiscardBufferedData();
sr.BaseStream.Seek(0, SeekOrigin.Begin);
sr.BaseStream.Position = 0;
currentLine = sr.ReadLine();
for( int i = 0; i < sectionCount; i++ )
sections[i] = new Section();
// Change input into data for each section
while( !sr.EndOfStream ){
foreach( Section section in sections )
{
// Go to the first instance of a section (001)
while( currentLine == "" || currentLine[0] < '0' || currentLine[0] > '9' )
{
currentLine = sr.ReadLine();
}
// Get section number and section type
section.Num = Convert.ToInt32(currentLine.Substring(0, 3));
section.Type = currentLine.Substring( 4, 3 );
// Go to the heading of time slots
while( currentLine == "" || currentLine[0] != 'D' )
currentLine = sr.ReadLine();
// Go to first line of time slots
currentLine = sr.ReadLine();
// Make array list with variable length to get the time slots
List <TimeSlot> timeSlotList = new List<TimeSlot>();
// Go through time slots and add them to the list
while( !String.IsNullOrWhiteSpace(currentLine) )
{
int cursor = 0;
int additionCount = 0;
// Finds the day(s) of the section
while( currentLine[cursor] != ' ' )
{
TimeSlot tempTimeSlot = new TimeSlot();
if( currentLine[cursor] == 'M' )
tempTimeSlot.Day = 0;
else if( currentLine[cursor] == 'T' && currentLine[cursor+1] != 'h' )
tempTimeSlot.Day = 1;
else if( currentLine[cursor] == 'W' )
tempTimeSlot.Day = 2;
else if( currentLine[cursor] == 'T' && currentLine[cursor+1] == 'h' )
tempTimeSlot.Day = 3;
else if( currentLine[cursor] == 'F' )
tempTimeSlot.Day = 4;
else if( currentLine[cursor] == 'S' )
tempTimeSlot.Day = 5;
if( currentLine[cursor] != 'h' )
{
timeSlotList.Add( tempTimeSlot );
additionCount++;
}
cursor++;
}
// Go to where the time stamp starts
cursor++;
string timeStamp = currentLine.Substring( cursor, currentLine.Length-1-cursor );
// Update the length of the course in minutes based on the timestamp
// Check whether the hour is represented by one or two numbers
int begHr = 2, endHr = 2;
if( timeStamp[1] == ':' && timeStamp[11] == ':' )
begHr = 1;
else if( timeStamp[1] != ':' && timeStamp[11] == ':' )
endHr = 1;
else if( timeStamp[1] == ':' && timeStamp[10] == ':' )
{
begHr = 1;
endHr = 1;
}
int startTime = Convert.ToInt32( timeStamp.Substring( 0, begHr ) ) * 60;
startTime += Convert.ToInt32( timeStamp.Substring( begHr+1, 2 ) );
int endTime = Convert.ToInt32( timeStamp.Substring( begHr+8, endHr ) ) * 60;
endTime += Convert.ToInt32( timeStamp.Substring( begHr+endHr+9, 2 ) );
if( timeStamp[begHr+3] == 'P'&& startTime < 12*60 )
startTime += 12*60;
if( timeStamp[begHr+endHr+11] == 'P' && endTime < 12*60)
endTime += 12*60;
int length = endTime - startTime;
// Find actual start time after 8am on half hour intervals
startTime = (startTime - 8*60)/30;
currentLine = sr.ReadLine();
// Update the location of the course
string location = currentLine;
currentLine = sr.ReadLine();
// Update the instructor for the course
string instructor = currentLine;
currentLine = sr.ReadLine();
// Skip over the dates -- unimportant
currentLine = sr.ReadLine();
// Update other fields of the latest additions to the List
for( int i = 0; i < additionCount; i++ )
{
int index = timeSlotList.Count-i-1;
timeSlotList[index].Length = length;
timeSlotList[index].Location = location;
timeSlotList[index].StartTime = startTime;
timeSlotList[index].Instructor = instructor;
}
}
// Create an array based on the List
TimeSlot [] timeSlots = new TimeSlot[timeSlotList.Count()];
for( int i = 0; i < timeSlotList.Count; i++ )
{
timeSlots[i] = timeSlotList[i];
}
// Set the time slot array to the section
section.TimeSlots = timeSlots;
}
}
}
/*public Section Sections
{
get { return sections; }
}*/
}
class Section
{
// enum Type { LECTURE, TUTORIAL, LAB };
public Section()
{
type = "";
num = 0;
}
public TimeSlot[] timeSlot;
private string type;
private int num;
public string Type
{
get { return type; }
set
{
type = value.ToLower();
}
}
public int Num
{
get { return num; }
set { num = value; }
}
public TimeSlot[] TimeSlots
{
get { return timeSlot; }
set { timeSlot = value; }
}
public void InitializeTimeSlots(int numOfTimeSlots)
{
TimeSlot[] timeSlots = new TimeSlot[numOfTimeSlots];
}
}
class TimeSlot
{
public TimeSlot()
{
day = 0;
instructor = "";
startTime = 0;
length = 0;
location = "";
}
enum WeekDay { M, T, W, Th, F, S, SU };
int day;
int startTime; //indexed by half hour from 0800 please
int length; //in minutes, please
string location;
private string instructor;
public int Day
{
get { return day; }
set { day = value; }
}
public int StartTime
{
get { return startTime; }
set { startTime = value; }
}
public int Length
{
get { return length; }
set { length = value; }
}
public string Location
{
get { return location; }
set { location = value; }
}
public string Instructor
{
get { return instructor; }
set { instructor = value; }
}
}