private eventOverallValues sessionSummary(List<uniqueEventValues> sessionList) { eventOverallValues sessionValues = new eventOverallValues(); bool firstEntry = true; double[] oldPosition = new double[3]; List<int> uniqueBiomeValues = new List<int>(); //parse data for each entry foreach (var value in sessionList) { uniqueEventValues dataPoint = new uniqueEventValues(); dataPoint = value; if (dataPoint.type < 10) { sessionValues.numberEvents++; //generate list of unique biomes if (!uniqueBiomeValues.Contains(dataPoint.biome)) uniqueBiomeValues.Add(dataPoint.biome); //info to calculate total time if(dataPoint.deltaTime > 0) sessionValues.sessionLenght += dataPoint.deltaTime; //events position double[] position = new double[3] { dataPoint.x, dataPoint.y, dataPoint.z }; //calculate distance between positions if (!firstEntry) { sessionValues.traveledDistance += Math.Sqrt((position[0] - oldPosition[0]) * (position[0] - oldPosition[0]) + (position[1] - oldPosition[1]) * (position[1] - oldPosition[1]) + (position[2] - oldPosition[2]) * (position[2] - oldPosition[2])); } else { sessionValues.playerName = dataPoint.name; sessionValues.sessionID = dataPoint.sessionID; firstEntry = false; } oldPosition[0] = position[0]; oldPosition[1] = position[1]; oldPosition[2] = position[2]; //Populate all the lists according to actions ID //0 session id, 1 player name, 2 action ID, 3 date, 4 deltaTime, 5 sub action, 6 unique value, 7 biome, 8 x, 9 y, 10 z if (dataPoint.type == 1) { sessionValues.miningEvents++; } if (dataPoint.type == 2) { sessionValues.buildingEvents++; } if (dataPoint.type == 3) { sessionValues.harvestingEvents++; } if (dataPoint.type == 4) { sessionValues.craftingEvents++; } if (dataPoint.type == 5) { sessionValues.farmingEvents++; } if (dataPoint.type == 6) { sessionValues.exploringEvents++; } if (dataPoint.type == 7) { sessionValues.deathsEvents++; } if (dataPoint.type == 8) { if (dataPoint.subAction == "Fight") { sessionValues.fightEvents++; } else { sessionValues.huntEvents++; } } if (dataPoint.type == 9) { sessionValues.consumableEvents++; } } } sessionValues.uniqueBiomes = uniqueBiomeValues.Count(); sessionValues.sessionLenght /= 10000; sessionValues.traveledDistance /= 10; return sessionValues; }
//export all sessions statistcs to output file. Session analyzes is made by function sessionParser() private void outputSessionToTextFile() { //time to analyze all sessions and do the calculations for all of them foreach (var subList in allEventsBySessions) { eventOverallValues sessionValues = new eventOverallValues(); sessionValues = sessionSummary(subList); if (sessionValues.numberEvents > 0) { string sessionInfo = sessionValues.sessionID + "," + sessionValues.playerName + "," + sessionValues.sessionLenght + "," + sessionValues.numberEvents + "," + sessionValues.uniqueBiomes + "," + sessionValues.traveledDistance + "," + sessionValues.miningEvents + "," + sessionValues.buildingEvents + "," + sessionValues.harvestingEvents + "," + sessionValues.craftingEvents + "," + sessionValues.farmingEvents + "," + sessionValues.exploringEvents + "," + sessionValues.deathsEvents + "," + sessionValues.huntEvents + "," + sessionValues.fightEvents + "," + sessionValues.consumableEvents; File.AppendAllText(fileOutputPath.Text, sessionInfo + Environment.NewLine); } } var count = File.ReadLines(fileOutputPath.Text).Count(); outputMessageToUser("Outputed successfully. Added " + allEventsBySessions.Count() + " sessions. File has now " + count + " sessions."); }