forked from zo0o0ot/draft-scorer-nfl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
676 lines (592 loc) · 25.6 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
using CsvHelper;
using HtmlAgilityPack;
using Spectre.Console;
using System.Text.RegularExpressions;
using SharpConfig;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Globalization;
// See https://aka.ms/new-console-template for more information
//Load config
var scraperConfig = Configuration.LoadFromFile("scorer.conf");
var draftSection = scraperConfig["Draft"];
var generalSection = scraperConfig["General"];
int draftYear = draftSection["DraftYear"].IntValue;
string urlPattern = draftSection["UrlPattern"].StringValue;
bool draftComplete = draftSection["DraftComplete"].BoolValue;
bool updateProspects = draftSection["UpdateProspectList"].BoolValue;
string apikey ="";
try
{
var localScraperConfig = Configuration.LoadFromFile("scorer.local.conf");
var localSection = localScraperConfig["API"];
apikey = localSection["apikey"].StringValue;
}
catch
{
apikey = "";
}
if (apikey == "")
{
AnsiConsole.WriteLine("No API key found. Please add one to scorer.local.conf");
return 0;
}
AnsiConsole.MarkupLine(":abacus: Loading Fantasy Draft :abacus:");
// Load from CSV named "FantasyDraft2021.csv"
var fantasyDraftPicks = new List<FantasyDraftPick>();
using (var reader = new StreamReader($"fantasy-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}FantasyDraft.csv"))
using (var csv = new CsvReader(reader, System.Globalization.CultureInfo.InvariantCulture))
{
csv.Context.RegisterClassMap<FantasyDraftPickMap>();
var fantasyDraftPickRecords = csv.GetRecords<FantasyDraftPick>();
fantasyDraftPicks = fantasyDraftPickRecords.ToList();
}
bool prospectsExist = File.Exists($"actual-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Prospects.json");
string jsonProspects = "";
//dynamic stuff = JsonConvert.DeserializeObject(jsonDraft);
JObject Jprospects = null;
if(prospectsExist)
{
AnsiConsole.MarkupLine(":abacus: We have a prospect list! Checking for updates...... :abacus:");
//stuff = JsonConvert.DeserializeObject(File.ReadAllText($"actual-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Draft.json"));
jsonProspects = File.ReadAllText($"actual-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Prospects.json");
}
else
{
AnsiConsole.MarkupLine(":abacus: We don't have a prospect list. Performing first time load...... :abacus:");
}
if (!prospectsExist || updateProspects)
{
//Load the prospects
using(var client = new HttpClient())
{
//Send HTTP request from here.
client.DefaultRequestHeaders.Accept.Clear();
var prospectsStringTask = client.GetStringAsync($"https://api.sportradar.us/draft/nfl/trial/v1/en/{draftYear}/prospects.json?api_key=" + apikey);
jsonProspects = await prospectsStringTask;
string fileName = $"actual-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Prospects.json";
File.WriteAllText(fileName, jsonProspects);
}
AnsiConsole.MarkupLine(":abacus: Prospect list updated. Waiting before making next API call. :abacus:");
// If updating prospects, wait 1.5 seconds before making the next API call. API limit is one call per second.
Thread.Sleep(1500);
AnsiConsole.MarkupLine(":abacus: OK, let's do this! :abacus:");
}
Jprospects = JObject.Parse(jsonProspects);
JArray prospects = (JArray)Jprospects["prospects"];
List<Prospect> prospectList = new List<Prospect>();
foreach (var prospect in prospects)
{
var newProspect = new Prospect();
newProspect.PlayerId = (Guid)prospect["id"];
newProspect.PlayerName = (string)prospect["name"];
newProspect.School = (string)prospect["team"]?["market"] ?? "";
newProspect.Position = (string)prospect["position"];
newProspect.Conference = (string)prospect["conference"]?["name"] ?? (string)prospect["team_name"];
newProspect.Experience = (string)prospect["experience"];
prospectList.Add(newProspect);
}
// Create list of prospects from JArray
bool draftExists = File.Exists($"actual-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Draft.json");
// Read in player and school data from CSV file.
string jsonDraft = "";
//dynamic stuff = JsonConvert.DeserializeObject(jsonDraft);
JObject draft = null;
if(draftExists && draftComplete)
{
AnsiConsole.MarkupLine(":abacus: The draft is complete and we have the draft JSON! No need to load :abacus:");
//stuff = JsonConvert.DeserializeObject(File.ReadAllText($"actual-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Draft.json"));
jsonDraft = File.ReadAllText($"actual-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Draft.json");
}
else
{
//Load the draft
using(var client = new HttpClient())
{
//Send HTTP request from here.
client.DefaultRequestHeaders.Accept.Clear();
var draftStringTask = await client.GetStringAsync($"https://api.sportradar.us/draft/nfl/trial/v1/en/{draftYear}/draft.json?api_key=" + apikey);
jsonDraft = draftStringTask;
string fileName = $"actual-draft{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Draft.json";
//var Draft = JsonConvert.DeserializeObject<JToken>(jsonDraft);
File.WriteAllText(fileName, jsonDraft);
}
}
draft = JObject.Parse(jsonDraft);
//var picks = stuff.rounds.picks;
string startDate = draft["draft"]["end_date"].ToString();
List<JArray> draftRounds = new List<JArray>();
JArray Round1Picks = (JArray)draft["rounds"][0]["picks"];
JArray Round2Picks = (JArray)draft["rounds"][1]["picks"];
JArray Round3Picks = (JArray)draft["rounds"][2]["picks"];
JArray Round4Picks = (JArray)draft["rounds"][3]["picks"];
JArray Round5Picks = (JArray)draft["rounds"][4]["picks"];
JArray Round6Picks = (JArray)draft["rounds"][5]["picks"];
JArray Round7Picks = (JArray)draft["rounds"][6]["picks"];
draftRounds.Add(Round1Picks);
draftRounds.Add(Round2Picks);
draftRounds.Add(Round3Picks);
draftRounds.Add(Round4Picks);
draftRounds.Add(Round5Picks);
draftRounds.Add(Round6Picks);
draftRounds.Add(Round7Picks);
// Now that we have the draft picks, we can make them into ActualDraftPick objects.
//Get picks from from Round1Picks and get values needed to create ActualDraftPick objects
List<ActualDraftPick> actualDraftPicks = new List<ActualDraftPick>();
for (int i = 1; i <= 7; i++)
{
var picksTest =
from p in draftRounds[i - 1]
where p["prospect"] != null
select new {
Pick = (int?)p["overall"],
PickInRound = (int)p["number"],
Round = i,
PlayerName = (string?)p["prospect"]["name"],
School = (string?)p["prospect"]["team_name"],
Traded = (bool?)p["traded"],
PlayerId = (Guid?)Guid.Parse(p["prospect"]["id"].ToString()),
};
foreach (var pick in picksTest)
{
(string State, string Conference) stateAndConference = GetStateAndConference(pick.School);
actualDraftPicks.Add(new ActualDraftPick()
{
Pick = pick.Pick,
Round = pick.Round,
Player = pick.PlayerName,
School = pick.School,
Traded = pick.Traded ?? false,
LeagifyPoints = GetLeagifyPoints(pick.Round, pick.PickInRound, pick.Traded ?? false),
State = stateAndConference.State,
Conference = stateAndConference.Conference,
PlayerId = pick.PlayerId
});
}
}
var actualDraftPicksVerified = from adp in actualDraftPicks
join p in prospectList on adp.PlayerId equals p.PlayerId
select new ActualDraftPick{
Pick = adp.Pick,
Round =adp.Round,
Player = adp.Player,
School = p.School,
Traded = adp.Traded,
LeagifyPoints = adp.LeagifyPoints,
State = adp.State,
Conference = adp.Conference,
Position = p.Position,
Experience = p.Experience,
PlayerId = p.PlayerId
};
//Go through the picks again and make sure if the school was updated, we get an updated State.
foreach (var pick in actualDraftPicksVerified)
{
(string State, string Conference) stateAndConference = GetStateAndConference(pick.School);
pick.State = stateAndConference.State;
pick.Conference = stateAndConference.Conference;
}
// sort actualDraftPicksVerified by LeagifyPoints, grouped by School.
var draftPicksBySchool = from adp in actualDraftPicksVerified
orderby adp.LeagifyPoints descending
group adp by adp.School into adpGroup
select new {
School = adpGroup.Key,
LeagifyPoints = adpGroup.Sum(x => x.LeagifyPoints),
Picks = adpGroup.ToList()
};
// Join draftPicksBySschool with fantasyDraftPicks by School. Ordered by LeafifyPoints.
var draftPicksBySchoolAndOwner = from dpbs in draftPicksBySchool
join fdp in fantasyDraftPicks on dpbs.School equals fdp.Player
select new {
School = dpbs.School,
LeagifyPoints = dpbs.LeagifyPoints,
Picks = dpbs.Picks,
Bid = fdp.Bid,
ProjectedPoints = fdp.ProjectedPoints,
Difference = dpbs.LeagifyPoints - fdp.ProjectedPoints,
Owner = fdp.Owner,
};
// sort draftPicksBySchoolAndOwner by LeagifyPoints
var draftPicksBySchoolAndOwnerSortedByLeagifyPoints = draftPicksBySchoolAndOwner.OrderByDescending(o => o.LeagifyPoints).ToList();
// Create Bar Chart of draft picks by School and Owner
var schoolChart = new BarChart();
schoolChart.Label = "[red bold underline]Draft Points By School[/]";
foreach (var school in draftPicksBySchoolAndOwnerSortedByLeagifyPoints)
{
string schoolLabel = $"{school.School} - {school.Owner}";
schoolChart.AddItem(schoolLabel, school.LeagifyPoints, Color.Red);
}
if (draftPicksBySchoolAndOwnerSortedByLeagifyPoints.Count > 0)
{
AnsiConsole.Write(schoolChart);
}
else
{
AnsiConsole.Write("No school results yet. Has the draft begun?");
}
// Write results to CSV
string schoolResultsFileName = $"leagify-result-stats{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}DraftPointsBySchool.csv";
using (var stream = new StreamWriter(schoolResultsFileName))
using (var csv = new CsvWriter(stream, CultureInfo.InvariantCulture))
{
csv.WriteRecords(draftPicksBySchoolAndOwnerSortedByLeagifyPoints);
}
AnsiConsole.WriteLine();
// Find results for any player in fantasyDraftPicks that is not in draftPicksBySchoolAndOwner.
var flops = from fdp in fantasyDraftPicks
join dpbs in draftPicksBySchoolAndOwner on fdp.Player equals dpbs.School into dpbsGroup
from dpbs in dpbsGroup.DefaultIfEmpty()
where dpbs == null
select new {
Player = fdp.Player,
Bid = fdp.Bid,
ProjectedPoints = fdp.ProjectedPoints,
Difference = fdp.ProjectedPoints - 0,
Owner = fdp.Owner,
};
if (flops.Count() > 0)
{
var flopSchools = new BarChart();
flopSchools.Label = "[aqua bold underline]Drafted Schools with NO POINTS[/]";
foreach (var school in flops)
{
string flopLabel = $"{school.Player} - {school.Owner}";
flopSchools.AddItem(flopLabel, school.ProjectedPoints, Color.Aqua);
}
// Write results to CSV
string flopsFileName = $"leagify-result-stats{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}Flops.csv";
using (var stream = new StreamWriter(flopsFileName))
using (var csv = new CsvWriter(stream, CultureInfo.InvariantCulture))
{
csv.WriteRecords(flops);
}
AnsiConsole.Write(flopSchools);
}
else
{
AnsiConsole.Write(new Markup("[green]No flop schools! Every school we drafted had players drafted![/]\n"));
}
AnsiConsole.WriteLine();
var draftPicksBySchoolAndOwnerSortedByDifference = draftPicksBySchoolAndOwner.OrderByDescending(o => o.Difference).ToList();
var differenceTable = new Spectre.Console.Table();
differenceTable.Border(TableBorder.Double).BorderColor(ConsoleColor.DarkMagenta);
differenceTable.AddColumn("School");
differenceTable.AddColumn("Owner");
differenceTable.AddColumn("Bid");
differenceTable.AddColumn("Projected");
differenceTable.AddColumn("Actual");
differenceTable.AddColumn("Difference");
differenceTable.AddColumn("Performance Ratio");
differenceTable.AddColumn("Points per Dollar");
var schoolStatsList = new List<SchoolStats>();
foreach (var school in draftPicksBySchoolAndOwnerSortedByDifference)
{
string[] ownerResult = {
school.School,
school.Owner,
school.Bid.ToString(),
school.ProjectedPoints.ToString(),
school.LeagifyPoints.ToString(),
school.Difference.ToString(),
((float)school.LeagifyPoints / school.ProjectedPoints).ToString(),
((float)school.LeagifyPoints / school.Bid).ToString(),
};
//Write these results to a class so that they can be output to CSV.
SchoolStats schoolStat = new SchoolStats{
// public string School { get; set; }
// public string Owner { get; set; }
// public int Bid { get; set; }
// public int Projected { get; set; }
// public int Actual { get; set; }
// public int Difference { get; set; }
// public float PerformanceRatio { get; set; }
// public float PointsPerDollar { get; set; }
School = school.School,
Owner = school.Owner,
Bid = school.Bid,
Projected = school.ProjectedPoints,
Actual = school.LeagifyPoints,
Difference = school.Difference,
PerformanceRatio = (float)school.LeagifyPoints / school.ProjectedPoints,
PointsPerDollar = (float)school.LeagifyPoints / school.Bid
};
schoolStatsList.Add(schoolStat);
differenceTable.AddRow(ownerResult);
}
AnsiConsole.Write(differenceTable);
// Write results to CSV
string differenceTableFileName = $"leagify-result-stats{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}LeagifySchoolStats.csv";
using (var stream = new StreamWriter(differenceTableFileName))
using (var csv = new CsvWriter(stream, CultureInfo.InvariantCulture))
{
csv.WriteRecords(schoolStatsList);
}
AnsiConsole.WriteLine();
// join actualDraftPicks to fantasyDraftPicks and sum up points for each owner.
var ownerPicks = from d in actualDraftPicksVerified
join f in fantasyDraftPicks on d.School equals f.Player
select new {
d.Pick,
d.Round,
d.Player,
d.School,
d.Traded,
d.LeagifyPoints,
d.State,
d.Conference,
f.Owner
};
// Show players not matching an owner by seeing which of the actualDraftPicksVerified are not in ownerPicks.
var playersNotMatching = from d in actualDraftPicksVerified
where !ownerPicks.Any(o => o.School == d.School)
select d;
AnsiConsole.MarkupLine(":abacus: Players not matching up to owners... :abacus:");
// Create list of "Nobody schools" for CSV.
IDictionary<string, int> nobodySchoolDictionary = new Dictionary<string, int>();
foreach (var player in playersNotMatching)
{
AnsiConsole.Write(new Markup($"Pick [bold yellow]{player.Pick}[/]: :american_football:[red]{player.Player}[/]:american_football: from [bold yellow]{player.School}[/] gives [lime]{player.LeagifyPoints}[/] points to :thumbs_down:[fuchsia]No One[/]:thumbs_down:\n"));
//update dictionary of nobody schools
if(!nobodySchoolDictionary.ContainsKey(player.School))
{
nobodySchoolDictionary[player.School] = player.LeagifyPoints;
}
else
{
nobodySchoolDictionary[player.School] += player.LeagifyPoints;
}
}
AnsiConsole.WriteLine();
var nobodySchoolsList = new List<NobodySchools>();
foreach (var nbs in nobodySchoolDictionary)
{
NobodySchools school = new NobodySchools {School = nbs.Key, Points = nbs.Value};
nobodySchoolsList.Add(school);
}
if (nobodySchoolsList.Count > 0)
{
// Sort values by points
List<NobodySchools> SortedListOfNobodySchools = nobodySchoolsList.OrderByDescending(s=>s.Points).ToList();
// Write results to CSV
string schoolsNotMatchingFileName = $"leagify-result-stats{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}NobodySchools.csv";
using (var stream = new StreamWriter(schoolsNotMatchingFileName))
using (var csv = new CsvWriter(stream, CultureInfo.InvariantCulture))
{
csv.WriteRecords(SortedListOfNobodySchools);
}
}
AnsiConsole.MarkupLine(":abacus: Scoring the draft... :abacus:");
AnsiConsole.WriteLine();
foreach (var pick in ownerPicks)
{
bool traded = pick.Traded.HasValue ? pick.Traded.Value : false;
if (traded)
AnsiConsole.Write(new Markup($"Pick [bold yellow]{pick.Pick}[/]: :american_football:[red]{pick.Player}[/]:american_football: from [bold yellow]{pick.School}[/] gives [lime]{pick.LeagifyPoints}[/] points to :backhand_index_pointing_right:[fuchsia]{pick.Owner}[/]:backhand_index_pointing_left: [aqua]via Trade[/]\n"));
else
AnsiConsole.Write(new Markup($"Pick [bold yellow]{pick.Pick}[/]: :american_football:[red]{pick.Player}[/]:american_football: from [bold yellow]{pick.School}[/] gives [lime]{pick.LeagifyPoints}[/] points to :backhand_index_pointing_right:[fuchsia]{pick.Owner}[/]:backhand_index_pointing_left:\n"));
}
// Along with points, get some stats about the draft.
var ownerPoints = ownerPicks.GroupBy(o => o.Owner).Select(o => new {
Owner = o.Key,
Points = o.Sum(p => p.LeagifyPoints)
});
// for ownerPicks, get the owner's name and the number of picks they made in each round
var ownerPicksByRoundAndOwner = ownerPicks.GroupBy(o => new {
o.Round,
o.Owner
}).Select(o => new {
Round = o.Key.Round,
Owner = o.Key.Owner,
NumberOfPicks = o.Count()
});
// change ownerPicksByRoundAndOwner to an arrayList starting with the owner name followed by the number of picks in each round
var ownerPicksByRoundAndOwnerArray = ownerPicksByRoundAndOwner.Select(o => new {
o.Owner,
o.Round,
o.NumberOfPicks
}).ToList();
// create list of owners from ownerPicksByRoundAndOwnerArray
var justTheOwners = ownerPicksByRoundAndOwner.Select(o => new {
o.Owner
}).Distinct().ToList();
// change ownerPicksByRoundAndOwnerArray to an arrayList starting with the owner name followed by the number of picks in each round
// Create string array of length 8
// string[] Ross = new string[8];
// string[] AJ = new string[8];
// string[] Tilo = new string[8];
// string[] Jared = new string[8];
// string[] Jawad = new string[8];
Dictionary<string, int[]> picksForTable = new Dictionary<string, int[]>();
foreach (var owner in justTheOwners)
{
picksForTable.Add(owner.Owner, new int[7]);
}
foreach (var pickResult in ownerPicksByRoundAndOwnerArray)
{
picksForTable[pickResult.Owner][(int)pickResult.Round - 1] = pickResult.NumberOfPicks;
AnsiConsole.Write(new Markup ($"[fuchsia]{pickResult.Owner}[/] has [fuchsia]{pickResult.NumberOfPicks}[/] picks in round [fuchsia]{pickResult.Round}[/]\n"));
}
// Output results of ownerPicksByRoundAndOwner to a Spectre Console table
AnsiConsole.MarkupLine(":abacus: Outputting round results to a table... :abacus:");
// Create a Spectre Console table with fully qualified class
AnsiConsole.WriteLine();
var roundPicksTable = new Spectre.Console.Table();
roundPicksTable.Border(TableBorder.Double).BorderColor(ConsoleColor.Yellow);
roundPicksTable.AddColumn("Owner");
roundPicksTable.AddColumn("Round 1");
roundPicksTable.AddColumn("Round 2");
roundPicksTable.AddColumn("Round 3");
roundPicksTable.AddColumn("Round 4");
roundPicksTable.AddColumn("Round 5");
roundPicksTable.AddColumn("Round 6");
roundPicksTable.AddColumn("Round 7");
roundPicksTable.AddColumn("Total");
foreach (var owner in picksForTable)
{
string[] ownerResult = {owner.Key,
owner.Value[0].ToString(),
owner.Value[1].ToString(),
owner.Value[2].ToString(),
owner.Value[3].ToString(),
owner.Value[4].ToString(),
owner.Value[5].ToString(),
owner.Value[6].ToString(),
owner.Value.Sum().ToString()};
roundPicksTable.AddRow(ownerResult);
}
AnsiConsole.Write(roundPicksTable);
AnsiConsole.WriteLine();
// Given ActualDraftPick objects, we can score them with a bar chart
var pointChart = new BarChart();
pointChart.Label = "[green bold underline]Draft Points[/]";
var ownerPointsList = ownerPoints.OrderByDescending(o => o.Points).ToList();
foreach (var owner in ownerPointsList)
{
pointChart.AddItem(owner.Owner, owner.Points, Color.Green);
}
if (ownerPointsList.Count > 0)
{
AnsiConsole.Write(pointChart);
// Write results to CSV
string ownerResultsFileName = $"leagify-result-stats{Path.DirectorySeparatorChar}{draftYear}{Path.DirectorySeparatorChar}{draftYear}OwnerResults.csv";
using (var stream = new StreamWriter(ownerResultsFileName))
using (var csv = new CsvWriter(stream, CultureInfo.InvariantCulture))
{
csv.WriteRecords(ownerPointsList);
}
}
else
{
AnsiConsole.Write("No points yet. Either we suck or the draft hasn't started yet.");
}
AnsiConsole.WriteLine();
int GetLeagifyPoints(int round, int pickInRound, bool traded)
{
int score = 0;
score = round switch
{
1 => ((Func<int>)(() => {
score = traded ? 10 : 0;
if (pickInRound == 1)
{
score += 40;
}
else if (pickInRound >= 2 && pickInRound <= 10)
{
score += 35;
}
else if (pickInRound >= 11 && pickInRound <= 20)
{
score += 30;
}
else if (pickInRound >= 21 && pickInRound <= 32)
{
score += 25;
}
return score;
}))(),
2 => ((Func<int>)(() => {
score = traded ? 10 : 0;
if (pickInRound >= 1 && pickInRound <= 16)
{
score += 20;
}
else if (pickInRound >= 17 && pickInRound <= 50)
{
score += 15;
}
return score;
}))(),
3 => score = traded ? 20 : 10,
4 => score = traded ? 18 : 8,
5 => score = traded ? 17 : 7,
6 => score = traded ? 16 : 6,
7 => score = traded ? 15 : 5,
_ => score = 0
};
return score;
}
(string, string) GetStateAndConference(string school)
{
List<SCS> schoolsAndConferences;
using (var reader = new StreamReader($"info{Path.DirectorySeparatorChar}SchoolStatesAndConferences.csv"))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
schoolsAndConferences = csv.GetRecords<SCS>().ToList();
}
var scs = from s in schoolsAndConferences
where s.School == school
select s;
SCS? currentSchoolConferenceState = scs.FirstOrDefault();
// var srfd = stateResult.FirstOrDefault();
// string sr = "";
// if (srfd != null)
// {
// sr = srfd.ToString();
// }
// else
// {
// Console.WriteLine("Error matching school!");
// }
// if(sr.Length > 0)
// {
// return sr;
// }
// else
// {
// return "";
// }
if (currentSchoolConferenceState != null)
{
return (currentSchoolConferenceState.State, currentSchoolConferenceState.Conference);
}
else
{
return ("", "");
}
}
return 0;
public class SCS
{
public string School { get; set; }
public string State { get; set; }
public string Conference { get; set; }
}
public class SchoolStats
{
public string School { get; set; }
public string Owner { get; set; }
public int Bid { get; set; }
public int Projected { get; set; }
public int Actual { get; set; }
public int Difference { get; set; }
public float PerformanceRatio { get; set; }
public float PointsPerDollar { get; set; }
}
public class NobodySchools
{
public string School { get; set; }
//public int Projected { get; set; }
public int Points { get; set; }
}