Skip to content

Commit

Permalink
Merge pull request #21 from nhi-vanye/bhio-2
Browse files Browse the repository at this point in the history
Add support for modelling resource supply and consumption
  • Loading branch information
nhi-vanye authored Nov 21, 2023
2 parents 938f6a9 + 2273e7c commit 3bec3c5
Show file tree
Hide file tree
Showing 45 changed files with 4,360 additions and 432 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# R packages
packrat/*

# any local sqlite files
# any local sqlite or log files in topdir
# there are db files in sims/
*.db
*.sql*
data/*
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
dist
build

# logs
/*.log

# richards editor files
*~
Expand Down
19 changes: 12 additions & 7 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
This CITATION.cff file was generated with cffinit.
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: 'Censere: A numerical simulator of human settlement of Mars'
title: >-
Censere - a Framework for Numerically Simulating the Human
Settlement of Mars
message: >-
If you use this software, please cite it using the
metadata from this file.
Expand All @@ -15,11 +17,14 @@ authors:
affiliation: Badon Hill Technologies
repository-code: 'https://github.com/badonhill-io/mars-censere'
abstract: >
Application for the numerical simulation of human
settlement of Mars. The simulation works at the (named)
individual level to allow following of families over
multiple generations.
Application framework for the numerical simulation of
human settlement of Mars. The simulation works at the
(named) individual level to allow following of individual
families over multiple generations. This is a framework
in that the mission parameters are not annointed and
are typically randomised with given ranges.
keywords:
- numerical simulation
- Human settlement of Mars
- numerical simulation
- Python
license: BSD-4-Clause
58 changes: 58 additions & 0 deletions censere/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
#
# Copyright (c) 2023 Richard Offer, All rights reserved.
import os.path
import traceback
import logging

BORING_FILES = [
"peewee.py",
"core.py", # click/core.py
"__init__.py" # this file and other boring ones
]

class AddStackFilter(logging.Filter):
def __init__(self, levels=None):
self.levels = levels or set()

def get_stack(self):
# Iterator over file names
frames = traceback.walk_stack(None)

interesting=[]

# Walk up the frames
for frame, lineno in frames:
#if os.path.basename(frame.f_code.co_filename) not in BORING_FILES:
if "site-packages" in frame.f_code.co_filename:
pass
# interesting.append( f" ..." )
elif "logging/__init__.py" in frame.f_code.co_filename:
pass
# interesting.append( f" ..." )
else:
interesting.append( f" {os.path.relpath(frame.f_code.co_filename)}:{frame.f_lineno}" )

interesting.insert(0, 'Called from :')
interesting.append("")

return "\n".join(interesting)

def filter(self, record):
if record.levelno in self.levels:
sinfo = self.get_stack()
if sinfo is not None:
record.stack_info = sinfo

return True

LOGGING = {
"version": 1,
Expand All @@ -18,6 +62,10 @@
"format": "%(asctime)s.%(msecs)03d %(levelname)-6s %(name)14s | %(message)s",
"datefmt": "%H:%M:%S",
},
"peewee": {
"format": "%(asctime)s.%(msecs)03d %(name)14s | %(message)s\n%(stack_info)s",
"datefmt": "%H:%M:%S",
},
},
"handlers": {
"cli": {
Expand All @@ -35,6 +83,11 @@
"formatter": "trace",
"stream" : "ext://sys.stdout"
},
"peewee": {
"class": "logging.StreamHandler",
"formatter": "peewee",
"stream" : "ext://sys.stdout"
},
},
"loggers": {
"": {
Expand Down Expand Up @@ -90,6 +143,11 @@
"level": "INFO",
"handlers": [ "trace" ],
'propagate': False,
},
"peewee": {
"level": "INFO",
"handlers": [ "peewee" ],
'propagate': False,
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions censere/actions/families.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def make(*args ):
relationship_ends = thisApp.solday + relationship_length

EVENTS.register_callback(
when= relationship_ends,
runon= relationship_ends,
callback_func=CALLBACKS.end_relationship,
kwargs= { "relationship_id" : r.relationship_id, "simulation": thisApp.simulation }
)
Expand Down Expand Up @@ -185,7 +185,7 @@ def make(*args ):

# register a function to be called at `when`
EVENTS.register_callback(
when= birth_day,
runon= birth_day,
callback_func=CALLBACKS.settler_born,
kwargs= {
"biological_mother" : mother,
Expand Down
8 changes: 4 additions & 4 deletions censere/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_command(self, ctx, name):
type=int,
help="Set system-wide verbosity")
@click.option(
'--debug',
'--debug/--no-debug',
default=False,
is_flag=True,
help="Run in development mode (additional logging)")
Expand All @@ -73,7 +73,7 @@ def get_command(self, ctx, name):
is_flag=True,
help="Dump the simulation parameters to stdout and exit (CENSERE_DUMP)")
@click.option(
'--debug-sql',
'--debug-sql/--no-debug-sql',
default=False,
is_flag=True,
help="Enable debug mode for SQL queries (CENSERE_DEBUG_SQL)")
Expand Down Expand Up @@ -110,7 +110,7 @@ def cli(ctx, verbose, debug, log_level, database, dump, debug_sql):
""")

logging.addLevelName(thisApp.NOTICE, "NOTICE")
logging.addLevelName(thisApp.DETAILS, "DETAIL")
logging.addLevelName(thisApp.DETAIL, "DETAIL")
logging.addLevelName(thisApp.TRACE, "TRACE")

logging.config.dictConfig( censere.LOGGING )
Expand All @@ -123,7 +123,7 @@ def cli(ctx, verbose, debug, log_level, database, dump, debug_sql):
logging.getLogger("d.trace").setLevel("ERROR")

for kv in log_level:
s = kv.split("=")
s = kv.split(":")
logging.getLogger( s[0] ).setLevel( s[1] )


Expand Down
Loading

0 comments on commit 3bec3c5

Please sign in to comment.