Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/TerraME/terrame
Browse files Browse the repository at this point in the history
  • Loading branch information
avancinirodrigo committed Jan 25, 2018
2 parents af260f0 + ec0243b commit 8a9f1d1
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 76 deletions.
5 changes: 4 additions & 1 deletion packages/base/lua/CellularSpace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1703,11 +1703,12 @@ function CellularSpace(data)

quantity = quantity + mcell[attribute]
end)

return quantity
end
end
elseif mtype == "boolean" then
if data[attribute] then
if data[attribute] then
customWarning("Attribute '"..attribute.."' will not be replaced by a summary function.")
return
end
Expand All @@ -1719,6 +1720,7 @@ function CellularSpace(data)
quantity = quantity + 1
end
end)

return quantity
end
elseif mtype == "string" or (mtype == "Random" and (value.distrib == "categorical" or (value.distrib == "discrete" and type(value[1]) == "string"))) then
Expand All @@ -1737,6 +1739,7 @@ function CellularSpace(data)
result[mvalue] = 1
end
end)

return result
end
end
Expand Down
30 changes: 16 additions & 14 deletions packages/base/lua/Profiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,20 @@ local createBlock = function(name)
running = false,
count = 0,
steps = 0,
total = 0,
uptime = function(self)
if self.running then
return os.time() - self.startTime
return self.total + os.time() - self.startTime
else
return self.endTime - self.startTime
return self.total
end
end,
report = function(self)
return { -- SKIP
name = self.name, -- SKIP
count = self.count, -- SKIP
time = timeToString(self:uptime()), -- SKIP
average = timeToString(self:uptime() / self.count) -- SKIP
average = timeToString(self:uptime() / math.max(1, self.count)) -- SKIP
} -- SKIP
end,
eta = function(self)
Expand All @@ -113,8 +114,13 @@ local createBlock = function(name)
self.running = true
end,
stop = function(self)
self.endTime = os.time()
self.running = false
if self.running then
self.endTime = os.time()
self.total = self.total + self.endTime - self.startTime
self.running = false
end

return self.endTime - self.startTime
end
}
end
Expand Down Expand Up @@ -184,7 +190,7 @@ Profiler_ = {

return block.count
end,
--- Return how much time was spent on the block.
--- Return how much time was spent on the block up to last stop.
-- It returns two representations: a string with a human-like representation of the time
-- and a number with the time in seconds.
-- @arg name A string with the block name. If the name is not informed, then it returns the uptime of the current block.
Expand All @@ -201,7 +207,7 @@ Profiler_ = {
local time = block:uptime()
return timeToString(time), time
end,
--- Stop to measure the time of a given block. It also returns how much time was spent with the block
--- Stop to measure the time of a given block. It also returns how much time was spent with the block since it was started.
-- in two representations: a string with a human-like representation of the time and a number with the time in seconds.
-- @arg name A string with the block name. If the name is not informed, then it stops and return the uptime of the current block.
-- @usage Profiler():start("block")
Expand All @@ -223,11 +229,7 @@ Profiler_ = {
customError(string.format("Block '%s' was not found.", name))
end

if block.running then
block:stop()
end

local time = block:uptime()
local time = block:stop()
return timeToString(time), time
end,
--- Clean the Profiler, removing all blocks and restarting its execution time.
Expand All @@ -247,8 +249,8 @@ Profiler_ = {
print(string.format("%-30s%-20d%-30s%s", report.name, report.count, report.time, report.average)) -- SKIP
end)

local _, total = self:uptime("main")
print("Total execution time: "..timeToString(total)) -- SKIP
local total = self:uptime("main")
print("Total execution time: "..total) -- SKIP
end,
--- Define how many times a given block will be executed.
-- @arg name A string with the block name.
Expand Down
21 changes: 0 additions & 21 deletions packages/base/lua/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,6 @@ function delay(delay_s)
while os.time() <= time_to do end
end

--- Convert the time in seconds to a more readable value. It returns a string in the format
-- "hours:minutes:seconds", or "days:hours:minutes:seconds" if the elapsed time is
-- more than one day.
-- @arg s A number.
-- @usage print(elapsedTime(100)) -- 00:01:40
function elapsedTime(s)
mandatoryArgument(1, "number", s)

local floor = math.floor
local seconds = s
local minutes = floor(s / 60); seconds = floor(seconds % 60)
local hours = floor(minutes / 60); minutes = floor(minutes % 60)
local days = floor(hours / 24); hours = floor(hours % 24)

if days > 0 then
return string.format("%02d:%02d:%02d:%02d", days, hours, minutes, seconds)
else
return string.format("%02d:%02d:%02d", hours, minutes, seconds)
end
end

--- Second order function to traverse a Society, Group, or Cell, applying a function to each of
-- its Agents. It returns true if no call to the function taken as argument returns false,
-- otherwise it returns false.
Expand Down
7 changes: 0 additions & 7 deletions packages/base/tests/functional/alternative/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ return{

unitTest:assertError(error_func, "You should provide the same number of differential equations and initial conditions.")
end,
elapsedTime = function(unitTest)
local error_func = function()
elapsedTime("2")
end

unitTest:assertError(error_func, incompatibleTypeMsg(1, "number", "2"))
end,
forEachAgent = function(unitTest)
local a = Agent{value = 2}
local soc = Society{instance = a, quantity = 10}
Expand Down
2 changes: 1 addition & 1 deletion packages/base/tests/functional/basics/Package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ return{
unitTest:assertType(cs, "CellularSpace")

-- The assert below checks the number of functions in package 'base'.
unitTest:assertEquals(getn(base), 181)
unitTest:assertEquals(getn(base), 180)
end,
import = function(unitTest)
forEachCell = nil
Expand Down
34 changes: 17 additions & 17 deletions packages/base/tests/functional/basics/Profiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,33 @@ return{
Profiler():start("test")
local _, startTime = Profiler():uptime()
delay(0.1)
local _, currentTime = Profiler():uptime()
unitTest:assert(startTime < currentTime)
delay(0.1)
Profiler():stop("test")
local _, stopTime = Profiler():uptime("test")
unitTest:assert(currentTime < stopTime)
Profiler():start("test")
delay(0.1)
local _, currentTime = Profiler():uptime()
unitTest:assert(startTime < currentTime)
local _, stopTime = Profiler():stop("test")
unitTest:assert(stopTime < currentTime)
_, currentTime = Profiler():uptime("test")
unitTest:assertEquals(currentTime, stopTime)

Profiler().blocks["test"].startTime = 0
Profiler().blocks["test"].endTime = 3600
delay(0.1)
local _, uptime = Profiler():uptime("test")
unitTest:assertEquals(currentTime, uptime)
Profiler().blocks["test"].total = 3600
timeString = Profiler():uptime("test")
unitTest:assertEquals(timeString, "1 hour")
Profiler().blocks["test"].endTime = 7250
Profiler().blocks["test"].total = 7250
timeString = Profiler():uptime("test")
unitTest:assertEquals(timeString, "2 hours")
Profiler().blocks["test"].endTime = 86401
Profiler().blocks["test"].total = 86401
timeString = Profiler():uptime("test")
unitTest:assertEquals(timeString, "1 day")
Profiler().blocks["test"].endTime = 86465321
Profiler().blocks["test"].total = 86465321
timeString = Profiler():uptime("test")
unitTest:assertEquals(timeString, "1000 days and 18 hours")
Profiler().blocks["test"].endTime = 60
Profiler().blocks["test"].total = 60
timeString = Profiler():uptime("test")
unitTest:assertEquals(timeString, "1 minute")
Profiler().blocks["test"].endTime = 125
Profiler().blocks["test"].total = 125
timeString = Profiler():uptime("test")
unitTest:assertEquals(timeString, "2 minutes and 5 seconds")
Profiler().stack = oldStack
Expand Down Expand Up @@ -190,14 +190,14 @@ return{
local oldBlocks = Profiler().blocks
Profiler().stack = {oldBlocks["main"]}
Profiler().blocks = {main = oldBlocks["main"]}
Profiler():steps("test", 1)
Profiler():steps("test", 10)
Profiler():start("test")
delay(0.1)
delay(0.9)
Profiler():stop("test")
local timeString, timeNumber = Profiler():eta("test")
unitTest:assertType(timeString, "string")
unitTest:assertType(timeNumber, "number")
unitTest:assertEquals(timeNumber, 0.1, 0.1)
unitTest:assertEquals(timeNumber, 10, 1)
Profiler().stack = oldStack
Profiler().blocks = oldBlocks
end
Expand Down
3 changes: 0 additions & 3 deletions packages/base/tests/functional/basics/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ return{

unitTest:assert(t2 - t1 >= .5)
end,
elapsedTime = function(unitTest)
unitTest:assertType(elapsedTime(50), "string")
end,
equals = function(unitTest)
unitTest:assert(equals(2, 2.00000001))
unitTest:assert(not equals(2, 2.1))
Expand Down
2 changes: 1 addition & 1 deletion repository/log/test-ca.log
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ All 17 tested functions exist in the source code of the package.
No tested function creates or updates any global variable.
No function prints any text on the screen.
No assertError() calls have error messages pointing to internal files.
No file was created along the tests.
No file or directory was created along the tests.
All 17 functions of the package were tested.
All lines from the source code were executed.
All 2 examples were successfully executed.
Expand Down
2 changes: 1 addition & 1 deletion repository/log/test-calibration.log
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ All 18 tested functions exist in the source code of the package.
No tested function creates or updates any global variable.
No function prints any text on the screen.
No assertError() calls have error messages pointing to internal files.
No file was created along the tests.
No file or directory was created along the tests.
All 9 functions of the package were tested.
All lines from the source code were executed.
All 12 examples were successfully executed.
Expand Down
2 changes: 1 addition & 1 deletion repository/log/test-gpm.log
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ All 9 tested functions exist in the source code of the package.
No tested function creates or updates any global variable.
No function prints any text on the screen.
No assertError() calls have error messages pointing to internal files.
No file was created along the tests.
No file or directory was created along the tests.
All 5 functions of the package were tested.
No lines from the source code were verified.
All 7 examples were successfully executed.
Expand Down
2 changes: 1 addition & 1 deletion repository/log/test-logo.log
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ All 12 tested functions exist in the source code of the package.
No tested function creates or updates any global variable.
No function prints any text on the screen.
No assertError() calls have error messages pointing to internal files.
No file was created along the tests.
No file or directory was created along the tests.
All 12 functions of the package were tested.
No lines from the source code were verified.
All 3 examples were successfully executed.
Expand Down
2 changes: 1 addition & 1 deletion repository/log/test-publish.log
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ All 33 tested functions exist in the source code of the package.
No tested function creates or updates any global variable.
No function prints any text on the screen.
No assertError() calls have error messages pointing to internal files.
No file was created along the tests.
No file or directory was created along the tests.
All 16 functions of the package were tested.
No lines from the source code were verified.
All 4 examples were successfully executed.
Expand Down
2 changes: 1 addition & 1 deletion repository/log/test-sci.log
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ All 2 tested functions exist in the source code of the package.
No tested function creates or updates any global variable.
No function prints any text on the screen.
No assertError() calls have error messages pointing to internal files.
No file was created along the tests.
No file or directory was created along the tests.
All 2 functions of the package were tested.
No lines from the source code were verified.
All 2 examples were successfully executed.
Expand Down
2 changes: 1 addition & 1 deletion repository/log/test-sysdyn.log
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ All 15 tested functions exist in the source code of the package.
No tested function creates or updates any global variable.
No function prints any text on the screen.
No assertError() calls have error messages pointing to internal files.
No file was created along the tests.
No file or directory was created along the tests.
All 15 functions of the package were tested.
All lines from the source code were executed.
All 7 examples were successfully executed.
Expand Down
8 changes: 4 additions & 4 deletions test/log/basic-profiler.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Block Count Time Average
main 1 3 seconds 3 seconds
tLoop 10 less than one second less than one second
main 1 4 seconds 4 seconds
tLoop 10 2 seconds less than one second
t1 1 2 seconds 2 seconds
t2 2 less than one second less than one second
Total execution time: 3 seconds
t2 2 1 second less than one second
Total execution time: 4 seconds
2 changes: 1 addition & 1 deletion test/scripts/profiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Profiler():stop("t1")
Profiler():stop("t2")
for _ = 1, 10 do
Profiler():start("tLoop")
sleep(0.1)
sleep(0.2)
Profiler():stop("tLoop")
end

Expand Down

0 comments on commit 8a9f1d1

Please sign in to comment.