Skip to content

Commit

Permalink
added imports to init file of elecsim
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkell committed Mar 1, 2019
1 parent 5a0624b commit dfae22b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 40 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,42 @@ venv.bak/

elecsim/Data/smart_meter.csv
.Rproj.user


# .gitignore for vscode

.DS_Store
.huskyrc.json
out
node_modules
*.pyc
*.vsix
**/.vscode/.ropeproject/**
**/testFiles/**/.cache/**
*.noseids
.nyc_output
.vscode-test
__pycache__
npm-debug.log
**/.mypy_cache/**
!yarn.lock
coverage/
.vscode-test/**
**/.venv*/
precommit.hook
pythonFiles/experimental/ptvsd/**
pythonFiles/lib/**
debug_coverage*/**
languageServer/**
languageServer.*/**
bin/**
obj/**
.pytest_cache
tmp/**
.python-version
.vs/





3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Users/b1017579/.pyenv/shims/python"
}
2 changes: 2 additions & 0 deletions elecsim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from elecsim.model.world import World
import elecsim.scenario.scenario_data
80 changes: 40 additions & 40 deletions test/test_model/test_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,43 @@

logging.basicConfig(level=logging.WARNING)


def display_top(snapshot, key_type='lineno', limit=3):
snapshot = snapshot.filter_traces((
tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
tracemalloc.Filter(False, "<unknown>"),
))
top_stats = snapshot.statistics(key_type)

print("Top %s lines" % limit)
for index, stat in enumerate(top_stats[:limit], 1):
frame = stat.traceback[0]
# replace "/path/to/module/file.py" with "module/file.py"
filename = os.sep.join(frame.filename.split(os.sep)[-2:])
print("#%s: %s:%s: %.1f KiB"
% (index, filename, frame.lineno, stat.size / 1024))
line = linecache.getline(frame.filename, frame.lineno).strip()
if line:
print(' %s' % line)

other = top_stats[limit:]
if other:
size = sum(stat.size for stat in other)
print("%s other: %.1f KiB" % (len(other), size / 1024))
total = sum(stat.size for stat in top_stats)
print("Total allocated size: %.1f KiB" % (total / 1024))

class TestWorld:
def test_world_initialization(self):
# with PyCallGraph(output=GraphvizOutput()):
world = World(initialization_year=2018)
tracemalloc.start()

for i in range(10):
snapshot = tracemalloc.take_snapshot()
display_top(snapshot)

world.step()

# data = world.datacollector.get_model_vars_dataframe()
# logger.info("final data: \n {}".format(data))
#
# def display_top(snapshot, key_type='lineno', limit=3):
# snapshot = snapshot.filter_traces((
# tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
# tracemalloc.Filter(False, "<unknown>"),
# ))
# top_stats = snapshot.statistics(key_type)
#
# print("Top %s lines" % limit)
# for index, stat in enumerate(top_stats[:limit], 1):
# frame = stat.traceback[0]
# # replace "/path/to/module/file.py" with "module/file.py"
# filename = os.sep.join(frame.filename.split(os.sep)[-2:])
# print("#%s: %s:%s: %.1f KiB"
# % (index, filename, frame.lineno, stat.size / 1024))
# line = linecache.getline(frame.filename, frame.lineno).strip()
# if line:
# print(' %s' % line)
#
# other = top_stats[limit:]
# if other:
# size = sum(stat.size for stat in other)
# print("%s other: %.1f KiB" % (len(other), size / 1024))
# total = sum(stat.size for stat in top_stats)
# print("Total allocated size: %.1f KiB" % (total / 1024))
#
# class TestWorld:
# def test_world_initialization(self):
# # with PyCallGraph(output=GraphvizOutput()):
# world = World(initialization_year=2018)
# tracemalloc.start()
#
# for i in range(10):
# snapshot = tracemalloc.take_snapshot()
# display_top(snapshot)
#
# world.step()
#
# # data = world.datacollector.get_model_vars_dataframe()
# # logger.info("final data: \n {}".format(data))

0 comments on commit dfae22b

Please sign in to comment.