Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam
Manage
Activity
Members
Labels
Plan
Issues
31
Issue boards
Milestones
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FINAM
finam
Commits
b285feed
Commit
b285feed
authored
2 years ago
by
Martin Lange
Browse files
Options
Downloads
Patches
Plain Diff
add tests for chapter on adapters
parent
a4ed3c8d
No related branches found
No related tags found
1 merge request
!127
Doc-tests
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/source/finam-book/development/adapters.rst
+56
-1
56 additions, 1 deletion
docs/source/finam-book/development/adapters.rst
docs/source/finam-book/development/components.rst
+1
-0
1 addition, 0 deletions
docs/source/finam-book/development/components.rst
with
57 additions
and
1 deletion
docs/source/finam-book/development/adapters.rst
+
56
−
1
View file @
b285feed
...
@@ -48,8 +48,34 @@ File ``src/scale.py``:
...
@@ -48,8 +48,34 @@ File ``src/scale.py``:
.. testcode:: scale-adapter
.. testcode:: scale-adapter
:hide:
:hide:
from datetime import datetime, timedelta
generator = fm.modules.CallbackGenerator(
{"Value": (lambda _t: 1.0, fm.Info(time=None, grid=fm.NoGrid()))},
start=datetime(2000, 1, 1),
step=timedelta(days=1),
)
consumer = fm.modules.DebugConsumer(
{"Input": fm.Info(None, grid=fm.NoGrid())},
start=datetime(2000, 1, 1),
step=timedelta(days=1),
)
adapter = Scale(0.5)
adapter = Scale(0.5)
comp = fm.Composition([generator, consumer])
comp.initialize()
generator.outputs["Value"] >> adapter >> consumer.inputs["Input"]
comp.run(datetime(2000, 1, 2))
print(fm.data.strip_data(consumer.data["Input"]))
.. testoutput:: scale-adapter
:hide:
0.5 dimensionless
In :meth:`.Adapter._get_data`, we:
In :meth:`.Adapter._get_data`, we:
1. Pull the input for the requested ``time``
1. Pull the input for the requested ``time``
...
@@ -171,7 +197,10 @@ In :meth:`.Adapter._get_data`, we can now do the interpolation whenever data is
...
@@ -171,7 +197,10 @@ In :meth:`.Adapter._get_data`, we can now do the interpolation whenever data is
def _get_data(self, time):
def _get_data(self, time):
if self.old_data is None:
if self.old_data is None:
return self.new_data[1]
if self.new_data is None:
return None
else:
return self.new_data[1]
dt = (time - self.old_data[0]) / (self.new_data[0] - self.old_data[0])
dt = (time - self.old_data[0]) / (self.new_data[0] - self.old_data[0])
...
@@ -183,8 +212,34 @@ In :meth:`.Adapter._get_data`, we can now do the interpolation whenever data is
...
@@ -183,8 +212,34 @@ In :meth:`.Adapter._get_data`, we can now do the interpolation whenever data is
.. testcode:: time-adapter
.. testcode:: time-adapter
:hide:
:hide:
from datetime import datetime, timedelta
generator = fm.modules.CallbackGenerator(
{"Value": (lambda t: t.day, fm.Info(time=None, grid=fm.NoGrid()))},
start=datetime(2000, 1, 1),
step=timedelta(days=30),
)
consumer = fm.modules.DebugConsumer(
{"Input": fm.Info(None, grid=fm.NoGrid())},
start=datetime(2000, 1, 1),
step=timedelta(days=1),
)
adapter = TimeInterpolation()
adapter = TimeInterpolation()
comp = fm.Composition([generator, consumer])
comp.initialize()
generator.outputs["Value"] >> adapter >> consumer.inputs["Input"]
comp.run(datetime(2000, 1, 15))
print(fm.data.strip_data(consumer.data["Input"]))
.. testoutput:: time-adapter
:hide:
14.0 dimensionless
In :meth:`.Adapter._get_data`, the following happens:
In :meth:`.Adapter._get_data`, the following happens:
1. If only one data entry was received so far, we can't interpolate and simply return the available data. Otherwise...
1. If only one data entry was received so far, we can't interpolate and simply return the available data. Otherwise...
...
...
This diff is collapsed.
Click to expand it.
docs/source/finam-book/development/components.rst
+
1
−
0
View file @
b285feed
...
@@ -416,5 +416,6 @@ Here is the final code of the completed component.
...
@@ -416,5 +416,6 @@ Here is the final code of the completed component.
TestDummy().test_dummy_model() #doctest: +ELLIPSIS
TestDummy().test_dummy_model() #doctest: +ELLIPSIS
.. testoutput::
.. testoutput::
:hide:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment