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.

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

Running This Sample in StreamBase Studio

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

  1. In the Package Explorer, 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 application.

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

  4. In the Application Output 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.

  5. Click Pause or Stop to end the simulation.

  6. When done, press F9 or click the Stop Running Application button.

Running This Sample in Terminal Windows

Follow these steps to run this sample in terminal windows.

This section describes how to run this sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to your workspace copy of the sample.

  2. In window 1, start StreamBase Server running the sample application.

    sbd weather_stats.sbapp

  3. In window 2, type:

    sbc dequeue

    This window is to display tuples dequeued from the application's output ports.

  4. In window 3, type:

    sbfeedsim daily_weather_stats.sbfs

    The feed simulation tuples display in this window. Look for output tuples in window 2 like those described in step 5 of the previous section.

  5. In window 2, type Ctrl+C to terminate the dequeuer. Then type the following command to shut down the server:

    sbadmin shutdown

Back to top^

Importing This Sample into StreamBase Studio

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

  • From the top menu, select FileLoad 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.

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.

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/feedsim-conditional

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