forked from dotnet/ai-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportingExamples.Example11_GeneratingReportProgrammaticallyFromCustomStorage.cs
More file actions
54 lines (45 loc) · 2.55 KB
/
ReportingExamples.Example11_GeneratingReportProgrammaticallyFromCustomStorage.cs
File metadata and controls
54 lines (45 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using Evaluation.Setup;
using Microsoft.Extensions.AI.Evaluation.Reporting;
using Microsoft.Extensions.AI.Evaluation.Reporting.Formats.Html;
using Reporting.Storage.Sqlite;
namespace Reporting;
public partial class ReportingExamples
{
[TestMethod]
public async Task Example11_GeneratingReportProgrammaticallyFromCustomStorage()
{
/// This example demonstrates how to generate an evaluation report programmatically using the results stored in
/// the SQLite-based result store present under the directory that you specified via the
/// 'EVAL_SAMPLE_STORAGE_ROOT_PATH' environment variable (and that stores results for the examples present in
/// <see cref="Example08_UsingCustomStorage_01"/> and <see cref="Example09_UsingCustomStorage_02"/>).
var results = new List<ScenarioRunResult>();
IResultStore sqliteResultStore = new SqliteResultStore(s_sqliteResultsFilePath);
/// Use the <see cref="resultStore"/> object above to read all results for the 'latest' execution.
await foreach (string executionName in sqliteResultStore.GetLatestExecutionNamesAsync(count: 1))
{
await foreach (ScenarioRunResult result in sqliteResultStore.ReadResultsAsync(executionName))
{
results.Add(result);
}
}
string reportFilePath = Path.Combine(EnvironmentVariables.StorageRootPath, "report_sqlite.html");
IEvaluationReportWriter reportWriter = new HtmlReportWriter(reportFilePath);
/// Generate a report containing the results read from the <see cref="resultStore"/> above.
await reportWriter.WriteReportAsync(results);
/// Open the generated report in the default browser.
Process.Start(
new ProcessStartInfo()
{
FileName = reportFilePath,
UseShellExecute = true
});
/// Note that the above report generation code won't quite work if you execute the tests in this project one at
/// a time (since each such result will then be considered part of a different (previous) execution as opposed
/// to the current (latest) execution in this case). In other words, the report generation code above will only
/// work when you run all unit tests in this project as part of a single execution.
}
}