/// <summary> /// For Players we don't copy PGID, TGID, POID = Player Id, Team Id , Player Original Id /// </summary> /// <param name="continuation"></param> /// <param name="playersSource"></param> /// <param name="depthChartSource"></param> /// <param name="playersDestination"></param> /// <param name="depthChartDestination"></param> static void CopyPlayers(ContinuationData continuation, MaddenTable playersSource, MaddenTable depthChartSource, MaddenTable playersDestination, MaddenTable depthChartDestination) { // first we group by team, so what we have is a Dictionary key'd by team id, and each bucket has a Dictionary keyed by PlayerId var sourceTeams = playersSource.lRecords.GroupBy(mr => mr["TGID"].ToInt32()).ToDictionary(group => group.Key, group => group.ToList().ToDictionary(mr => mr["PGID"].ToInt32())); var sourceDepthChart = depthChartSource.lRecords.GroupBy(mr => mr["TGID"].ToInt32()).ToDictionary(group => group.Key, group => group.ToList().ToDictionary(mr => new DepthChartKey(mr["PPOS"].ToInt32(), mr["ddep"].ToInt32()))); var destTeams = playersDestination.lRecords.GroupBy(mr => mr["TGID"].ToInt32()).ToDictionary(group => group.Key, group => group.ToList().ToDictionary(mr => mr["PGID"].ToInt32())); var destDepthChart = depthChartDestination.lRecords.GroupBy(mr => mr["TGID"].ToInt32()).ToDictionary(group => group.Key, group => group.ToList().ToDictionary(mr => new DepthChartKey(mr["PPOS"].ToInt32(), mr["ddep"].ToInt32()))); foreach (var key in destDepthChart.Keys) { // only copy over for valid teams if (key.IsValidTeam() == false) { continue; } // uconn and nmsu are gone! if (key == 61 || key == 100) { continue; } var sourceId = key.SourceKeyFromDesintation(out var value) ? value : key; CopyPlayersForTeam(sourceTeams[sourceId], sourceDepthChart[sourceId], destTeams[key], destDepthChart[key]); } }
static void CopyNCAARecordData(MaddenTable source, MaddenTable destination) { var include = new string[] { "RCDH", "RCDV", "RCDO" }; CopyData( source.CreateDictionary(mr => mr["RCDI"].ToInt32(), mr => { var id = mr["RCDI"].ToInt32(); var allRecordsWithid = source.lRecords.Where(rec => rec["RCDI"].ToInt32() == id).ToArray(); if (allRecordsWithid.Length == 1) { return(true); } var year = mr["RCDY"].ToInt32(); var ordered = allRecordsWithid.OrderByDescending(or => or["RCDY"].ToInt32()).ToArray(); return(ordered[0]["RCDY"].ToInt32() == year); }), destination.CreateDictionary(mr => mr["RCDI"].ToInt32(), null), null, null, key => include.Contains(key), (s, d, k) => k != "RCDY" || d[k].Data.ToInt32() != 63); }
private void cbTable_SelectedIndexChanged(object sender, EventArgs e) { view = View.FindView(lMappedViews, cbTable.SelectedItem.ToString( )); lvFitlers.Items.Clear( ); cbField.Items.Clear( ); if (view.lChildFields.Count > 0) { foreach (Field f in view.lChildFields) { cbField.Items.Add((f.Name != "") ? f.Name : f.Abbreviation); } } else { MaddenTable table = MaddenTable.FindTable(lMappedTables, view.SourceName); if (table == null) { return; } foreach (Field f in table.lFields) { cbField.Items.Add((f.Name != "") ? f.Name : f.Abbreviation); } } }
static void CopyStadiumData(MaddenTable source, MaddenTable destination) { var include = new[] { "SNAM", "SCIT", "STAT", "STNN", "TDNA", "SCAP", "STAA", "FLID", "WCLC", "STOF", "STRY", "STYP" }; var sourceToDestinationMap = new Dictionary <int, int>(); // for a straight map we just copy var ids = new int[] { 242, 258, 261, 262, 263, 264, 265, 266, 267, 163, 259, 268 }; foreach (var id in ids) { sourceToDestinationMap[id] = id; } sourceToDestinationMap[279] = 278; // sourceToDestinationMap[279] = 257; // we need to know what destination to copy to var destinationMap = sourceToDestinationMap.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); destinationMap[257] = 279; var sauce = source.CreateDictionary(mr => mr["SGID"].ToInt32(), mr => sourceToDestinationMap.ContainsKey(mr["SGID"].ToInt32())); var dest = destination.CreateDictionary(mr => mr["SGID"].ToInt32(), mr => destinationMap.ContainsKey(mr["SGID"].ToInt32())); foreach (var key in dest.Keys) { var sourceKey = destinationMap[key]; var sourceRow = sauce[sourceKey]; var destRow = dest[key]; CopyRecordData(sourceRow, destRow, dataKey => include.Contains(dataKey)); switch (key) { case 278: destRow["TDNA"].Data = "Southwest Classic"; break; case 257: destRow["TDNA"].Data = "Battle for the Iron Skillet"; break; case 268: destRow["FLID"].Data = "HSNESM"; break; case 259: case 266: case 265: case 264: destRow["FLID"].Data = "HSNEMD"; break; default: break; } } }
static void CopyHSAARoster(MaddenTable source, MaddenTable destination) { var recruitFields = source.lRecords.First().lEntries.Select(entry => entry.GetFieldName()).ToArray(); var playerFields = destination.lRecords.First().lEntries.Select(entry => entry.GetFieldName()).ToArray(); var intersection = recruitFields.Intersect(playerFields).Where(s => s != "TGID").ToArray(); var list = string.Join(",", intersection); // ARMY GETS EAST CopyHSAARoster(RecruitAllAmericans.EastRoster.Players, destination.lRecords.Where(mr => mr["TGID"].ToInt32() == 8).OrderBy(mr => mr["PPOS"].ToInt32()).ToList(), intersection); // NAVY GETS WEST CopyHSAARoster(RecruitAllAmericans.WestRoster.Players, destination.lRecords.Where(mr => mr["TGID"].ToInt32() == 57).OrderBy(mr => mr["PPOS"].ToInt32()).ToList(), intersection); }
static void CopyBowlData(MaddenTable source, MaddenTable destination) { var include = new[] { "BCI1", "BCR1", "BCI2", "BCR2", "BNME" }; var dest = destination.CreateDictionary(mr => mr["BIDX"].ToInt32(), mr => mr.lEntries[12].Data.ToInt32() > 16); var sauce = source.CreateDictionary(mr => mr["BIDX"].ToInt32(), mr => mr.lEntries[12].Data.ToInt32() > 16); CopyData( sauce, dest, null, null, key => include.Contains(key)); }
static void CopyTeamRecordData(MaddenTable source, MaddenTable destination) { var include = new string[] { "RCDH", "RCDV", "RCDO" }; CopyData( source.CreateDictionary(CreateSchoolRecordKey, mr => mr["RCDY"].ToInt32() != 63), destination.CreateDictionary(CreateSchoolRecordKey, mr => mr["RCDY"].ToInt32() != 63), null, null, key => include.Contains(key), null ); }
static void CopyCoachSkillTable(ContinuationData continuation, MaddenTable source, MaddenTable destination) { var levelsData = File.ReadAllText("levels.txt"); Dictionary <int, int> levelsAndXp = null; using (var stream = new MemoryStream()) { var bytes = Encoding.UTF8.GetBytes(levelsData); stream.Write(bytes, 0, bytes.Length); stream.Position = 0; var ser = new DataContractJsonSerializer(typeof(Dictionary <int, int>)); levelsAndXp = (Dictionary <int, int>)ser.ReadObject(stream); } var exclude = new[] { "CCID", "CFUC", "TOID", "BLCS", "NLVL" }; var coachSkillKeys = File.ReadAllText("coachSkill.txt").Split(',').Where(s => !exclude.Contains(s)).ToArray(); var sourceData = source.CreateDictionary( record => continuation.OldToNewCoachMap[CreateCoachSkillKey(record)], record => continuation.OldToNewCoachMap.ContainsKey(CreateCoachSkillKey(record)), (a, b) => { if (a["CLVL"].Data.ToInt32() > b["CLVL"].Data.ToInt32()) { return(a); } return(b); }); var destinationData = destination.CreateDictionary(CreateCoachSkillKey, null); CopyData( sourceData, destinationData, null, /* (a,b,s,d)=> * { * var key = s["CLVL"].Data.ToInt32(); * if (levelsAndXp.ContainsKey(key) == false) * { * key++; * } * s["CEXP"].Data = levelsAndXp[key].ToString(); * },*/ null, key => coachSkillKeys.Contains(key) ); }
static void CopyTeamData(ContinuationData continuation, MaddenTable teamSource, MaddenTable teamDestination) { Action <int, int, Dictionary <string, DBData>, Dictionary <string, DBData> > action = null; if (MessageBox.Show("W-L records and Championships will be set to 0", "Do you want to change Team W-L", MessageBoxButtons.YesNo) == DialogResult.Yes) { action = SetTeamStatsToZero; } var columnsToCopy = new[] { "PCHV", "PPFV", "PAFV", "PTDV", "TMAR", "TDPB", "TOPB", "PCLV", "PAPV", "PCPV", "PPSV", "PTVV", "TPRX", "TPST", "TPSL", "TPSW", "TCRK", "TMRK", "TCHS" }; CopyTeamData( teamSource.CreateDictionary(mr => mr["TGID"].ToInt32(), mr => mr.IsValidTeam()), teamDestination.CreateDictionary(mr => mr["TGID"].ToInt32(), mr => mr.IsValidTeam()), action, new string[0], ck => columnsToCopy.Contains(ck)); }
public static void GetRecruits(MaddenTable recruitStatTable, MaddenTable recruitPitchTable) { RecruitPlayer.PitchTable = recruitPitchTable; // order recruits by rank foreach (var recruit in recruitStatTable.lRecords.OrderBy(mr => mr.lEntries[62].Data.ToInt32())) { var recruitState = recruit["STAT"].ToInt32(); HSAARoster teamTryingOutFor = EastStates.Contains(recruitState) ? EastRoster : WestRoster; teamTryingOutFor.TryOut(recruit); // stop iterating once we filled our rosters if (EastRoster.RosterFilled && WestRoster.RosterFilled) { EastRoster.SortPlayers(); WestRoster.SortPlayers(); break; } } }
static void CopyCoachTable(ContinuationData continuationData, MaddenTable source, MaddenTable destination) { var exclude = new[] { "CCID", "CLPS", "CFUC", "CSXP", "PTID", "TOID", "CLPS", "TGID" }; var coachSkillKeys = File.ReadAllText("coachColumns.txt").Split(',').Where(s => !exclude.Contains(s)).ToArray(); //CCID is coach ID //TGID is team id //COPS is position var destinationTable = destination.CreateDictionary(CreateCoachKey, mr => mr.IsValidTeam()); var sourceTable = source.CreateDictionary(CreateCoachKey, mr => mr.IsValidTeam()); foreach (var key in destinationTable.Keys) { // dont modify uncc/ccu, you dont have to do this for the next continuation if (key.Team == 61 || key.Team == 100) { continue; } // source key for gaso/appst are different var sourceKey = key.Team.SourceKeyFromDesintation(out var value) ? new CoachKey { Team = value, Position = key.Position } : key; if (sourceTable.TryGetValue(sourceKey, out var sourceRow)) { var rowKey = sourceTable.Keys.First(myKey => myKey.Equals(sourceKey)); continuationData.CoachMapping.Add( new CoachMapping { OldCoachId = rowKey.CoachId, NewCoachId = key.CoachId, }); CopyRecordData(sourceRow, destinationTable[key], fieldKey => coachSkillKeys.Contains(fieldKey)); } } }
public static void Report(MaddenTable table) { var firstNames = table.lRecords.Select(mr => mr["PFNA"]).GroupBy(n => n).ToDictionary(g => g.Key, g => g.Count()); var lastNames = table.lRecords.Select(mr => mr["PLNA"]).GroupBy(n => n).ToDictionary(g => g.Key, g => g.Count()); var groups = table.lRecords.Where(mr => PositionGroups.ContainsKey(mr["RPGP"].ToInt32())).GroupBy(mr => PositionGroups[mr["RPGP"].ToInt32()]); var keys = Player.RatingMap.Keys.ToArray(); List <PositionGroup> sizes = new List <PositionGroup>(); foreach (var group in groups) { sizes.Add(new PositionGroup { Position = group.Key, Height = group.Average(mr => mr["PHGT"].ToInt32()), Weight = group.Average(mr => mr["PWGT"].ToInt32() + 160), Ratings = keys.Select(key => new Rating(key, group.Average(mr => mr[key].ToInt32()))).ToArray(), TopRatings = keys.Select(key => new Rating(key, group.Where(mr => mr["RCRK"].ToInt32() <= 250).Average(mr => mr[key].ToInt32()))).ToArray() }); } PositionSizes = sizes; sizes.ToJsonFile("ratings.json"); }
public SaveFilterForm(List <FieldFilter> lsF, List <FieldFilter> adF, MaddenTable mt, SaveAction action, string title) { InitializeComponent(); listFilters = lsF; adjustFilters = adF; table = mt; text = title; fmAction = action; try { lSavedCriteria = XmlSerialization.ReadFromXmlFile <List <SavedCriteria> >("SavedFilter.txt"); foreach (SavedCriteria sc in lSavedCriteria) { cboSavedName.Items.Add(sc.Name); } cboSavedName.SelectedIndex = 0; } catch { MessageBox.Show("Could not read SavedFilter.txt"); } }
public FilterAdjustForm(List <Field> lMF, List <MaddenTable> lMT, List <View> lMV, string title, string MTabbr, List <FieldFilter> lFltr, List <FieldFilter> aFltr) { InitializeComponent(); lMappedFields = lMF; lMappedTables = lMT; lMappedViews = lMV; text = title; // TODO: add try..catch table = MaddenTable.GetTableByAbbreviation(lMappedTables, MTabbr); string tName = table.Name == "" ? table.Abbreviation : table.Name; foreach (View v in lMappedViews) { if (v.Type == "Grid") { cbTable.Items.Add(v.Name); } } Console.Write(FindViewbyFieldFilter(aFltr, tName)); if (cbTable.Items.Contains(tName)) { cbTable.SelectedIndex = cbTable.Items.IndexOf(tName); } else if (lFltr.Count == 0) { cbTable.SelectedIndex = cbTable.Items.IndexOf(FindViewbyFieldFilter(aFltr, tName)); } else if (aFltr.Count == 0 || isFieldFilterinView(aFltr, FindViewbyFieldFilter(lFltr, tName))) { cbTable.SelectedIndex = cbTable.Items.IndexOf(FindViewbyFieldFilter(lFltr, tName)); } else { //if (table.Name == table.Abbreviation) //{ //TODO: Create new view isViewInConfig = false; View tbview = new View(); tbview.Name = table.Abbreviation; tbview.Type = "Grid"; tbview.SourceName = table.Abbreviation; tbview.SourceType = "Table"; List <string> cf = new List <string>(); foreach (Field f in table.lFields) { cf.Add(f.name); } tbview.ChildFields = cf; lMappedViews.Insert(0, tbview); cbTable.Items.Add(tbview.Name); cbTable.SelectedIndex = cbTable.Items.IndexOf(tbview.Name); //} MessageBox.Show("The Table for this filter is not mapped in this config. You will not be able to view the changes."); } foreach (FieldFilter ff in lFltr) { Field mf = Field.GetFieldByAbbreviation(lMappedFields, ff.field); string fName = mf.Name == "" ? mf.Abbreviation : mf.Name; BetterListViewNS.BetterListView.AddToListView(lvFilters, null, lvFilters.Items.Count, fName, ff.OperationToText(), ff.value.ToString()); } foreach (FieldFilter ff in aFltr) { Field mf = Field.GetFieldByAbbreviation(lMappedFields, ff.field); string fName = mf.Name == "" ? mf.Abbreviation : mf.Name; BetterListViewNS.BetterListView.AddToListView(lvAdjust, null, lvAdjust.Items.Count, fName, ff.OperationToText(), ff.value.ToString(), ff.min.ToString(), ff.max.ToString()); } }
static Dictionary <TableKey, Dictionary <string, DBData> > CreateDictionary <TableKey>(this MaddenTable table, Func <MaddenRecord, TableKey> keyCreator, Func <MaddenRecord, bool> recordFilter, Func <Dictionary <string, DBData>, Dictionary <string, DBData>, Dictionary <string, DBData> > resolver = null) { if (recordFilter == null) { recordFilter = record => true; } var tbl = new Dictionary <TableKey, Dictionary <string, DBData> >(); foreach (var record in table.lRecords.Where(mr => recordFilter(mr))) { var newKey = keyCreator(record); var data = record.lEntries.ToDictionary(dbd => dbd.GetFieldName()); if (tbl.ContainsKey(newKey) && resolver != null) { tbl[newKey] = resolver(tbl[newKey], data); } else { tbl.Add(newKey, data); } } /* return table.lRecords.Where(mr => recordFilter(mr)).ToDictionary( * record => keyCreator(record), * mr => mr.lEntries.ToDictionary(dbd => dbd.GetFieldName()) * ); */ return(tbl); }
public static void Run(Form1 form) { Init(); var playerTable = MaddenTable.FindTable(form.maddenDB.lTables, "PLAY"); Dictionary <int, TeamNumbers> dict = new Dictionary <int, TeamNumbers>(); foreach (var row in playerTable.lRecords) { row.FixPlayerSleeve(); var team = row.TeamId(); if (team == 1023) { continue; } TeamNumbers numbers = null; if (!dict.TryGetValue(team, out numbers)) { numbers = new TeamNumbers(team); dict.Add(team, numbers); } // don't add new frosh numbers to the mix just yet if (IsNewFrosh(row)) { continue; } if (!numbers.NumbersUsed.Add(row.JerseyNumber())) { var position = row.Position(); var positionNums = NumberLookup[position]; // transfer might have dupe number, fix that while (true) { var num = positionNums.Next(); if (numbers.NumbersUsed.Add(num)) { row.AssignJerseuNumber(num); break; } } } } // now we know all the numbers of all the players on all teams var incomingFrosh = playerTable.lRecords.Where(r => IsNewFrosh(r)).ToArray(); incomingFrosh = incomingFrosh.Where(r => r.Position() == 0).OrderByDescending(r => r.Overall()).Concat(incomingFrosh.Where(r => r.Position() != 0 && r.Position() < 19).OrderByDescending(r => r.Overall())).Concat(incomingFrosh.Where(r => r.Position() >= 19)).ToArray(); foreach (var row in incomingFrosh) { var team = row.TeamId(); if (team == 1023) { continue; } TeamNumbers numbers = null; if (!dict.TryGetValue(team, out numbers)) { continue; } var position = row.Position(); var positionNums = NumberLookup[position]; if (positionNums.ReplaceOnlyIfDuplicate && numbers.NumbersUsed.Add(row.JerseyNumber())) { continue; } while (true) { var num = positionNums.Next(); if (numbers.NumbersUsed.Add(num)) { row.AssignJerseuNumber(num); break; } } } }
public static void LoadSource(Form1 form, MaddenDatabase destination, CopyAction copyAction) { ContinuationData continuation = new ContinuationData(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = @"D:\OneDrive\ncaa"; openFileDialog.AddExtension = true; openFileDialog.DefaultExt = ".*"; openFileDialog.Filter = "(*.*)|*.*"; openFileDialog.Multiselect = false; openFileDialog.Title = "Select MC02 file to open..."; if (System.Windows.Forms.DialogResult.OK == openFileDialog.ShowDialog()) { var maddenDB = new MaddenDatabase(openFileDialog.FileName); var tables = new List <string>(new[] { "CSKL", "COCH", "DCHT", "PLAY", "TEAM", "RCPT", "RCPR" }); var sourceTablesForRoster = maddenDB.lTables.Where(t => tables.Contains(t.Table.TableName)).ToList(); continuation.Teams = MaddenTable.FindMaddenTable(maddenDB.lTables, "TEAM").lRecords.Where(mr => mr["TGID"].ToInt32().IsValidTeam()).Select(mr => new TeamData(mr)).ToList(); // walked each table and field and add in the mapped elements foreach (MaddenTable mt in sourceTablesForRoster) { MaddenTable mtmapped = MaddenTable.FindTable(lMappedTables, mt.Table.TableName); mt.Abbreviation = mt.Table.TableName; if (mtmapped != null) { mt.Name = mtmapped.Name; } foreach (Field f in mt.lFields) { Field fmapped = lMappedFields.FindField(f.name); f.Abbreviation = f.name; if (fmapped != null) { f.Name = fmapped.Name; } } } if (copyAction == CopyAction.Coach) { CopyCoachTable(continuation, FindTable(sourceTablesForRoster, "COCH"), FindTable(destination.lTables, "COCH")); CopyCoachSkillTable(continuation, FindTable(sourceTablesForRoster, "CSKL"), FindTable(destination.lTables, "CSKL")); if (MessageBox.Show("Do you want to copy over Bowl Tie-ins, NCAA Records and School Records?", "Copy", MessageBoxButtons.YesNo) == DialogResult.Yes) { CopyTeamRecordData(maddenDB.lTables[159], destination.lTables[159]); //CopyNCAARecordData(maddenDB.lTables[91], destination.lTables[91]); CopyBowlData(maddenDB.lTables[129], destination.lTables[129]); CopyStadiumData(MaddenTable.FindTable(maddenDB.lTables, "STAD"), MaddenTable.FindTable(destination.lTables, "STAD")); } } else if (copyAction == CopyAction.Roster) { CopyPlayers(continuation, FindTable(sourceTablesForRoster, "PLAY"), FindTable(sourceTablesForRoster, "DCHT"), FindTable(destination.lTables, "PLAY"), FindTable(destination.lTables, "DCHT")); if (MessageBox.Show("Recruit ratings and playbook, etc", "Do you want to copy over team data?", MessageBoxButtons.YesNo) == DialogResult.Yes) { CopyTeamData(continuation, FindTable(sourceTablesForRoster, "TEAM"), FindTable(destination.lTables, "TEAM")); } } else if (copyAction == CopyAction.HSAA) { var source = FindTable(sourceTablesForRoster, "RCPT"); RecruitAllAmericans.GetRecruits(source, FindTable(sourceTablesForRoster, "RCPR")); var dest = FindTable(destination.lTables, "PLAY"); CopyHSAARoster(source, dest); } form.PostProcessMaps(); form.UpdateTableBoundViews(); } SerializeToFile(continuation, "continuationfile.txt"); }