-
Notifications
You must be signed in to change notification settings - Fork 9
/
Program.cs
818 lines (727 loc) · 38.3 KB
/
Program.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
using CsvHelper;
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace prospectScraper
{
class Program
{
static void Main(string[] args)
{
// Initial attempt to handle command line arguments.
// "b" for the big boards, "m" for mock drafts, "e" for everything
if (args.Length == 0)
{
Console.WriteLine("No Arguments");
RunTheBigBoards();
}
else
{
string s = args[0].ToString().ToLower();
switch(s)
{
case "bb":
Console.WriteLine("Running Big Board");
RunTheBigBoards();
break;
case "md":
Console.WriteLine("Running Mock Draft");
RunTheMockDraft();
break;
case "all":
Console.WriteLine("Running Big Board and Mock Draft");
RunTheBigBoards();
RunTheMockDraft();
break;
default:
Console.WriteLine("Input argument of " + s + " not recognized. Please try running again.");
RunTheBigBoards();
break;
}
}
//RunTheBigBoards();
}
private static void RunTheBigBoards()
{
File.WriteAllText($"logs{Path.DirectorySeparatorChar}Status.log", "");
File.WriteAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "");
Console.WriteLine("Getting data...");
var webGet = new HtmlWeb();
webGet.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0";
var document1 = webGet.Load("https://www.drafttek.com/2021-NFL-Draft-Big-Board/Top-NFL-Draft-Prospects-2021-Page-1.asp");
var document2 = webGet.Load("https://www.drafttek.com/2021-NFL-Draft-Big-Board/Top-NFL-Draft-Prospects-2021-Page-2.asp");
var document3 = webGet.Load("https://www.drafttek.com/2021-NFL-Draft-Big-Board/Top-NFL-Draft-Prospects-2021-Page-3.asp");
var document4 = webGet.Load("https://www.drafttek.com/2021-NFL-Draft-Big-Board/Top-NFL-Draft-Prospects-2021-Page-4.asp");
var document5 = webGet.Load("https://www.drafttek.com/2021-NFL-Draft-Big-Board/Top-NFL-Draft-Prospects-2021-Page-5.asp");
Console.WriteLine("Parsing data...");
//Get ranking date
var dateOfRanks = document1.DocumentNode.SelectSingleNode("//*[@id='HeadlineInfo1']").InnerText.Replace(" EST", "").Trim();
//Change date to proper date. The original format should be like this:
//" May 21, 2019 2:00 AM EST"
DateTime parsedDate;
DateTime.TryParse(dateOfRanks, out parsedDate);
string dateInNiceFormat = parsedDate.ToString("yyyy-MM-dd");
List<ProspectRanking> list1 = GetProspects(document1, parsedDate, 1);
List<ProspectRanking> list2 = GetProspects(document2, parsedDate, 2);
List<ProspectRanking> list3 = GetProspects(document3, parsedDate, 3);
List<ProspectRanking> list4 = GetProspects(document4, parsedDate, 4);
List<ProspectRanking> list5 = GetProspects(document5, parsedDate, 5);
//This is the file name we are going to write.
var csvFileName = $"ranks{Path.DirectorySeparatorChar}{dateInNiceFormat}-ranks.csv";
Console.WriteLine("Creating csv...");
//Write projects to csv with date.
using (var writer = new StreamWriter(csvFileName))
using (var csv = new CsvWriter(writer))
{
csv.Configuration.RegisterClassMap<ProspectRankingMap>();
csv.WriteRecords(list1);
csv.WriteRecords(list2);
csv.WriteRecords(list3);
if (list4.Count > 0)
{
csv.WriteRecords(list4);
}
if (list5.Count > 0)
{
csv.WriteRecords(list5);
}
}
CheckForMismatches(csvFileName);
CreateCombinedCSV();
CheckForMismatches($"ranks{Path.DirectorySeparatorChar}combinedRanks2021.csv");
CreateCombinedCSVWithExtras();
Console.WriteLine("Big Board Completed.");
}
private static void RunTheMockDraft()
{
//TODO - Implement Mock Draft
var webGet = new HtmlWeb();
webGet.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0";
var document1 = webGet.Load("https://www.drafttek.com/2021-NFL-Mock-Draft/2021-NFL-Mock-Draft-Round-1.asp");
var document2 = webGet.Load("https://www.drafttek.com/2021-NFL-Mock-Draft/2021-NFL-Mock-Draft-Round-1b.asp");
var document3 = webGet.Load("https://www.drafttek.com/2021-NFL-Mock-Draft/2021-NFL-Mock-Draft-Round-2.asp");
var document4 = webGet.Load("https://www.drafttek.com/2021-NFL-Mock-Draft/2021-NFL-Mock-Draft-Round-3.asp");
var document5 = webGet.Load("https://www.drafttek.com/2021-NFL-Mock-Draft/2021-NFL-Mock-Draft-Round-4.asp");
var document6 = webGet.Load("https://www.drafttek.com/2021-NFL-Mock-Draft/2021-NFL-Mock-Draft-Round-6.asp");
//Console.WriteLine(document1.ParsedText);
//#content > table:nth-child(9)
//html body div#outer div#wrapper2 div#content table
///html/body/div[3]/div[3]/div[1]/table[1]
// Need to get date of mock draft eventually.
string draftDate = getDraftDate(document1);
List<MockDraftPick> list1 = getMockDraft(document1, draftDate);
List<MockDraftPick> list2 = getMockDraft(document2, draftDate);
List<MockDraftPick> list3 = getMockDraft(document3, draftDate);
List<MockDraftPick> list4 = getMockDraft(document4, draftDate);
List<MockDraftPick> list5 = getMockDraft(document5, draftDate);
List<MockDraftPick> list6 = getMockDraft(document6, draftDate);
//This is the file name we are going to write.
var csvFileName = $"mocks{Path.DirectorySeparatorChar}{draftDate}-mock.csv";
Console.WriteLine("Creating csv...");
//Write projects to csv with date.
using (var writer = new StreamWriter(csvFileName))
using (var csv = new CsvWriter(writer))
{
csv.Configuration.RegisterClassMap<MockDraftPickMap>();
csv.WriteRecords(list1);
csv.WriteRecords(list2);
csv.WriteRecords(list3);
csv.WriteRecords(list4);
csv.WriteRecords(list5);
csv.WriteRecords(list6);
}
Console.WriteLine("Checking for mock draft mismatches...");
CheckForMockDraftMismatches(list1, "top of the first round");
CheckForMockDraftMismatches(list2, "second half of the first round");
CheckForMockDraftMismatches(list3, "second round");
CheckForMockDraftMismatches(list4, "third round");
CheckForMockDraftMismatches(list5, "fourth/fifth round");
CheckForMockDraftMismatches(list6, "sixth/seventh round");
CheckForMockDraftMismatches($"mocks{Path.DirectorySeparatorChar}{draftDate}-mock.csv");
// Document data is of type HtmlAgilityPack.HtmlDocument - need to parse it to find info.
// I'm pretty sure I'm looking for tables with this attribute: background-image: linear-gradient(to bottom right, #0b3661, #5783ad);
Console.WriteLine("Behold, the draft! Mock Draft Completed.");
}
public static List<MockDraftPick> getMockDraft(HtmlAgilityPack.HtmlDocument doc, string pickDate)
{
List<MockDraftPick> mdpList = new List<MockDraftPick>();
// This is still messy from debugging the different values. It should be optimized.
var dn = doc.DocumentNode;
var dns = dn.SelectNodes("/html/body/div/div/div/table");
var attr = dns[1].Attributes;
var attrs = attr.ToArray();
var style = attr.FirstOrDefault().Value;
var ss = style.ToString();
bool hasStyle = ss.IndexOf("background-image: linear-gradient", StringComparison.OrdinalIgnoreCase) >= 0;
foreach(var node in dns)
{
var nodeStyle = node.Attributes.FirstOrDefault().Value.ToString();
bool hasTheStyle = node.Attributes.FirstOrDefault().Value.ToString().IndexOf("background-image: linear-gradient", StringComparison.OrdinalIgnoreCase) >= 0;
if (hasTheStyle)
{
var tr = node.SelectSingleNode("tr");
MockDraftPick mockDraftPick = createMockDraftEntry(tr, pickDate);
mdpList.Add(mockDraftPick);
}
}
var hasGradient = dns[1].Attributes.Contains("background-image");
return mdpList;
}
public static MockDraftPick createMockDraftEntry(HtmlNode tableRow, string pickDate)
{
var childNodes = tableRow.ChildNodes;
var node1 = childNodes[1].InnerText; //pick number?
string pickNumber = node1.Replace("\r","")
.Replace("\n","")
.Replace("\t","")
.Replace(" ","");
var node3 = childNodes[3]; //team (and team image)?
var teamCity = node3.ChildNodes[0].InnerText
.Replace("\r","")
.Replace("\n","")
.Replace("\t","")
.TrimEnd();
var node5 = childNodes[5]; //Has Child Nodes - Player, School, Position, Reach/Value
string playerName = node5.ChildNodes[1].InnerText
.Replace("\r","")
.Replace("\n","")
.Replace("\t","")
.TrimEnd();
string playerSchoolBeforeChecking = node5.ChildNodes[3].InnerText
.Replace("\r","")
.Replace("\n","")
.Replace("\t","")
.TrimEnd(); // this may have a space afterwards.
string playerSchool = checkSchool(playerSchoolBeforeChecking);
string playerPosition = node5.ChildNodes[5].InnerText
.Replace("\r","")
.Replace("\n","")
.Replace("\t","")
.Replace(" ","");
string reachValue = node5.ChildNodes[9].InnerText
.Replace("\r","")
.Replace("\n","")
.Replace("\t","")
.Replace(" ","");
MockDraftPick mdp = new MockDraftPick(pickNumber, teamCity, playerName, playerSchool, playerPosition, reachValue, pickDate);
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Mock Draft Round: " + mdp.round + Environment.NewLine);
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Pick Number: " + mdp.pickNumber + Environment.NewLine);
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Player: " + mdp.playerName + Environment.NewLine);
//Console.WriteLine(mdp.round);
//Console.WriteLine(mdp.leagifyPoints);
//Console.WriteLine(mdp.pickNumber);
//Console.WriteLine(mdp.teamCity);
//Console.WriteLine(mdp.playerName);
//Console.WriteLine(mdp.school);
//Console.WriteLine(mdp.position);
//Console.WriteLine(mdp.reachValue);
//Console.WriteLine(mdp.state);
return mdp;
}
public static string getDraftDate(HtmlAgilityPack.HtmlDocument doc)
{
HtmlNode hn = doc.DocumentNode;
HtmlNode hi1 = hn.SelectSingleNode("//*[@id='HeadlineInfo1']");
//Console.WriteLine(hi1.InnerText);
string hi2 = hi1.InnerText.Replace(" EST", "").Trim();
//Change date to proper date. The original format should be like this:
//" May 21, 2019 2:00 AM EST"
DateTime parsedDate;
bool parseWorks = DateTime.TryParse(hi2, out parsedDate);
string dateInNiceFormat = "";
if (parseWorks)
{
dateInNiceFormat = parsedDate.ToString("yyyy-MM-dd");
}
else
{
dateInNiceFormat = DateTime.Now.ToString("yyyy-MM-dd");
}
Console.WriteLine("Mock Draft - Date parsed: " + parsedDate + " - File name will be: "+ dateInNiceFormat + "-mock.csv");
return dateInNiceFormat;
}
private static void CreateCombinedCSV()
{
//Combine ranks from CSV files to create a master CSV.
var filePaths = Directory.GetFiles($"ranks{Path.DirectorySeparatorChar}", "20??-??-??-ranks.csv").ToList<String>();
//The results are probably already sorted, but I don't trust that, so I'm going to sort manually.
filePaths.Sort();
string destinationFile = $"ranks{Path.DirectorySeparatorChar}combinedRanks2021.csv";
// Specify wildcard search to match CSV files that will be combined
StreamWriter fileDest = new StreamWriter(destinationFile, false);
int i;
for (i = 0; i < filePaths.Count; i++)
{
string file = filePaths[i];
string[] lines = File.ReadAllLines(file);
if (i > 0)
{
lines = lines.Skip(1).ToArray(); // Skip header row for all but first file
}
foreach (string line in lines)
{
fileDest.WriteLine(line);
}
}
fileDest.Close();
}
private static void CreateCombinedCSVWithExtras()
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", "Creating the big CSV....." + Environment.NewLine);
// Get Schools and the States where they are located.
List<School> schoolsAndConferences;
using (var reader = new StreamReader($"info{Path.DirectorySeparatorChar}SchoolStatesAndConferences.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<SchoolCsvMap>();
schoolsAndConferences = csv.GetRecords<School>().ToList();
}
List<Region> statesAndRegions;
using(var reader = new StreamReader($"info{Path.DirectorySeparatorChar}StatesToRegions.csv"))
using(var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<RegionCsvMap>();
statesAndRegions = csv.GetRecords<Region>().ToList();
}
//Get position types
List<PositionType> positionsAndTypes;
using (var reader = new StreamReader($"info{Path.DirectorySeparatorChar}PositionInfo.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<PositionTypeCsvMap>();
positionsAndTypes = csv.GetRecords<PositionType>().ToList();
}
// Let's assign these ranks point values.
List<PointProjection> ranksToProjectedPoints;
using (var reader = new StreamReader($"info{Path.DirectorySeparatorChar}RanksToProjectedPoints.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<PointProjectionCsvMap>();
ranksToProjectedPoints = csv.GetRecords<PointProjection>().ToList();
}
//Combine ranks from CSV files to create a master CSV.
var filePaths = Directory.GetFiles($"ranks{Path.DirectorySeparatorChar}", "20??-??-??-ranks.csv").ToList<String>();
//The results are probably already sorted, but I don't trust that, so I'm going to sort manually.
filePaths.Sort();
string destinationFile = $"ranks{Path.DirectorySeparatorChar}joinedRanks2021.csv";
// Specify wildcard search to match CSV files that will be combined
StreamWriter fileDest = new StreamWriter(destinationFile, false);
int i;
for (i = 0; i < filePaths.Count; i++)
{
string file = filePaths[i];
string[] lines = File.ReadAllLines(file);
if (i > 0)
{
lines = lines.Skip(1).ToArray(); // Skip header row for all but first file
}
foreach (string line in lines)
{
fileDest.WriteLine(line);
}
}
fileDest.Close();
// Get ranks from the newly created CSV file.
List<ExistingProspectRanking> prospectRanks;
using (var reader = new StreamReader($"ranks{Path.DirectorySeparatorChar}joinedRanks2021.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<ExistingProspectRankingCsvMap>();
prospectRanks = csv.GetRecords<ExistingProspectRanking>().ToList();
}
// Use linq to join the stuff back together, then write it out again.
var combinedHistoricalRanks = from r in prospectRanks
join school in schoolsAndConferences on r.school equals school.schoolName
join region in statesAndRegions on school.state equals region.state
join positions in positionsAndTypes on r.position1 equals positions.positionName
join rank in ranksToProjectedPoints on r.rank equals rank.rank
select new {
Rank = r.rank,
Change = r.change,
Name = r.playerName,
Position = r.position1,
College = r.school,
Conference = school.conference,
State = school.state,
Region = region.region,
Height = r.height,
Weight = r.weight,
CollegeClass = r.collegeClass,
PositionGroup = positions.positionGroup,
PositionAspect = positions.positionAspect,
ProspectStatus = r.draftStatus,
Date = r.rankingDateString,
Points = rank.projectedPoints
};
//Write everything back to CSV, only better!
using (var writer = new StreamWriter($"ranks{Path.DirectorySeparatorChar}joinedRanks2021.csv"))
using (var csv = new CsvWriter(writer))
{
csv.WriteRecords(combinedHistoricalRanks);
}
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", "Creating the big CSV completed." + Environment.NewLine);
}
private static void CheckForMismatches(string csvFileName)
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", "Checking for mismatches in " + csvFileName + "....." + Environment.NewLine);
// Read in data from a different project.
List<School> schoolsAndConferences;
using (var reader = new StreamReader($"info{Path.DirectorySeparatorChar}SchoolStatesAndConferences.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<SchoolCsvMap>();
schoolsAndConferences = csv.GetRecords<School>().ToList();
}
List<ProspectRankSimple> ranks;
using (var reader = new StreamReader(csvFileName))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<ProspectRankSimpleCsvMap>();
ranks = csv.GetRecords<ProspectRankSimple>().ToList();
}
var schoolMismatches = from r in ranks
join school in schoolsAndConferences on r.school equals school.schoolName into mm
from school in mm.DefaultIfEmpty()
where school is null
select new {
rank = r.rank,
name = r.playerName,
college = r.school
}
;
bool noMismatches = true;
if (schoolMismatches.Count() > 0)
{
File.WriteAllText($"logs{Path.DirectorySeparatorChar}Mismatches.log", "");
}
foreach (var s in schoolMismatches){
noMismatches = false;
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Mismatches.log", $"{s.rank}, {s.name}, {s.college}" + Environment.NewLine);
}
if (noMismatches)
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", "No mismatches in " + csvFileName + "....." + Environment.NewLine);
}
else
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", schoolMismatches.Count() + " mismatches in " + csvFileName + ".....Check Mismatches.log." + Environment.NewLine);
}
}
public static List<ProspectRanking> GetProspects(HtmlDocument document, DateTime dateOfRanks, int pageNumber)
{
// Create variables to store prospect rankings.
int rank = 0;
string change = "";
string playerName = "";
string school = "";
string position1 = "";
string height = "";
int weight = 0;
string collegeClass = "";
List<ProspectRanking> prospectList = new List<ProspectRanking>();
if (document.DocumentNode != null)
{
// "/html[1]/body[1]/div[1]/div[3]/div[1]/table[1]"
var tbl = document.DocumentNode.SelectNodes("/html[1]/body[1]/div[1]/div[3]/div[1]/table[1]");
if (tbl == null)
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", $"No prospects on page {pageNumber}" + Environment.NewLine);
return prospectList;
}
foreach (HtmlNode table in tbl) {
foreach (HtmlNode row in table.SelectNodes("tr")) {
foreach (HtmlNode cell in row.SelectNodes("th|td")) {
string Xpath = cell.XPath;
int locationOfColumnNumber = cell.XPath.Length - 2 ;
char dataIndicator = Xpath[locationOfColumnNumber];
bool isRank = (dataIndicator == '1');
switch (dataIndicator)
{
case '1':
// td[1]= Rank
if (Int32.TryParse(cell.InnerText, out int rankNumber))
rank = rankNumber;
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Big Board Rank: " + cell.InnerText + Environment.NewLine);
break;
case '2':
// td[2]= Change
change = cell.InnerText;
change = change.Replace(" ","");
break;
case '3':
// td[3]= Player
playerName = cell.InnerText;
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Player: " + cell.InnerText + Environment.NewLine);
break;
case '4':
// td[4]= School
school = checkSchool(cell.InnerText);
break;
case '5':
// td[5]= Pos1
position1 = cell.InnerText;
break;
case '6':
// td[6]= Ht
height = cell.InnerText;
break;
case '7':
// td[7]= Weight
if (Int32.TryParse(cell.InnerText, out int weightNumber))
weight = weightNumber;
break;
case '8':
// College Class- used to be Pos2 (which was often blank)
collegeClass = cell.InnerText;
break;
case '9':
// td[9]= Link to Bio (not used)
continue;
default:
break;
}
}
// Handle draft eligibility and declarations (done via row color)
string draftStatus = "";
if (row.Attributes.Contains("style") && row.Attributes["style"].Value.Contains("background-color"))
{
string rowStyle = row.Attributes["style"].Value;
string backgroundColor = Regex.Match(rowStyle, @"background-color: \w*").Value.Substring(18);
switch (backgroundColor)
{
case "white":
draftStatus = "Eligible";
break;
case "lightblue":
draftStatus = "Underclassman";
break;
case "palegoldenrod":
draftStatus = "Declared";
break;
default:
draftStatus = "";
break;
}
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Draft Status: " + draftStatus + Environment.NewLine);
}
// The header is in the table, so I need to ignore it here.
if (change != "CNG")
{
prospectList.Add(new ProspectRanking(dateOfRanks, rank, change, playerName, school, position1, height, weight, collegeClass, draftStatus));
}
}
}
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", $"Prospect count on page {pageNumber}: {prospectList.Count}" + Environment.NewLine);
}
return prospectList;
}
public static string checkSchool(string school)
{
switch(school)
{
case "Miami":
return "Miami (FL)";
case "Mississippi":
return "Ole Miss";
case "Central Florida":
return "UCF";
case "MTSU":
return "Middle Tennessee";
case "Eastern Carolina":
return "East Carolina";
case "Pittsburgh":
return "Pitt";
case "FIU":
return "Florida International";
case "Florida St":
return "Florida State";
case "Penn St":
return "Penn State";
case "Minneosta":
return "Minnesota";
case "Mississippi St.":
return "Mississippi State";
case "Mississippi St":
return "Mississippi State";
case "Oklahoma St":
return "Oklahoma State";
case "Boise St":
return "Boise State";
case "Lenoir-Rhyne":
return "Lenoir–Rhyne";
case "NCState":
return "NC State";
case "W Michigan":
return "Western Michigan";
case "UL Lafayette":
return "Louisiana-Lafayette";
case "Cal":
return "California";
case "S. Illinois":
return "Southern Illinois";
case "UConn":
return "Connecticut";
case "LA Tech":
return "Louisiana Tech";
case "Louisiana":
return "Louisiana-Lafayette";
case "San Diego St":
return "San Diego State";
case "South Carolina St":
return "South Carolina State";
case "Wake Forrest":
return "Wake Forest";
case "NM State":
return "New Mexico State";
case "New Mexico St":
return "New Mexico State";
case "Southern Cal":
return "USC";
case "Mempis":
return "Memphis";
case "Southeast Missouri":
return "Southeast Missouri State";
case "Berry College":
return "Berry";
case "USF":
return "South Florida";
case "N Dakota State":
return "North Dakota State";
case "SE Missouri State":
return "Southeast Missouri State";
case "Appalachian St":
return "Appalachian State";
case "N Illinois":
return "Northern Illinois";
case "UL Monroe":
return "Louisiana-Monroe";
case "Central Missouri St":
return "Central Missouri";
case "North Carolina State":
return "NC State";
default:
return school;
}
}
public static int convertHeightToInches(string height, string playerName)
{
// Height might look something like "\"6'1\"\"\"" - convert to inches to look less awful.
string regexHeight = Regex.Match(height, @"\d'\d+").Value;
string[] feetAndInches = regexHeight.Split("'");
bool parseFeet = Int32.TryParse(feetAndInches[0], out int feet);
int inches = 0;
bool parseInches = false;
if (feetAndInches.Length > 1 && feetAndInches[1] != null)
{
parseInches = Int32.TryParse(feetAndInches[1], out inches);
}
if (parseFeet && parseInches)
{
int heightInInches = (feet*12)+inches;
return heightInInches;
}
else
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Mismatches.log", $"Player {playerName} height of {height} not converted properly, entring 0 instead" + Environment.NewLine);
return 0;
}
}
private static void CheckForMockDraftMismatches(List<MockDraftPick> listOfPicks, string description)
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", "Checking for mismatches in " + description + "....." + Environment.NewLine);
//Console.WriteLine("Checking for Mock Draft mismatches in "+ description + "....");
// Read in data from a different project.
List<School> schoolsAndConferences;
using (var reader = new StreamReader($"info{Path.DirectorySeparatorChar}SchoolStatesAndConferences.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<SchoolCsvMap>();
schoolsAndConferences = csv.GetRecords<School>().ToList();
}
List<MockDraftPick> ranks = listOfPicks;
var schoolMismatches = from r in ranks
join school in schoolsAndConferences on r.school equals school.schoolName into mm
from school in mm.DefaultIfEmpty()
where school is null
select new {
rank = r.pickNumber,
name = r.playerName,
college = r.school
}
;
bool noMismatches = true;
if (schoolMismatches.Count() > 0)
{
File.WriteAllText($"logs{Path.DirectorySeparatorChar}Mismatches.log", "");
}
foreach (var s in schoolMismatches){
noMismatches = false;
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Mismatches.log", $"Mock draft mismatch: {s.rank}, {s.name}, {s.college}" + Environment.NewLine);
//Console.WriteLine($"{s.rank}, {s.name}, {s.college}");
}
if (noMismatches)
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", "No mismatches in " + description + "....." + Environment.NewLine);
//Console.WriteLine("No mismatches in " + listOfPicks.ToString() + ".....");
}
else
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", schoolMismatches.Count() + " mismatches in list of picks from " + description + ".....Check Mismatches.log." + Environment.NewLine);
//Console.WriteLine(schoolMismatches.Count() + " mismatches in " + listOfPicks.ToString() + ".....");
}
}
private static void CheckForMockDraftMismatches(string csvFileName)
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", "Checking for mismatches in " + csvFileName + "....." + Environment.NewLine);
//Console.WriteLine("Checking for mismatches in " + csvFileName + ".....");
// Read in data from a different project.
List<School> schoolsAndConferences;
using (var reader = new StreamReader($"info{Path.DirectorySeparatorChar}SchoolStatesAndConferences.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<SchoolCsvMap>();
schoolsAndConferences = csv.GetRecords<School>().ToList();
}
List<MockDraftPick> ranks;
using (var reader = new StreamReader(csvFileName))
using (var csv = new CsvReader(reader))
{
csv.Configuration.RegisterClassMap<MockDraftPickCsvMap>();
ranks = csv.GetRecords<MockDraftPick>().ToList();
}
var schoolMismatches = from r in ranks
join school in schoolsAndConferences on r.school equals school.schoolName into mm
from school in mm.DefaultIfEmpty()
where school is null
select new {
rank = r.pickNumber,
name = r.playerName,
college = r.school
}
;
bool noMismatches = true;
if (schoolMismatches.Count() > 0)
{
//File.WriteAllText($"logs{Path.DirectorySeparatorChar}Mismatches.log", "");
}
foreach (var s in schoolMismatches){
noMismatches = false;
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Mismatches.log", $"{s.rank}, {s.name}, {s.college}" + Environment.NewLine);
//Console.WriteLine($"{s.rank}, {s.name}, {s.college}");
}
if (noMismatches)
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", "No mismatches in " + csvFileName + "....." + Environment.NewLine);
//Console.WriteLine("No mismatches in " + csvFileName + ".....");
}
else
{
File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", schoolMismatches.Count() + " mismatches in " + csvFileName + ".....Check Mismatches.log." + Environment.NewLine);
//Console.WriteLine(schoolMismatches.Count() + " mismatches in " + csvFileName + ".....");
}
}
}
}