Skip to content

Commit 4893287

Browse files
committed
Fix naming of events in speedpuzzling parser.
1 parent 769527a commit 4893287

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

Arctic.Puzzlers.Parsers/CompetitionParsers/SpeedPuzzlingParser.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public async Task Parse(string url)
6262
var competition = new Competition();
6363
competition.Url = competitionUrl;
6464
competition.Location = "Virtual";
65-
65+
competition.Name = GetCompetitionName(stream);
6666
var competitionGroup = await ParsePdf(stream);
6767
competition.CompetitionGroups.Add(competitionGroup);
6868
competition.SetTotalResults();
@@ -80,11 +80,30 @@ public async Task Parse(string url)
8080
}
8181
}
8282

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+
83102
public async Task<CompetitionGroup> ParsePdf(Stream stream)
84103
{
85104
var competitionGroup = new CompetitionGroup();
86105
var competitionRound = new CompetitionRound();
87-
106+
stream.Position = 0;
88107
using (var pdf = PdfDocument.Open(stream, new ParsingOptions() { ClipPaths = true }))
89108
{
90109
var rows = GetTableRows(pdf);
@@ -93,8 +112,20 @@ public async Task<CompetitionGroup> ParsePdf(Stream stream)
93112
var text = ContentOrderTextExtractor.GetText(page);
94113
var textLines = text.Split(new string[] { "\r\n", "\r", "\n" },StringSplitOptions.None);
95114

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+
}
98129

99130

100131
var topRow = rows.First().ToArray();

0 commit comments

Comments
 (0)