Skip to content
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

saveCSV does not work in certain cases of selected strategy #168

Open
agojunior opened this issue Nov 11, 2016 · 2 comments
Open

saveCSV does not work in certain cases of selected strategy #168

agojunior opened this issue Nov 11, 2016 · 2 comments
Assignees
Labels

Comments

@agojunior
Copy link
Collaborator

useful code:
basic test
saveCSV = function(unitTest)
MyModel = Model{
x = Choice{-100, -1, 0, 1, 2, 100},
finalTime = 1,
init = function(self)
self.timer = Timer{
Event{action = function()
self.value = x
end}
}
end
}

m = MultipleRuns{
     model = MyModel,
     parameters = {scenario = {x = 2}},
     repetition = 3,
 }

-- Saves MultipleRuns results:
m:saveCSV("myCSVFile", ";")

end,

multipleruns.lua
--- Save the results of MultipleRuns to a CSV file.
-- Each line represents the values in a different simulation.
-- The columns are each of the parameters passed to MultipleRuns
-- and the return values of all additional functions and parameters in the output table.
-- @arg name The name of the CSV file.
-- @arg separator The chosen separator to be used in the CSV file.
-- @Usage
-- import("calibration")
-- MyModel = Model{
-- x = Choice{-100, -1, 0, 1, 2, 100},
-- finalTime = 1,
-- init = function(self)
-- self.timer = Timer{
-- Event{action = function()
-- self.value = x
-- end}
-- }
-- end
-- }
--
-- m = MultipleRuns{
-- model = MyModel,
-- parameters = {scenario = {x = 2}},
-- repetition = 3,
-- }
--
-- -- Saves MultipleRuns results:
-- m:saveCSV("myCSVFile", ";")
saveCSV = function(self, name, separator)
mandatoryArgument(2, "string", separator)
mandatoryArgument(1, "string", name)
local CSVTable = {}

	forEachOrderedElement(self, function(idx, att, typ)
		if typ == "table" and idx ~= "parameters" then
			local counter = 0
			print(idx)
			print(type(att))
			forEachOrderedElement(att, function(_, att2, _)
				counter = counter + 1
				if CSVTable[counter] == nil then
					CSVTable[counter] = {}
				end

				CSVTable[counter][idx] = att2
			end)
		end
	end)
	print(vardump(CSVTable))
	local csvFile = File(name..".csv")
	csvFile:write(CSVTable, separator)
end

}

@agojunior agojunior added the bug label Nov 11, 2016
@agojunior agojunior self-assigned this Nov 11, 2016
@agojunior
Copy link
Collaborator Author

fix this and create a new error test

1 similar comment
@agojunior
Copy link
Collaborator Author

fix this and create a new error test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant