Feed Simulation Conditional Field Sample

In most feed simulations, all values are independent. However, you can configure some fields to be dependent on other ones. This sample demonstrates how to create feed simulations that contain fields whose values are contingent on values in other fields. Such dependent fields are called conditional and can be of any data type.

For more information about creating Feed Simulations with conditional fields, including a discussion of this sample, see Conditional Field Generation.

Sample Overview

The StreamBase sample application weather_stats aggregates daily weather observations to produce weekly averages and extremes using Aggregate, Map, and Filter operators. Its input schema describes observations of temperature and wind speed for specific cities over time:

{City: string; Month: string; AvgTemp: double; Windspeed: double}

Values for the AvgTemp and Windspeed fields are computed conditionally. Both depend on the value of the City and Month fields, which are enumerated strings. The AvgTemp and Windspeed fields are conditionalized in order to provide city- and month-specific random walk parameters for them. Both fields thus has 10 cases specified for it.

The application creates weekly aggregates of these daily values by city and outputs them to a separate stream for each month (only January and July are simulated). It also uses input data to calculate a wind chill factor.

The application's Aggregate operator has a Tuple dimension that emits after it receives seven tuples, advances by seven, and groups values by city and by month. The feed simulation does not guarantee that all cities will generate the same number of tuples.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, select File>Load StreamBase Sample.

  • Select feedsim-conditional from the Extending StreamBase category.

  • Click OK.

StreamBase Studio creates a project for the sample in your current Studio workspace.

Running This Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. In the Project Explorer view, double-click to open the weather_stats.sbapp application.

  2. Make sure the application is the currently active tab in the EventFlow Editor, then click the Run button. This opens the SB Test/Debug perspective and starts the module.

  3. In the Feed Simulations tab, select daily_weather_stats.sbfs and click Run.

  4. In the Output Streams view, select All Output Streams and view the data emitted by the StreamBase application, the beginning of which should be similar to the following tuples:


    The two output streams (JanWeeklyWeather and JulWeeklyWeather) are displayed combined above. Each receives data for a particular month from the Filter operator. The schema for this output is:

    CityName: string; MonthName: string; StartDay: int; WeekAvgT: double; WeekMinT: double;
    WeekMaxT: double; WindAvg: double; WindchillAvg: double

    A third output stream, OtherWeather, would collect output for other months but is unused in the simulation. Edit the feed simulation to generate data for a third month as an exercise if you want to practice setting up conditional simulations.

    The feed simulation is set up to issue 350 tuples, sufficient to produce a month of observations for each city. However, as it chooses cities and months at random, some cities will have less than 31 observations per month and some will have more. The generator emits ten tuples per second. You can speed up or slow down that rate using the slider in the Feed Simulation view.

  5. Click Pause or Stop to end the simulation.

  6. When done, press F9 or click the Terminate EventFlow Fragment button.

This Sample's Files

This sample includes the following files:

File Description
weather_stats.sbapp An EventFlow application that aggregates daily weather data into weekly averages and extremes.
daily_weather_stats.sbfs A custom feed simulation file that generates five data fields: two strings, one int (conditional), and two doubles (both conditional).

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.


Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:


See Default Installation Directories for the default location of studio-workspace on your system.