simulant-example
simulant-example copied to clipboard
Sample application for Simulant (https://github.com/Datomic/simulant)
Example Simulant Test
This module has a complete test harness built with Simulant. It simulates a shopper interacting with an ecommerce system. The parts are designed to be easy to learn.
You can interact with the simulation via a command-line interface or a REPL.
This depends on Datomic Free. With a minor change to project.clj, it will work with Datomic Pro as well.
Everything interesting is under the simtest directory. You should cd
into it right away.
One-time Setup
Before we can get started, we need to set up some fake item and category data. In a real implementation, you would get this from the system under test. For our purposes, a big pile of fake data will suffice.
- Generate seed data
lein run -m create-data
Walkthrough
- Start Datomic with
scripts/start-transactor.sh - Install the schema
lein run install-schema - Make a model
lein run make-model - Make a different model
lein run make-model -m "Another model" - See the models
lein run list-models - View the model's parameters
lein run list-model-parameters - Reduce the abandon rate
lein run set-model-parameter abandon-rate 8 - View the new parameters
lein run list-model-parameters - Make an activity stream
lein run make-activity - View the activity stream
lein run list-activities
Introducing the Parts
Basic schema
Some one-time setup is needed. simtest.database has a simple
migrations framework to install the schema. The schema definitions are
in resources/simulant/schema.edn and resources/simtest.edn
The Model
The model is expressed in simtest.model. There are three parts to the
model itself:
- State transitions, represented as
shopper-transitions. This function returns a sparse Markov matrix that we use to create a random walk through the commerce system. - Control parameters that adjust various probabilities. These are read from a model entity in the database. They change the Markov transition probabilities. They also affect how heavily traffic will focus on "hot" items and categories.
- Category and item data. In a full system, this would either be extracted from the target system or pushed into it at simulation start. We've got a data generator that spoofs up a pile of identifiers. You should have run this as part of the one-time setup. If not, please go back and do that now.
Generator
The generator is cleverly named simtest.generator. It divides
roughly into three sections.
- Creating an activity stream for a single agent, based on the model.
- Building a population of agents and their activity streams.
- The command line interface functions and their helpers.
Execution/Capture
Not implemented yet.
Validation
Not implemented yet.
License
Copyright © 2014-2015 Cognitect, Inc.
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.