Skip to content
Snippets Groups Projects
Commit 08e45ae6 authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Merge branch 'iss933' into dev

parents 142af332 cde1d4ac
Branches
No related tags found
No related merge requests found
...@@ -51,6 +51,6 @@ data: makelist([rand(322)/100.0,rand(600)/100.0,rand(300)/100.0], i, 50); ...@@ -51,6 +51,6 @@ data: makelist([rand(322)/100.0,rand(600)/100.0,rand(300)/100.0], i, 50);
``` ```
[[comment]]Use them like this in the question-text.[[/comment]] [[comment]]Use them like this in the question-text.[[/comment]]
Load the data from Load the data from
<a href="[[textdownload name="data.csv"]]{@["%root",stack_csv_formatter(data,lab)]@}[[/textdownload]]">this file</a> and ... <a href="[[textdownload name="data.csv"]]{@stack_csv_formatter(data,lab)@}[[/textdownload]]">this file</a> and ...
``` ```
That function returns a string and it takes in the data as a matrix or a list of lists and labels as a list. If no labels are necessary use `false`. Also you can use `stackfltfmt` to control the representation of pure floats in the data. Just in case you meet trouble `labels` is a keyword that cannot be used which is a shame when defining labels. That function returns a string and it takes in the data as a matrix or a list of lists and labels as a list. If no labels are necessary use `false`. Also you can use `stackfltfmt` to control the representation of pure floats in the data. Just in case you meet trouble `labels` is a keyword that cannot be used which is a shame when defining labels.
...@@ -234,12 +234,10 @@ stackjson_stringify(obj) := block([tmp,r,l], ...@@ -234,12 +234,10 @@ stackjson_stringify(obj) := block([tmp,r,l],
/** /**
* Special tools for dealing with CASText2, absolutely no use * Special tools for dealing with CASText2.
* if you are not running a system with CASText2.
* *
* Even if you have CASText2 enabled system these tools are very * These tools are very advanced and probably not for a novice author.
* advanced and probably not for a novice author. Essenttially, * Essentially, these are useful if one generates CASText2 values inside
* these are useful if one generates CASText2 values inside
* keyval-fields and/or stores them into the state in Stateful. * keyval-fields and/or stores them into the state in Stateful.
* The only real use for a raw CASText2 value is to be outputted * The only real use for a raw CASText2 value is to be outputted
* by the castext-block within castext itself. * by the castext-block within castext itself.
...@@ -317,8 +315,8 @@ return(bool1))$ ...@@ -317,8 +315,8 @@ return(bool1))$
/* STACK csv-helpper special tool for file output generation. /* STACK csv-helpper special tool for file output generation.
* Generates a string in CSV format of a list of lists or a matrix * Generates a string in CSV format of a list of lists or a matrix
* with an optional list of labels * with an optional list of labels
* Will use normal grind/string style value form output but will return string * Will use normal grind/string style value form output but will return a castext list ["%root", ...]
* values without Maxima style escapes. Special handling for pure float * with values without Maxima style escapes. Special handling for pure float
* values, with them will use `stackfltfmt` to tune display. * values, with them will use `stackfltfmt` to tune display.
* Uses "-wrapped strings when need be and picks , or ; as the separator * Uses "-wrapped strings when need be and picks , or ; as the separator
* based on how many values would need to be wrapped. * based on how many values would need to be wrapped.
...@@ -400,8 +398,9 @@ stack_csv_formatter(_data, _labels) := block([_sep,simp,_out,_rowcount,_sepcount ...@@ -400,8 +398,9 @@ stack_csv_formatter(_data, _labels) := block([_sep,simp,_out,_rowcount,_sepcount
/* Now let's join everything up. */ /* Now let's join everything up. */
_out: maplist(lambda([_row], simplode(_row, _sep)), _out), _out: maplist(lambda([_row], simplode(_row, _sep)), _out),
_out: simplode(_out," _out: simplode(_out,"
") "),
/* We might want to add a line change to the end. */ /* We might want to add a line change to the end. */
return(["%root", _out])
)$ )$
......
...@@ -2045,7 +2045,7 @@ class castext_test extends qtype_stack_testcase { ...@@ -2045,7 +2045,7 @@ class castext_test extends qtype_stack_testcase {
$this->assertTrue($at2->get_valid()); $this->assertTrue($at2->get_valid());
$cs2->add_statement($at2); $cs2->add_statement($at2);
$cs2->instantiate(); $cs2->instantiate();
$this->assertEquals("\"A,B\n1.24,1.34\n2.23,4.56\"", $at2->get_rendered()); $this->assertEquals("[\"%root\",\"A,B\n1.24,1.34\n2.23,4.56\"]", $at2->get_rendered());
$vars = 'S1:stack_csv_formatter([[1.24,1.34],[2.23,4.56]],[A,B]);'; $vars = 'S1:stack_csv_formatter([[1.24,1.34],[2.23,4.56]],[A,B]);';
$at1 = new stack_cas_keyval($vars, $options, 123); $at1 = new stack_cas_keyval($vars, $options, 123);
...@@ -2055,10 +2055,10 @@ class castext_test extends qtype_stack_testcase { ...@@ -2055,10 +2055,10 @@ class castext_test extends qtype_stack_testcase {
$this->assertTrue($at2->get_valid()); $this->assertTrue($at2->get_valid());
$cs2->add_statement($at2); $cs2->add_statement($at2);
$cs2->instantiate(); $cs2->instantiate();
// We currently strip out newlines in the LaTeX representation of strings. // We add in some magic to the return to not strip out newlines in the LaTeX representation of strings.
// This does not matter in LaTeX but does in other uses, such as download. $this->assertEquals("A,B\n1.24,1.34\n2.23,4.56", $at2->get_rendered());
$this->assertEquals("A,B1.24,1.342.23,4.56", $at2->get_rendered());
// Extra wrapping does no harm.
$vars = 'S1:["%root",stack_csv_formatter([[1.24,1.34],[2.23,4.56]],[A,B])];'; $vars = 'S1:["%root",stack_csv_formatter([[1.24,1.34],[2.23,4.56]],[A,B])];';
$at1 = new stack_cas_keyval($vars, $options, 123); $at1 = new stack_cas_keyval($vars, $options, 123);
$this->assertTrue($at1->get_valid()); $this->assertTrue($at1->get_valid());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment