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 have 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>Import Samples and Community Content.

  • Enter condit to narrow the list of options.

  • Select Feed simulation fields from the Extending StreamBase category.

  • Click Import Now.

StreamBase Studio creates a single project containing the sample files.

Running This Sample in StreamBase Studio

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

  1. In the Project Explorer view, open this sample's folder.

    Keep an eye on the bottom right status bar of the Studio window. Make sure any Updating, Downloading, Building, or Rebuild project messages finish before you proceed.

  2. Open the src/main/eventflow/packageName folder.

  3. Double-click to open the weather_stats.sbapp module. Make sure the module is the currently active tab in the EventFlow Editor.

  4. Click the Run button. This opens the SB Test/Debug perspective and starts the module.

  5. Wait for the Waiting for fragment to initialize message to clear.

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

  7. 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:

    Boston,January,0,30.4,29.0,32.0,10.1,21.7
    Denver,July,0,68.7,67.0,70.0,5.4,69.9
    Denver,January,0,25.4,24.0,27.0,17.4,12.3
    Albuquerque,January,0,16.3,15.0,17.0,3.4,14.1
    Minneapolis,January,0,15.1,14.0,17.0,20.7,-2.4
    Atlanta,January,0,42.7,40.0,45.0,1.3,42.7
    Minneapolis,July,0,76.6,75.0,79.0,1.7,76.6
    Atlanta,July,0,76.7,75.0,78.0,1.9,76.7
    

    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.

  8. Click Pause or Stop to end the simulation.

  9. 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 module 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.

Important

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:

studio-workspace/sample_feedsim-conditional

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