CSVProvider csv write width and precision

92 views
Skip to first unread message

László Torjai

unread,
Apr 25, 2019, 2:58:43 AM4/25/19
to AIMMS - The Modeling System
Hello,

Below is the sample procedure to write data out into a csv file.
However, I haven't found a way to set the width and precision of the numeric 'Capacity' column which should be written out with 3 decimal places (by default, it is rounded to the closest integer by the CSVProvider). 

---------------------------
empty DataMap;
dl::DataTables += {'Capacity'} ;
DataMap(dl::dt,dl::idn,dl::cn,dl::dn) := data {
( 'Capacity', 'Store'       , 1, 1 ) : "Store",
( 'Capacity', 'Capacity'       , 2, 0 ) : "Capacity"
};

dl::RemoveDataSourceMapping("TheMapping");
dl::AddDataSourceMapping("TheMapping", DataMap, dl::DependEmpty, dl::TableAttributesEmpty, dl::ColAttributeEmpty);

spCommunicationAttributes := { 'DataProvider' : csvprov::DataLink ,'ContainsHeaders' : "yes", 'Separator': ","};

dl::DataWrite(CurrentFolder, "TheMapping" , spCommunicationAttributes);
---------------------------

I have  the identifier spColAttr(dl::colattr) but couldn't really found how to refer to its values.

Could you please advise if I need to create further identifiers and how to set the precision and width of the csv?

Thank you in advance,
Laszlo

Mohan

unread,
Apr 25, 2019, 8:26:25 PM4/25/19
to AIMMS - The Modeling System
Hi Laszlo,

You can specify a string parameter, say ColumnAttributes like below.

StringParameter ColumnAttributes {
   
IndexDomain: dl::colattr;
   
Definition: data { Precision : "3" };
}
If you click on the definition or data of this, you will see the different values of dl::colattr which are Filter, Width, Precision, Format. In the above example, I set Precision as 3.

Now, modify your dl::AddDataSourceMapping call as below. Instead of using the predeclared dl::colAttributeEmpty, you will use the string parameter ColumnAttributes that you declared.

dl::AddDataSourceMapping("TheMapping", DataMap, dl::DependEmpty, dl::TableAttributesEmpty, ColumnAttributes);
Hope this helps.

László Torjai

unread,
Apr 30, 2019, 9:32:13 AM4/30/19
to AIMMS - The Modeling System
Hi Mohan,

As a result I get an error message as below:
"There is a mismatch in the master sets of domain set "dl::ColumnAttributes" and domain set "dl::DataTables" in the fifth argument of the call to external procedure "dl::AddDataSourceMapping"."

Should I change something else too?

Thank you,
Laszlo

Mohan

unread,
May 2, 2019, 5:22:25 PM5/2/19
to AIMMS - The Modeling System
Hello Laszlo,

Sorry, my mistake. My previous post wasn't complete.

ColumnAttributes must have index domain as below. The same index domain as sp::ColAttributeEmpty

StringParameter ColAttributes {
   
IndexDomain: (dl::dt, dl::cn, dl::colattr);
}

Now, you will add the precision values to this ColAttributes before you create the data source mapping.

sp_DataMap(dl::dt, dl::idn, dl::cn, dl::dn) := data {
(CSVTest, s_I, 1, 1) : "IndexColumn",
(CSVTest, p_data, 2, 0) : "Values"};

sp_MapName
:= "CSVMapTest";

dl
::RemoveDataSourceMapping(MapName : sp_MapName );

ColAttributes(dl::dt, dl::cn, dl::colattr) := data{
(CSVTest, 2, Precision): "4"};

dl
::AddDataSourceMapping(
   
MapName        : sp_MapName ,
   
DataMap        : sp_DataMap ,
   
ColDepend      : dl::DependEmpty ,
   
TableAttribute : dl::TableAttributesEmpty ,
   
ColAttribute   : ColAttributes );

dl::dt value will be the same as the one you used in DataMap, so - Capacity.

You want to modify the precision of the values of capacity which is in column number 2 according to your data map. Hence, the column attributes.

Hope this helps

László Torjai

unread,
May 8, 2019, 1:20:26 PM5/8/19
to ai...@googlegroups.com
Thanks a lot,
Now it works properly.
Laszlo

--
You received this message because you are subscribed to the Google Groups "AIMMS - The Modeling System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aimms/48741411-0b58-4d70-87f5-c0b64b926950%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages