@@ -803,17 +803,19 @@ public static MatchData FromDemoFile(string file, bool parseChickens, bool parse
803
803
return md ;
804
804
}
805
805
806
- public AllStats CreateFiles ( ProcessedData processedData , bool createJsonFile = true )
806
+ public AllOutputData CreateFiles ( ProcessedData processedData , bool createJsonFile = true )
807
807
{
808
808
var mapDateSplit = ( ! string . IsNullOrWhiteSpace ( processedData . DemoInformation . TestDate ) && processedData . DemoInformation . TestDate != "unknown" ) ? processedData . DemoInformation . TestDate . Split ( '/' ) : null ;
809
809
var mapDateString = ( mapDateSplit != null && mapDateSplit . Count ( ) >= 3 ) ? ( mapDateSplit [ 2 ] + "_" + mapDateSplit [ 0 ] + "_" + mapDateSplit [ 1 ] ) : string . Empty ;
810
810
811
811
var mapNameSplit = ( processedData . MatchStartValues . Count ( ) > 0 ) ? processedData . MatchStartValues . ElementAt ( 0 ) . Mapname . Split ( '/' ) : new string [ ] { processedData . DemoInformation . MapName } ;
812
812
var mapNameString = mapNameSplit . Count ( ) > 2 ? mapNameSplit [ 2 ] : mapNameSplit [ 0 ] ;
813
813
814
-
815
814
var dataAndPlayerNames = GetDataAndPlayerNames ( processedData ) ;
816
815
816
+
817
+ PlayerPositionsStats playerPositionsStats = null ;
818
+
817
819
AllStats allStats = new AllStats
818
820
{
819
821
versionNumber = GetVersionNumber ( ) ,
@@ -848,18 +850,24 @@ public AllStats CreateFiles(ProcessedData processedData, bool createJsonFile = t
848
850
849
851
allStats . firstDamageStats = GetFirstDamageStats ( processedData ) ;
850
852
851
- if ( processedData . ParsePlayerPositions )
853
+ // JSON creation
854
+ if ( createJsonFile )
852
855
{
853
- allStats . playerPositionsStats = GetPlayerPositionsStats ( processedData ) ;
856
+ CreateJsonAllStats ( processedData , allStats , mapNameString , mapDateString ) ;
854
857
}
855
858
856
- // JSON creation
857
- if ( createJsonFile )
859
+ if ( processedData . ParsePlayerPositions )
858
860
{
859
- CreateJson ( processedData , allStats , mapNameString , mapDateString ) ;
861
+ playerPositionsStats = GetPlayerPositionsStats ( processedData , allStats ) ;
862
+ CreateJsonPlayerPositionsStats ( processedData , allStats , playerPositionsStats , mapNameString , mapDateString ) ;
860
863
}
861
864
862
- return allStats ;
865
+ // return for testing purposes
866
+ return new AllOutputData ( )
867
+ {
868
+ AllStats = allStats ,
869
+ PlayerPositionsStats = playerPositionsStats ,
870
+ } ;
863
871
}
864
872
865
873
public DataAndPlayerNames GetDataAndPlayerNames ( ProcessedData processedData )
@@ -1922,18 +1930,20 @@ public List<firstDamageStats> GetFirstDamageStats(ProcessedData processedData)
1922
1930
return firstDamageStats ;
1923
1931
}
1924
1932
1925
- public List < playerPositionsStats > GetPlayerPositionsStats ( ProcessedData processedData )
1933
+ public PlayerPositionsStats GetPlayerPositionsStats ( ProcessedData processedData , AllStats allStats )
1926
1934
{
1927
- List < playerPositionsStats > playerPositionsStats = new List < playerPositionsStats > ( ) ;
1935
+ PlayerPositionsStats playerPositionsStats ;
1936
+
1937
+ List < PlayerPositionByRound > playerPositionByRound = new List < PlayerPositionByRound > ( ) ;
1928
1938
1929
- // create playerPositionsStats with empty PlayerPositionByTimeInRound
1939
+ // create playerPositionByRound with empty PlayerPositionByTimeInRound
1930
1940
foreach ( var roundsGroup in processedData . PlayerPositionsValues . GroupBy ( x => x . Round ) )
1931
1941
{
1932
1942
int lastRound = processedData . RoundEndReasonValues . Count ( ) ;
1933
1943
1934
1944
foreach ( var round in roundsGroup . Where ( x => x . Round > 0 && x . Round <= lastRound ) . Select ( x => x . Round ) . Distinct ( ) )
1935
1945
{
1936
- playerPositionsStats . Add ( new playerPositionsStats ( )
1946
+ playerPositionByRound . Add ( new PlayerPositionByRound ( )
1937
1947
{
1938
1948
Round = round ,
1939
1949
PlayerPositionByTimeInRound = new List < PlayerPositionByTimeInRound > ( ) ,
@@ -1942,7 +1952,7 @@ public List<playerPositionsStats> GetPlayerPositionsStats(ProcessedData processe
1942
1952
}
1943
1953
1944
1954
//create PlayerPositionByTimeInRound with empty PlayerPositionBySteamId
1945
- foreach ( var playerPositionsStat in playerPositionsStats )
1955
+ foreach ( var playerPositionsStat in playerPositionByRound )
1946
1956
{
1947
1957
foreach ( var timeInRoundsGroup in processedData . PlayerPositionsValues . Where ( x => x . Round == playerPositionsStat . Round ) . GroupBy ( x => x . TimeInRound ) )
1948
1958
{
@@ -1958,7 +1968,7 @@ public List<playerPositionsStats> GetPlayerPositionsStats(ProcessedData processe
1958
1968
}
1959
1969
1960
1970
//create PlayerPositionBySteamId
1961
- foreach ( var playerPositionsStat in playerPositionsStats )
1971
+ foreach ( var playerPositionsStat in playerPositionByRound )
1962
1972
{
1963
1973
foreach ( var playerPositionByTimeInRound in playerPositionsStat . PlayerPositionByTimeInRound )
1964
1974
{
@@ -1983,10 +1993,16 @@ public List<playerPositionsStats> GetPlayerPositionsStats(ProcessedData processe
1983
1993
}
1984
1994
}
1985
1995
1996
+ playerPositionsStats = new PlayerPositionsStats ( )
1997
+ {
1998
+ DemoName = allStats . mapInfo . DemoName ,
1999
+ PlayerPositionByRound = playerPositionByRound ,
2000
+ } ;
2001
+
1986
2002
return playerPositionsStats ;
1987
2003
}
1988
2004
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 )
1990
2006
{
1991
2007
string filename = processedData . SameFilename ? allStats . mapInfo . DemoName : Guid . NewGuid ( ) . ToString ( ) ;
1992
2008
@@ -2017,16 +2033,66 @@ public void CreateJson(ProcessedData processedData, AllStats allStats, string ma
2017
2033
path += mapDateString + "_" ;
2018
2034
}
2019
2035
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 ) ;
2021
2080
2022
- StreamWriter sw = new StreamWriter ( path , false ) ;
2081
+ StreamWriter sw = new StreamWriter ( outputFilepath , false ) ;
2023
2082
2024
- string json = JsonConvert . SerializeObject ( allStats , Formatting . Indented ) ;
2083
+ string json = JsonConvert . SerializeObject ( playerPositionsStats , Formatting . Indented ) ;
2025
2084
2026
- sw . WriteLine ( json ) ;
2027
- /* JSON creation end*/
2085
+ sw . WriteLine ( json ) ;
2086
+ /* JSON creation end*/
2028
2087
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
+ }
2030
2096
}
2031
2097
2032
2098
public long GetSteamIdByPlayerName ( Dictionary < long , Dictionary < string , string > > playerNames , string name )
0 commit comments