Skip to content

Commit

Permalink
CLDR-16979 CheckCLDR UI for non-path checks
Browse files Browse the repository at this point in the history
- add a new 'supplemental' report that simply lists the overall errors
- update Chart API to take testbundle
  • Loading branch information
srl295 committed Apr 19, 2024
1 parent 277e98c commit be946ad
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2 deletions.
1 change: 1 addition & 0 deletions tools/cldr-apps/js/src/esm/cldrText.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ const strings = {
special_r_datetime: "Datetime",
special_r_zones: "Zones",
special_r_personnames: "Person Names",
special_r_supplemental: "Entire Locale Errors",
special_recent_activity: "Recent Activity",
special_retry: "Retry",
special_retry_inplace: "Retry",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.unicode.cldr.util.VoterReportStatus.ReportAcceptability;
import org.unicode.cldr.util.VoterReportStatus.ReportId;
import org.unicode.cldr.web.CookieSession;
import org.unicode.cldr.web.DataPage;
import org.unicode.cldr.web.ReportsDB;
import org.unicode.cldr.web.ReportsDB.UserReport;
import org.unicode.cldr.web.STFactory;
Expand Down Expand Up @@ -414,10 +415,10 @@ public Response getReportOutput(

private String writeReport(ReportId report, CLDRLocale loc) throws IOException {
final Writer w = new StringWriter();
final STFactory stf = CookieSession.sm.getSTFactory();
final Chart chart = Chart.forReport(report, loc.getBaseName());
if (chart != null) {
final STFactory stf = CookieSession.sm.getSTFactory();
chart.writeContents(w, stf);
chart.writeContents(w, stf, stf.getTestResult(loc, DataPage.getSimpleOptions(loc)));
} else {
switch (report) {
// "Old Three" reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.Writer;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.unicode.cldr.test.TestCache.TestResultBundle;
import org.unicode.cldr.tool.FormattedFileWriter.Anchors;
import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRFile;
Expand Down Expand Up @@ -158,6 +159,11 @@ public void writeContents(Writer pw, Factory factory) throws IOException {
throw new IllegalArgumentException("Not implemented yet");
}

public void writeContents(Writer pw, Factory factory, TestResultBundle bundle)
throws IOException {
this.writeContents(pw, factory);
}

private static final class AnalyticsHelper {
private static final AnalyticsHelper INSTANCE = new AnalyticsHelper();

Expand Down Expand Up @@ -220,6 +226,8 @@ public static Chart forReport(final ReportId report, final String locale) {
switch (report) {
case personnames:
return new ChartPersonName(locale);
case supplemental:
return new ChartSupplemental(locale);
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.unicode.cldr.tool;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.unicode.cldr.test.CheckCLDR.CheckStatus;
import org.unicode.cldr.test.TestCache.TestResultBundle;
import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRFile;
import org.unicode.cldr.util.CLDRPaths;
import org.unicode.cldr.util.Factory;

public class ChartSupplemental extends Chart {
private static final CLDRConfig CLDR_CONFIG = CLDRConfig.getInstance();
static final CLDRFile ENGLISH = CLDR_CONFIG.getEnglish();
static final String DIR = CLDRPaths.CHART_DIRECTORY + "verify/supplemental/";

private final String locale;

public ChartSupplemental(String locale) {
super();
this.locale = locale;
}

@Override
public String getDirectory() {
return DIR;
}

@Override
public String getTitle() {
return ENGLISH.getName(locale) + ": Supplemental Data";
}

@Override
public String getExplanation() {
return "<p>This chart shows supplemental data that is of concern to the locale overall.</p>";
}

@Override
public String getFileName() {
return locale;
}

@Override
public void writeContents(Writer pw, Factory factory, TestResultBundle test)
throws IOException {
CLDRFile cldrFile = factory.make(locale, true);

Set<CheckStatus> pp = new TreeSet<CheckStatus>();

// add any 'early' errors
pp.addAll(test.getPossibleProblems());

// add all non-path status
for (final String x : cldrFile) {
List<CheckStatus> result = new ArrayList<CheckStatus>();
test.check(x, result, cldrFile.getStringValue(x));
for (final CheckStatus s : result) {
if (s.isEntireLocale()) pp.add(s);
}
}

// report

if (pp.isEmpty()) {
pw.write("<h3>No Errors</h3>\n");
pw.write("There are no overall locale issues to report");
} else {
pw.write("<h3>Overall Errors</h3>\n");
pw.write("<ol>\n");
for (final CheckStatus s : pp) {
pw.write(
String.format(
"<li> <b>%s</b> <i>%s</i> - %s</li>\n",
s.getType(), s.getSubtype(), s.getMessage()));
}
pw.write("</ol>\n\n");
}

pw.write("</div> <!-- ReportSupplemental -->\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ public Status getErrorStatus(
StringBuilder errorMessage = new StringBuilder();
factory.getTestCache().getBundle(options).check(path, result, value);
for (CheckStatus checkStatus : result) {
if (checkStatus.isEntireLocale())
continue; // these will show up in the Entire Locale (supplemental) report
final CheckCLDR cause = checkStatus.getCause();
/*
* CheckCoverage will be shown under Missing, not under Warnings; and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class VoterReportStatus<T> {
* 'Person Names' Also see {@link org.unicode.cldr.tool.Chart#forReport(ReportId, String)}
*/
public enum ReportId {
supplemental, // non-Chart (Entire Locale)
datetime, // non-Chart
zones, // non-Chart
compact, // non-Chart, aka 'numbers'
Expand Down

0 comments on commit be946ad

Please sign in to comment.