public string convertToFinalStruct(Dictionary <List <int>, List <int> > tuple, List <string> playerStat, int genFolderCount, int iterable) { Console.WriteLine("*************** Combine the friend deck with their respective enemy deck and win and Lose stat ******************\n\n"); string jsonStruct = ""; List <csvStructure> cStruct = new List <csvStructure>(); string[] pStat = playerStat.ToArray(); int count = 0; foreach (var tunpleKey in tuple.Keys) { csvStructure cStructTemp = new csvStructure(); if (count < (genFolderCount * iterable)) { cStructTemp.FriendDeck = tunpleKey; cStructTemp.EnemyDeck = tuple.GetValueOrDefault(tunpleKey); cStructTemp.WinnerDeck = pStat[count]; } cStruct.Add(cStructTemp); count++; } jsonStruct = JsonConvert.SerializeObject(cStruct); /* Save the JSON string in a FinalDataJSON.json */ string fileName = "C:/Development/HeartstoneDataCapture/HeartstoneDataCapture/Data/FinalData/FinalDataJSON.json"; System.IO.File.WriteAllText(fileName, jsonStruct); return(jsonStruct); }
/// <summary> /// This method will conver the JSON data to one hot representation /// </summary> /// <param name="json"></param> /// <returns></returns> public string convertJSONToOneHot1(String json, Dictionary <string, string> CardPool) { Dictionary <int, cardDefs> cardsInfo = cPro.getAllCardsWithId(); Dictionary <string, cardDefs> cardsInfoStr = cPro.getAllCards(); List <csvStructure> data = JsonConvert.DeserializeObject <List <csvStructure> >(json); /***/ List <int> CardPoolIdMain = new List <int>(); foreach (string keys in CardPool.Keys) { CardPoolIdMain.Add(cardsInfoStr.GetValueOrDefault(keys.Split('\r')[0]).dbfId); } /***/ List <csvStructure> finalOneHotStr = new List <csvStructure>(); foreach (csvStructure struc in data) { List <int> FriendDeck = new List <int>(); List <int> EnemyDeck = new List <int>(); Dictionary <int, int> cardCountFriend = new Dictionary <int, int>(); Dictionary <int, int> cardCountEnemy = new Dictionary <int, int>(); List <int> CardPoolId = new List <int>(); csvStructure cStructTemp = new csvStructure(); foreach (string keys in CardPool.Keys) { CardPoolId.Add(cardsInfoStr.GetValueOrDefault(keys.Split('\r')[0]).dbfId); } foreach (int id in struc.FriendDeck) { string cardName = cardsInfo.GetValueOrDefault(id).name; if (CardPool.ContainsKey(cardName)) { if (cardCountFriend.ContainsKey(id)) { cardCountFriend[id] = cardCountFriend[id] + 1; } else { cardCountFriend.Add(id, 1); } } } foreach (int id in struc.EnemyDeck) { string cardName = cardsInfo.GetValueOrDefault(id).name; if (CardPool.ContainsKey(cardName)) { if (cardCountEnemy.ContainsKey(id)) { cardCountEnemy[id] = cardCountEnemy[id] + 1; } else { cardCountEnemy.Add(id, 1); } } } foreach (int id in CardPoolId) { if (cardCountFriend.ContainsKey(id)) { FriendDeck.Add(cardCountFriend[id]); } else { FriendDeck.Add(0); } if (cardCountEnemy.ContainsKey(id)) { EnemyDeck.Add(cardCountEnemy[id]); } else { EnemyDeck.Add(0); } } cStructTemp.FriendDeck = FriendDeck; cStructTemp.EnemyDeck = EnemyDeck; cStructTemp.WinnerDeck = struc.WinnerDeck; finalOneHotStr.Add(cStructTemp); } string result = JsonConvert.SerializeObject(finalOneHotStr); return(result); }