How to generate analysis report by opening an existing project programmatically via API

Hi,

I want to use Trados API to do project automation. Currently I am familiar with many tasks.

But for analysis report, I have a question. 

Currently, If I run a new project, I know using the following method to generate a report out.

AutomaticTask analyzeTask = project.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.AnalyzeFiles);

Guid reportId = analyzeTask.Id;
project.SaveTaskReportAs(reportId, filePath, Sdl.ProjectAutomation.Core.ReportFormat.Excel);

But I want just to open an existing project and only want to generate the analysis report, how to to do that, I don't know how to get the report ID without running the analysis (the exisitng project has run the analysis task).

I am using two versions, Trados 2019 and Trados 2024, both version do not have such API doc about this part.

Thanks,

Parents
  • Hi Flavio,

    you can access an existing project via the ProjectController (the project list in Studio), or via opening a stored file based project:


    var projController = SdlTradosStudio.Application.GetController<ProjectsController>();
    var proj = projController.CurrentProject;

    or

    proj = new FileBasedProject(projectFilePath);

    After that, you can access various project information, including the already generated statistics:

    var pi = proj.GetProjectStatistics();
    var tc = pi.TargetLanguageStatistics[0];
    var ana = tc.AnalysisStatistics;
    var pinfo = proj.GetProjectInfo();
    pName = pinfo.Name;

    Unfortunately, as far as I know you cannot directly save this statistics as an Excel report. You can generate your own though, maybe populate an Excel template via OpenXML or Excel Interop.
    The following code simply concats all info for a MessageBox but it should not be a big problem using the same info to populate any other grid or template:

    txt =
    $"Project: {pinfo.Name}\r\nTotal words: {tc.AnalysisStatistics.Total.Words}\r\Comprising Rep: {tc.AnalysisStatistics.Repetitions.Words}\r\n100+CM: {tc.AnalysisStatistics.Exact.Words + tc.AnalysisStatistics.Perfect.Words + tc.AnalysisStatistics.InContextExact.Words}\r\nFuzzy:";
    foreach (var fcd in tc.AnalysisStatistics.Fuzzy)
    {
    txt += $"{fcd.Band.MinimumMatchValue}-{fcd.Band.MaximumMatchValue}: {fcd.Words}\r\n";
    }

    Would this work for you?

    Best,
    Andreas

Reply
  • Hi Flavio,

    you can access an existing project via the ProjectController (the project list in Studio), or via opening a stored file based project:


    var projController = SdlTradosStudio.Application.GetController<ProjectsController>();
    var proj = projController.CurrentProject;

    or

    proj = new FileBasedProject(projectFilePath);

    After that, you can access various project information, including the already generated statistics:

    var pi = proj.GetProjectStatistics();
    var tc = pi.TargetLanguageStatistics[0];
    var ana = tc.AnalysisStatistics;
    var pinfo = proj.GetProjectInfo();
    pName = pinfo.Name;

    Unfortunately, as far as I know you cannot directly save this statistics as an Excel report. You can generate your own though, maybe populate an Excel template via OpenXML or Excel Interop.
    The following code simply concats all info for a MessageBox but it should not be a big problem using the same info to populate any other grid or template:

    txt =
    $"Project: {pinfo.Name}\r\nTotal words: {tc.AnalysisStatistics.Total.Words}\r\Comprising Rep: {tc.AnalysisStatistics.Repetitions.Words}\r\n100+CM: {tc.AnalysisStatistics.Exact.Words + tc.AnalysisStatistics.Perfect.Words + tc.AnalysisStatistics.InContextExact.Words}\r\nFuzzy:";
    foreach (var fcd in tc.AnalysisStatistics.Fuzzy)
    {
    txt += $"{fcd.Band.MinimumMatchValue}-{fcd.Band.MaximumMatchValue}: {fcd.Words}\r\n";
    }

    Would this work for you?

    Best,
    Andreas

Children