@@ -803,17 +803,19 @@ public static MatchData FromDemoFile(string file, bool parseChickens, bool parse
803803 return md ;
804804 }
805805
806- public AllStats CreateFiles ( ProcessedData processedData , bool createJsonFile = true )
806+ public AllOutputData CreateFiles ( ProcessedData processedData , bool createJsonFile = true )
807807 {
808808 var mapDateSplit = ( ! string . IsNullOrWhiteSpace ( processedData . DemoInformation . TestDate ) && processedData . DemoInformation . TestDate != "unknown" ) ? processedData . DemoInformation . TestDate . Split ( '/' ) : null ;
809809 var mapDateString = ( mapDateSplit != null && mapDateSplit . Count ( ) >= 3 ) ? ( mapDateSplit [ 2 ] + "_" + mapDateSplit [ 0 ] + "_" + mapDateSplit [ 1 ] ) : string . Empty ;
810810
811811 var mapNameSplit = ( processedData . MatchStartValues . Count ( ) > 0 ) ? processedData . MatchStartValues . ElementAt ( 0 ) . Mapname . Split ( '/' ) : new string [ ] { processedData . DemoInformation . MapName } ;
812812 var mapNameString = mapNameSplit . Count ( ) > 2 ? mapNameSplit [ 2 ] : mapNameSplit [ 0 ] ;
813813
814-
815814 var dataAndPlayerNames = GetDataAndPlayerNames ( processedData ) ;
816815
816+
817+ PlayerPositionsStats playerPositionsStats = null ;
818+
817819 AllStats allStats = new AllStats
818820 {
819821 versionNumber = GetVersionNumber ( ) ,
@@ -848,18 +850,24 @@ public AllStats CreateFiles(ProcessedData processedData, bool createJsonFile = t
848850
849851 allStats . firstDamageStats = GetFirstDamageStats ( processedData ) ;
850852
851- if ( processedData . ParsePlayerPositions )
853+ // JSON creation
854+ if ( createJsonFile )
852855 {
853- allStats . playerPositionsStats = GetPlayerPositionsStats ( processedData ) ;
856+ CreateJsonAllStats ( processedData , allStats , mapNameString , mapDateString ) ;
854857 }
855858
856- // JSON creation
857- if ( createJsonFile )
859+ if ( processedData . ParsePlayerPositions )
858860 {
859- CreateJson ( processedData , allStats , mapNameString , mapDateString ) ;
861+ playerPositionsStats = GetPlayerPositionsStats ( processedData , allStats ) ;
862+ CreateJsonPlayerPositionsStats ( processedData , allStats , playerPositionsStats , mapNameString , mapDateString ) ;
860863 }
861864
862- return allStats ;
865+ // return for testing purposes
866+ return new AllOutputData ( )
867+ {
868+ AllStats = allStats ,
869+ PlayerPositionsStats = playerPositionsStats ,
870+ } ;
863871 }
864872
865873 public DataAndPlayerNames GetDataAndPlayerNames ( ProcessedData processedData )
@@ -1922,18 +1930,20 @@ public List<firstDamageStats> GetFirstDamageStats(ProcessedData processedData)
19221930 return firstDamageStats ;
19231931 }
19241932
1925- public List < playerPositionsStats > GetPlayerPositionsStats ( ProcessedData processedData )
1933+ public PlayerPositionsStats GetPlayerPositionsStats ( ProcessedData processedData , AllStats allStats )
19261934 {
1927- List < playerPositionsStats > playerPositionsStats = new List < playerPositionsStats > ( ) ;
1935+ PlayerPositionsStats playerPositionsStats ;
1936+
1937+ List < PlayerPositionByRound > playerPositionByRound = new List < PlayerPositionByRound > ( ) ;
19281938
1929- // create playerPositionsStats with empty PlayerPositionByTimeInRound
1939+ // create playerPositionByRound with empty PlayerPositionByTimeInRound
19301940 foreach ( var roundsGroup in processedData . PlayerPositionsValues . GroupBy ( x => x . Round ) )
19311941 {
19321942 int lastRound = processedData . RoundEndReasonValues . Count ( ) ;
19331943
19341944 foreach ( var round in roundsGroup . Where ( x => x . Round > 0 && x . Round <= lastRound ) . Select ( x => x . Round ) . Distinct ( ) )
19351945 {
1936- playerPositionsStats . Add ( new playerPositionsStats ( )
1946+ playerPositionByRound . Add ( new PlayerPositionByRound ( )
19371947 {
19381948 Round = round ,
19391949 PlayerPositionByTimeInRound = new List < PlayerPositionByTimeInRound > ( ) ,
@@ -1942,7 +1952,7 @@ public List<playerPositionsStats> GetPlayerPositionsStats(ProcessedData processe
19421952 }
19431953
19441954 //create PlayerPositionByTimeInRound with empty PlayerPositionBySteamId
1945- foreach ( var playerPositionsStat in playerPositionsStats )
1955+ foreach ( var playerPositionsStat in playerPositionByRound )
19461956 {
19471957 foreach ( var timeInRoundsGroup in processedData . PlayerPositionsValues . Where ( x => x . Round == playerPositionsStat . Round ) . GroupBy ( x => x . TimeInRound ) )
19481958 {
@@ -1958,7 +1968,7 @@ public List<playerPositionsStats> GetPlayerPositionsStats(ProcessedData processe
19581968 }
19591969
19601970 //create PlayerPositionBySteamId
1961- foreach ( var playerPositionsStat in playerPositionsStats )
1971+ foreach ( var playerPositionsStat in playerPositionByRound )
19621972 {
19631973 foreach ( var playerPositionByTimeInRound in playerPositionsStat . PlayerPositionByTimeInRound )
19641974 {
@@ -1983,10 +1993,16 @@ public List<playerPositionsStats> GetPlayerPositionsStats(ProcessedData processe
19831993 }
19841994 }
19851995
1996+ playerPositionsStats = new PlayerPositionsStats ( )
1997+ {
1998+ DemoName = allStats . mapInfo . DemoName ,
1999+ PlayerPositionByRound = playerPositionByRound ,
2000+ } ;
2001+
19862002 return playerPositionsStats ;
19872003 }
19882004
1989- public void CreateJson ( ProcessedData processedData , AllStats allStats , string mapNameString , string mapDateString )
2005+ public string GetOutputJsonFilepath ( ProcessedData processedData , AllStats allStats , PlayerPositionsStats playerPositionsStats , string mapNameString , string mapDateString )
19902006 {
19912007 string filename = processedData . SameFilename ? allStats . mapInfo . DemoName : Guid . NewGuid ( ) . ToString ( ) ;
19922008
@@ -2017,16 +2033,66 @@ public void CreateJson(ProcessedData processedData, AllStats allStats, string ma
20172033 path += mapDateString + "_" ;
20182034 }
20192035
2020- path += mapNameString + "_" + filename + ".json" ;
2036+ path += mapNameString + "_" + filename ;
2037+
2038+ if ( playerPositionsStats != null )
2039+ {
2040+ path += "_playerpositions" ;
2041+ }
2042+
2043+ path += ".json" ;
2044+
2045+ return path ;
2046+ }
2047+
2048+ public void CreateJsonAllStats ( ProcessedData processedData , AllStats allStats , string mapNameString , string mapDateString )
2049+ {
2050+ var outputFilepath = string . Empty ;
2051+
2052+ try
2053+ {
2054+ outputFilepath = GetOutputJsonFilepath ( processedData , allStats , null , mapNameString , mapDateString ) ;
2055+
2056+ StreamWriter sw = new StreamWriter ( outputFilepath , false ) ;
2057+
2058+ string json = JsonConvert . SerializeObject ( allStats , Formatting . Indented ) ;
2059+
2060+ sw . WriteLine ( json ) ;
2061+ /* JSON creation end*/
2062+
2063+ sw . Close ( ) ;
2064+ }
2065+ catch ( Exception e )
2066+ {
2067+ Console . WriteLine ( "Could not create json file." ) ;
2068+ Console . WriteLine ( string . Concat ( "Filename: " , outputFilepath ) ) ;
2069+ Console . WriteLine ( string . Concat ( "Demoname: " , allStats . mapInfo . DemoName ) ) ;
2070+ }
2071+ }
2072+
2073+ public void CreateJsonPlayerPositionsStats ( ProcessedData processedData , AllStats allStats , PlayerPositionsStats playerPositionsStats , string mapNameString , string mapDateString )
2074+ {
2075+ var outputFilepath = string . Empty ;
2076+
2077+ try
2078+ {
2079+ outputFilepath = GetOutputJsonFilepath ( processedData , allStats , playerPositionsStats , mapNameString , mapDateString ) ;
20212080
2022- StreamWriter sw = new StreamWriter ( path , false ) ;
2081+ StreamWriter sw = new StreamWriter ( outputFilepath , false ) ;
20232082
2024- string json = JsonConvert . SerializeObject ( allStats , Formatting . Indented ) ;
2083+ string json = JsonConvert . SerializeObject ( playerPositionsStats , Formatting . Indented ) ;
20252084
2026- sw . WriteLine ( json ) ;
2027- /* JSON creation end*/
2085+ sw . WriteLine ( json ) ;
2086+ /* JSON creation end*/
20282087
2029- sw . Close ( ) ;
2088+ sw . Close ( ) ;
2089+ }
2090+ catch ( Exception e )
2091+ {
2092+ Console . WriteLine ( "Could not create json file." ) ;
2093+ Console . WriteLine ( string . Concat ( "Filename: " , outputFilepath ) ) ;
2094+ Console . WriteLine ( string . Concat ( "Demoname: " , allStats . mapInfo . DemoName ) ) ;
2095+ }
20302096 }
20312097
20322098 public long GetSteamIdByPlayerName ( Dictionary < long , Dictionary < string , string > > playerNames , string name )
0 commit comments