Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LT-21999: Improve saving of parser test reports #224

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions Src/LexText/ParserUI/ParserListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ private void UpdateWordforms(IEnumerable<IWfiWordform> wordforms, ParserPriority
ReadParserReports();
// Write an empty parser report.
var parserReport = CreateParserReport();
AddParserReport(parserReport);
ShowParserReport(parserReport, m_mediator, m_cache);
ParserReportViewModel viewModel = AddParserReport(parserReport);
ShowParserReport(viewModel, m_mediator, m_cache);
}
}
m_parserConnection.UpdateWordforms(wordforms, priority, checkParser);
Expand Down Expand Up @@ -670,8 +670,8 @@ private void WordformUpdatedEventHandler(object sender, WordformUpdatedEventArgs
ReadParserReports();
// Convert parse results into ParserReport.
var parserReport = CreateParserReport();
AddParserReport(parserReport);
ShowParserReport(parserReport, m_mediator, m_cache);
ParserReportViewModel viewModel = AddParserReport(parserReport);
ShowParserReport(viewModel, m_mediator, m_cache);
}
}

Expand Down Expand Up @@ -701,15 +701,18 @@ ParserReport CreateParserReport()
return parserReport;
}

public static void SaveParserReport(ParserReport report, LcmCache cache, string defaultComment)
public static void SaveParserReport(ParserReportViewModel reportViewModel, LcmCache cache, string defaultComment)
{
Form inputBox = CreateInputBox(ParserUIStrings.ksEnterComment, ref defaultComment);
DialogResult result = inputBox.ShowDialog();
if (result == DialogResult.OK)
{
ParserReport report = reportViewModel.ParserReport;
Control textBox = inputBox.Controls["input"];
report.Comment = textBox.Text;
report.DeleteJsonFile();
report.WriteJsonFile(cache);
reportViewModel.UpdateDisplayComment();
}
}

Expand Down Expand Up @@ -850,20 +853,22 @@ private void ReadParserReports()
/// <summary>
/// Add parserReport to the list of parser reports.
/// </summary>
private void AddParserReport(ParserReport parserReport)
private ParserReportViewModel AddParserReport(ParserReport parserReport)
{
m_parserReports.Insert(0, new ParserReportViewModel { ParserReport = parserReport });
ParserReportViewModel viewModel = new ParserReportViewModel { ParserReport = parserReport };
m_parserReports.Insert(0, viewModel);
if (m_parserReportsDialog != null)
// Reset ParserReports so that the window gets notified when the new report is selected.
((ParserReportsViewModel)m_parserReportsDialog.DataContext).ParserReports = m_parserReports;
return viewModel;
}

/// <summary>
/// Display a parser report window.
/// </summary>
/// <param name="parserReport"></param>
/// <param name="mediator">the mediator is used to call TryAWord</param>
public static void ShowParserReport(ParserReport parserReport, Mediator mediator, LcmCache cache)
public static void ShowParserReport(ParserReportViewModel parserReport, Mediator mediator, LcmCache cache)
{
ParserReportDialog dialog = new ParserReportDialog(parserReport, mediator, cache);
dialog.Show();
Expand Down
250 changes: 132 additions & 118 deletions Src/LexText/ParserUI/ParserReportDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,169 +14,183 @@
<local:PositiveIntToRedBrushConverter x:Key="PositiveIntToRedBrushConverter" />
</Window.Resources>
<Grid>
<DataGrid AutoGenerateColumns="False" CanUserAddRows="False" ItemsSource="{Binding ParseReports}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="{x:Static local:ParserUIStrings.ksShowAnalyses}"
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto" PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
<DataGrid Name="DataGrid" AutoGenerateColumns="False" CanUserAddRows="False" IsReadOnly="True" SelectionChanged="DataGrid_SelectionChanged"
MouseDoubleClick="DataGrid_MouseDoubleClick" ItemsSource="{Binding ParseReports}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="{x:Static local:ParserUIStrings.ksShowAnalyses}"
ToolTip="{x:Static local:ParserUIStrings.ksShowAnalysesToolTip}"
Click="ShowWordAnalyses"
CommandParameter="{Binding}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="{x:Static local:ParserUIStrings.ksReparse}"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="{x:Static local:ParserUIStrings.ksReparse}"
ToolTip="{x:Static local:ParserUIStrings.ksReparseToolTip}"
Click="ReparseWord"
CommandParameter="{Binding}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Word}">
<DataGridTextColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksWord}"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Word}">
<DataGridTextColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksWord}"
ToolTip="{x:Static local:ParserUIStrings.ksWordToolTip}"/>
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksNumWordsParsedToolTip}"
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksNumWordsParsedToolTip}"
Text="{Binding DataContext.ParserReport.NumWords, RelativeSource={RelativeSource AncestorType=DataGrid}}"></TextBlock>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTemplateColumn SortMemberPath="NoParse" CanUserSort="True">
<DataGridTemplateColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumZeroParses}"
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTemplateColumn SortMemberPath="NoParse" CanUserSort="True">
<DataGridTemplateColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumZeroParses}"
ToolTip="{x:Static local:ParserUIStrings.ksNumZeroParsesToolTip}"/>
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksNumZeroParsesToolTip}"
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksNumZeroParsesToolTip}"
Text="{Binding DataContext.ParserReport.NumZeroParses, RelativeSource={RelativeSource AncestorType=DataGrid}}"
Foreground="{Binding DataContext.ParserReport.NumZeroParses,
RelativeSource={RelativeSource AncestorType=DataGrid},
Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</StackPanel>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NoParse}"
</StackPanel>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NoParse}"
Foreground="{Binding NoParse, Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn SortMemberPath="NumUserApprovedAnalysesMissing" CanUserSort="True">
<DataGridTemplateColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumMissingAnalyses}"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn SortMemberPath="NumUserApprovedAnalysesMissing" CanUserSort="True">
<DataGridTemplateColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumMissingAnalyses}"
ToolTip="{x:Static local:ParserUIStrings.ksNumMissingAnalysesToolTip}"/>
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksTotalMissingAnalysesToolTip}"
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksTotalMissingAnalysesToolTip}"
Text="{Binding DataContext.ParserReport.TotalUserApprovedAnalysesMissing, RelativeSource={RelativeSource AncestorType=DataGrid}}"
Foreground="{Binding DataContext.ParserReport.TotalUserApprovedAnalysesMissing,
RelativeSource={RelativeSource AncestorType=DataGrid},
Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</StackPanel>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NumUserApprovedAnalysesMissing}"
</StackPanel>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NumUserApprovedAnalysesMissing}"
Foreground="{Binding NumUserApprovedAnalysesMissing, Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn SortMemberPath="NumUserDisapprovedAnalyses" CanUserSort="True">
<DataGridTemplateColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumDisapprovedAnalyses}"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn SortMemberPath="NumUserDisapprovedAnalyses" CanUserSort="True">
<DataGridTemplateColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumDisapprovedAnalyses}"
ToolTip="{x:Static local:ParserUIStrings.ksNumDisapprovedAnalysesToolTip}"/>
<Separator/>
<TextBlock ToolTip="{x:Static local:ParserUIStrings.ksTotalDisapprovedAnalysesToolTip}"
<Separator/>
<TextBlock ToolTip="{x:Static local:ParserUIStrings.ksTotalDisapprovedAnalysesToolTip}"
Text="{Binding DataContext.ParserReport.TotalUserDisapprovedAnalyses, RelativeSource={RelativeSource AncestorType=DataGrid}}"
Foreground="{Binding DataContext.ParserReport.TotalUserDisapprovedAnalyses,
RelativeSource={RelativeSource AncestorType=DataGrid},
Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</StackPanel>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NumUserDisapprovedAnalyses}"
</StackPanel>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NumUserDisapprovedAnalyses}"
Foreground="{Binding NumUserDisapprovedAnalyses, Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn SortMemberPath="NumUserNoOpinionAnalyses" CanUserSort="True">
<DataGridTemplateColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumNoOpinionAnalyses}"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn SortMemberPath="NumUserNoOpinionAnalyses" CanUserSort="True">
<DataGridTemplateColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumNoOpinionAnalyses}"
ToolTip="{x:Static local:ParserUIStrings.ksNumNoOpinionAnalysesToolTip}"/>
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksTotalNoOpinionAnalysesToolTip}"
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksTotalNoOpinionAnalysesToolTip}"
Text="{Binding DataContext.ParserReport.TotalUserNoOpinionAnalyses, RelativeSource={RelativeSource AncestorType=DataGrid}}"
Foreground="{Binding DataContext.ParserReport.TotalUserNoOpinionAnalyses,
RelativeSource={RelativeSource AncestorType=DataGrid},
Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</StackPanel>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NumUserNoOpinionAnalyses}"
</StackPanel>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NumUserNoOpinionAnalyses}"
Foreground="{Binding NumUserNoOpinionAnalyses, Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding ErrorMessage}" Width="100">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}"
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding ErrorMessage}" Width="100">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="TextWrapping"
<Setter Property="TextWrapping"
Value="NoWrap" />
<Setter Property="TextTrimming"
<Setter Property="TextTrimming"
Value="CharacterEllipsis" />
<Setter Property="ToolTip"
<Setter Property="ToolTip"
Value="{Binding ErrorMessage}" />
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksErrorMessage}"
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksErrorMessage}"
ToolTip="{x:Static local:ParserUIStrings.ksErrorMessageToolTip}"/>
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksNumParseErrorsToolTip}"
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksNumParseErrorsToolTip}"
Text="{Binding DataContext.ParserReport.NumParseErrors, RelativeSource={RelativeSource AncestorType=DataGrid}}"
Foreground="{Binding DataContext.ParserReport.NumParseErrors,
RelativeSource={RelativeSource AncestorType=DataGrid},
Converter={StaticResource PositiveIntToRedBrushConverter}}"/>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumAnalyses}">
<DataGridTextColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumAnalyses}"
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumAnalyses}">
<DataGridTextColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksNumAnalyses}"
ToolTip="{x:Static local:ParserUIStrings.ksNumAnalysesToolTip}"/>
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksTotalAnalysesToolTip}"
<Separator/>
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksTotalAnalysesToolTip}"
Text="{Binding DataContext.ParserReport.TotalAnalyses, RelativeSource={RelativeSource AncestorType=DataGrid}}"></TextBlock>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ParseTime, Converter={StaticResource MillisecondsToTimeSpanConverter}, StringFormat=\{0:g\}}">
<DataGridTextColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksParseTime}"
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ParseTime, Converter={StaticResource MillisecondsToTimeSpanConverter}, StringFormat=\{0:g\}}">
<DataGridTextColumn.Header>
<StackPanel>
<Label Content="{x:Static local:ParserUIStrings.ksParseTime}"
ToolTip="{x:Static local:ParserUIStrings.ksParseTimeToolTip}"/>
<Separator/>
<!-- The following must be a TextBlock for StringFormat to work. -->
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksTotalParseTimeToolTip}"
<Separator/>
<!-- The following must be a TextBlock for StringFormat to work. -->
<TextBlock ToolTip ="{x:Static local:ParserUIStrings.ksTotalParseTimeToolTip}"
Text="{Binding DataContext.ParserReport.TotalParseTime, RelativeSource={RelativeSource AncestorType=DataGrid},
Converter={StaticResource MillisecondsToTimeSpanConverter}, StringFormat=\{0:g\}}"></TextBlock>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Height="40">
<Button Content="{x:Static local:ParserUIStrings.ksSaveReport}"
ToolTip="{x:Static local:ParserUIStrings.ksSaveReportToolTip}"
Click="SaveParserReport" Width="100" Margin="5"/>
<Label x:Name="commentLabel" Height="27"/>
<Label Content="{Binding DisplayComment, Mode=OneWay}" Height="27"/>
</StackPanel>
</Grid>
</Window>
Loading
Loading