Source code for solcore.science_tracker

import inspect

bibliography = []
bibliography_id = []
science_tracking = []
track_science_references = False
track_each_reference_call = False


[docs]def hexID(obj): return "{}".format(id(obj))
[docs]def science_reference(short_purpose, reference): """Marker acting as a reference for the origin of specific information Acts as a marker in code where particular alogrithms/data/... originates. General execution of code silently passes these markers, but remembers how and where they were called. Which markers were passed in a particular program run can be recalled with print_references(). Arguments: short_purpose: Identify the thing being referenced (string) reference: The reference itself, in any sensible format. """ global bibliography, bibliography_id, science_tracking, track_science_references if not track_science_references: return stack = inspect.stack() frame, path, line, function, context, index = stack[1] del stack arguments = inspect.formatargvalues(*inspect.getargvalues(frame)) availableObjects = {} availableObjects.update(frame.f_globals) availableObjects.update(frame.f_locals) del frame func_id = hexID(availableObjects[function]) identifier = "{} [{}]".format(function, func_id) call_record = "{}{}".format(function, arguments) add_anyway = False if identifier not in bibliography_id: bibliography_id.append(identifier) bibliography.append(reference) add_anyway = True if track_each_reference_call or add_anyway: science_tracking.append((call_record, short_purpose, bibliography_id.index(identifier) + 1))
[docs]def track_science(track_each_call=False): """configure science references -- determine whether or not each call separately or only the first for each reference.""" global track_science_references, track_each_reference_call track_science_references = True track_each_reference_call = track_each_call
if __name__ == "__main__": def myRandomFunctionA(): myRandomFunctionB(d=1) def myRandomFunctionB(d): a = 1 science_reference("doing something smart", "My Awesome Book, by me.") track_science() myRandomFunctionA() myRandomFunctionA() print_references()