@@ -62,7 +62,7 @@ public async Task Parse(string url)
62
62
var competition = new Competition ( ) ;
63
63
competition . Url = competitionUrl ;
64
64
competition . Location = "Virtual" ;
65
-
65
+ competition . Name = GetCompetitionName ( stream ) ;
66
66
var competitionGroup = await ParsePdf ( stream ) ;
67
67
competition . CompetitionGroups . Add ( competitionGroup ) ;
68
68
competition . SetTotalResults ( ) ;
@@ -80,11 +80,30 @@ public async Task Parse(string url)
80
80
}
81
81
}
82
82
83
+ private string ? GetCompetitionName ( Stream stream )
84
+ {
85
+ stream . Position = 0 ;
86
+ using ( var pdf = PdfDocument . Open ( stream , new ParsingOptions ( ) { ClipPaths = true } ) )
87
+ {
88
+ var rows = GetTableRows ( pdf ) ;
89
+ var page = pdf . GetPages ( ) . FirstOrDefault ( ) ;
90
+ if ( page == null )
91
+ {
92
+ return string . Empty ;
93
+ }
94
+ var text = ContentOrderTextExtractor . GetText ( page ) ;
95
+ var textLines = text . Split ( new string [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ;
96
+
97
+ var firstLine = textLines . First ( ) ;
98
+ return firstLine . Replace ( "Results" , "" ) . TrimEnd ( ) ;
99
+ }
100
+ }
101
+
83
102
public async Task < CompetitionGroup > ParsePdf ( Stream stream )
84
103
{
85
104
var competitionGroup = new CompetitionGroup ( ) ;
86
105
var competitionRound = new CompetitionRound ( ) ;
87
-
106
+ stream . Position = 0 ;
88
107
using ( var pdf = PdfDocument . Open ( stream , new ParsingOptions ( ) { ClipPaths = true } ) )
89
108
{
90
109
var rows = GetTableRows ( pdf ) ;
@@ -93,8 +112,20 @@ public async Task<CompetitionGroup> ParsePdf(Stream stream)
93
112
var text = ContentOrderTextExtractor . GetText ( page ) ;
94
113
var textLines = text . Split ( new string [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ;
95
114
96
- var firstLine = textLines . First ( ) ;
97
- competitionRound . RoundName = firstLine . Replace ( "Results" , "" ) . TrimEnd ( ) ;
115
+ if ( string . IsNullOrEmpty ( competitionRound . RoundName ) )
116
+ {
117
+ var roundLine = textLines . FirstOrDefault ( t=> t . StartsWith ( "(" ) && t . EndsWith ( ")" ) ) ;
118
+ if ( ! string . IsNullOrEmpty ( roundLine ) )
119
+ {
120
+ roundLine = roundLine . Replace ( "(" , string . Empty ) ;
121
+ roundLine = roundLine . Replace ( ")" , string . Empty ) ;
122
+ var roundLineData = roundLine . Split ( "--" ) ;
123
+ if ( roundLineData . Count ( ) > 0 )
124
+ {
125
+ competitionRound . RoundName = roundLineData [ roundLineData . Count ( ) - 1 ] ;
126
+ }
127
+ }
128
+ }
98
129
99
130
100
131
var topRow = rows . First ( ) . ToArray ( ) ;
0 commit comments