Skip to content

CLDR-18731 BRS Generate charts for 48 #4795

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import org.unicode.cldr.tool.TablePrinter;
import org.unicode.cldr.util.CLDRPaths;
import org.unicode.cldr.util.CldrUtility;
import org.unicode.cldr.util.PatternCache;
import org.unicode.cldr.util.With;
Expand Down Expand Up @@ -616,4 +618,12 @@ public static void handleFile(String filename, LineHandler handler) throws IOExc
public static Iterable<String> in(File file) {
return With.in(new FileLines(openFile(file, StandardCharsets.UTF_8)));
}

public static void makeTsv(String title, TablePrinter tablePrinter) throws IOException {
String fileName = anchorize(title);
final File tsvFile = new File(CLDRPaths.CHART_DIRECTORY + "tsv/", fileName + ".tsv");
try (final PrintWriter newLsraw = FileUtilities.openUTF8Writer(tsvFile); ) {
tablePrinter.toTsv(newLsraw);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1103,9 +1103,13 @@ private void writeNonLdmlPlain(Anchors anchors) throws IOException {
continue;
}
File dirOld = new File(PREV_CHART_VERSION_DIRECTORY + "common/" + dir);
System.out.println("\tLast dir: " + dirOld);
System.out.println("\tLast dir:\t" + dirOld);
File dir2 = new File(CHART_VERSION_DIRECTORY + "common/" + dir);
System.out.println("\tCurr dir: " + dir2);
boolean isDirectory = dir2.isDirectory();
System.out.println("\tCurr dir:\t" + dir2 + (isDirectory ? "" : "\tNOT DIRECTORY"));
if (!isDirectory) {
continue;
}

for (String file : dir2.list()) {
if (!file.endsWith(".xml")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@
public class ChartUnitConversions extends Chart {
private static final boolean DUMP_UNIT_TABLE_TO_STDOUT = false;

public static final String QUANTITY_MSG =
"The units are grouped and ordered by Quantity (which are based on the NIST quantities, see "
+ "<a href='https://www.nist.gov/pml/special-publication-811' target='nist811'>NIST 811</a>). Note that the quantities are informative.";
public static final String RATIONAL_MSG =
"Each numeric value is an exact rational. (Radians are an exception since the value of π is irrational; a rational approximation is used.)"
+ "The format is a terminating decimal where possible; "
+ "otherwise a repeating decimal if possible (where ˙ marks the start of the <a href='https://en.wikipedia.org/wiki/Repeating_decimal' target='wiki'>reptend</a>); "
+ "otherwise a <a href='https://en.wikipedia.org/wiki/Rational_number' target='wiki'>rational number</a> (of the form <i>numerator/denominator</i>)."
+ "";
public static final String SPEC_GENERAL_MSG =
"The "
+ ldmlSpecLink("/tr35-general.html#Contents")
+ " should be consulted for more details, such as how to handle complex units (such as foot-per-minute) by converting the elements";

public static void main(String[] args) {
new ChartUnitConversions().writeChart(null);
}
Expand All @@ -53,21 +39,49 @@ public String getExplanation() {
return "<p>Unit Conversions provide conversions for units, such as meter ⟹ foot, "
+ "so that a source units can be converted into what is needed for localized "
+ "<a href='unit_preferences.html' target='unit_preferences'>Unit Preferences</a>. "
+ "There are many possible units, and additional units and conversions will be added in future releases.</p>"
+ "<ul>"
+ "<li>Each Source Unit is converted to the Target Unit by multiplying it by the Factor and adding the Offset (if any).</li>"
+ "<li>The unit identifiers are internal, and are to be localized for display to users. See <a href='https://www.unicode.org/cldr/charts/latest/by_type/units.area.html#hectare' target='units.area.hectare'>Hectare</a>, for example. "
+ "<li>"
+ RATIONAL_MSG
+ "There are many possible units, and additional units and conversions will be added in future releases. "
+ "The unit identifiers are internal, and are to be localized for display to users. "
+ "See <a href='https://www.unicode.org/cldr/charts/latest/by_type/units.area.html#hectare' target='units.area.hectare'>Hectare</a>, for example. "
+ "</p>"
+ "<details><summary><b>Column Key</b></summary><ul>"
+ "<li><b>Quantity.</b> "
+ "The units are grouped and ordered by Quantity (which are based on SI quantities according to "
+ "<a href='https://www.nist.gov/pml/special-publication-811' target='nist811'>NIST 811</a>). "
+ "There are some additions, such as year-duration."
+ "</li>"
+ "<li>The Systems column indicates which systems the units are used in. For now, they just show the two ‘inch-pound’ systems.</li>"
+ "<li>"
+ QUANTITY_MSG
+ "<b>Base Unit.</b> The Base Unit is based on an SI base unit or derived unit (with some additions). "
+ "</li>"
+ "<li><b>Systems.</b> These indicate which systems the units are used in. </li>"
+ "<li><b>Source Unit.</b> "
+ "Each Source Unit is converted to the Base Unit by multiplying it by the Factor and adding the Offset (if any). "
+ "The inverse conversion is done by subtracting the Offset, and dividing by the Factor. "
+ "Conversion between units is done by converting the first unit to the Base Units, then using the inverse conversion to get the second unit. "
+ "</li>"
+ "<li><b>Approx. Factor.</b> "
+ "This is an approximation to the exact factor, limited to <a href='https://en.wikipedia.org/wiki/Double-precision_floating-point_format'>double precision</a>,"
+ "which has at most 17 decimal digits of accuracy. "
+ "Some values are given as simple rational numbers. "
+ "Some units (such as beaufort) require more complex conversions than factor & offset. "
+ "The values that are not equivalent to the Exact Factor are marked with ~, such as ~9.4607×10ˆ15. "
+ "</li>"
+ "<li>"
+ SPEC_GENERAL_MSG
+ ".</li>"
+ "<b>Exact* Factor.</b> Each numeric value is an exact rational, "
+ "with a few exceptions, such as radians because the value of π is irrational — a rational approximation is used.) "
+ "The format is a terminating decimal where possible; "
+ "otherwise a repeating decimal if possible (where ˙ marks the start of the <a href='https://en.wikipedia.org/wiki/Repeating_decimal' target='wiki'>reptend</a>); "
+ "otherwise a <a href='https://en.wikipedia.org/wiki/Rational_number' target='wiki'>rational number</a> of the form <i>numerator/denominator</i>. "
+ "The numerator may be a precise decimal (24.01/1331 rather than 2401/133100, and the denominator is skipped if 1."
+ ""
+ "</li>"
+ "<li><b>Offset.</b> This is rarely needed. The format is the same as Exact* Factor. </li>"
+ "</ul>"
+ "<p>"
+ "The "
+ ldmlSpecLink("/tr35-general.html#Contents")
+ " should be consulted for more details, such as how to handle complex units (such as foot-per-minute) by converting the elements, or what the Systems mean. "
+ "</p>"
+ "</details>"
+ dataScrapeMessage(
"/tr35-general.html#Contents",
"common/testData/units/unitsTest.txt",
Expand All @@ -94,7 +108,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException {
true)
.setRepeatHeader(true)
.setBreakSpans(true)
.addColumn("Target", "class='source'", null, "class='source'", true)
.addColumn("Base Unit", "class='source'", null, "class='source'", true)
.addColumn("Systems", "class='source'", null, "class='source'", true)
.addColumn(
"Source Unit",
Expand All @@ -104,7 +118,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException {
true)
.addColumn("Approx. Factor", "class='target'", null, "class='target'", true)
.setCellAttributes("class='target' style='text-align:right'")
.addColumn("Exact* Factor", "class='target'", null, "class='target'", true)
.addColumn("Exact Factor", "class='target'", null, "class='target'", true)
.setCellAttributes("class='target' style='text-align:right'")
.addColumn("Offset", "class='target'", null, "class='target'", true)
.setCellAttributes("class='target' style='text-align:right'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ public String getExplanation() {
+ "<li>The ‘If ≥’ column shows the thresholds: the first line for a given region where the input amount is greater or equal applies. "
+ "For example, for 0.5km as input for [area, default, 001] would result in <i>hectare</i>.</li>"
+ "<li>"
+ ChartUnitConversions.RATIONAL_MSG
+ "Each numeric value is an exact rational. (Radians are an exception since the value of π is irrational; a rational approximation is used.)"
+ "The format is a terminating decimal where possible; "
+ "otherwise a repeating decimal if possible (where ˙ marks the start of the <a href='https://en.wikipedia.org/wiki/Repeating_decimal' target='wiki'>reptend</a>); "
+ "otherwise a <a href='https://en.wikipedia.org/wiki/Rational_number' target='wiki'>rational number</a> (of the form <i>numerator/denominator</i>)."
+ ""
+ "</li>\n"
+ "<li>"
+ ChartUnitConversions.QUANTITY_MSG
+ "The units are grouped and ordered by Quantity (which are based on the NIST quantities, see "
+ "<a href='https://www.nist.gov/pml/special-publication-811' target='nist811'>NIST 811</a>). Note that the quantities are informative."
+ "</li>"
+ "<li>"
+ ChartUnitConversions.SPEC_GENERAL_MSG
+ "The "
+ Chart.ldmlSpecLink("/tr35-general.html#Contents")
+ " should be consulted for more details, such as how to handle complex units (such as foot-per-minute) by converting the elements"
+ ", and how to fall back if a given usage or region is not found.</li>\n"
+ "</ul>"
+ dataScrapeMessage(
Expand Down
Loading
Loading