Create analytics

Screenshot

Next requirement is dummy data that matches the created schema. To do this, use a real-time engine process (RTE) and a custom analytic. There is an art to creating realistic dummy data. The dummy data feed will publish data to the tickerplant on a timer. The first step is to create a custom analytic to generate and publish the dummy data. Then add the analytic to the timer of the RTE process in the initialStateFunct function.

Analytics are created in Kx Control.

Create a new analytic group: select File > New > Analytic Group. Enter dhtDummyData in the dialog box and click Add.

Screenshot

Save the analytic group without making any changes. It will appear in the tree.

Screenshot

Write some q code to create a dummy table. It will be easier to experiment with this if a connection is made to a running process, for example an RDB. The one created above would be best. In Kx Control right-click on a running RDB in the Process Library Status view and select Connect.

Screenshot

A new tab opens with an Analyst session connected to the RDB. If there is no Scratchpad open, Select Tools > Scratchpad to open a scratchpad to work in. Scratchpads can be used to develop q code interactively without having to create a function. Copy and paste the following code into the scratchpad:

maxrows: 10;
tradeN: rand maxrows;
quoteN: rand maxrows;
dummytrade:([]sym:n?`A`B`C`D`E;price:n?100f;size:n?1000;srctime:.z.p);
dummyquote:([]sym:n?`A`B`C`D`E;bid:n?100f;bsize:n?1000;ask:n?100f;asize:n?1000;srctime:.z.p);

Right-click on the first line and select Display from the context menu.

Screenshot

The Display command executes the line and displays the result of the operation in the console at the bottom of the screen.

Screenshot

Update the code to replace n? with tradeN? and quoteN?.

maxrows: 10;
tradeN: rand maxrows;
quoteN: rand maxrows;
dummytrade:([]sym:tradeN?`A`B`C`D`E;price:tradeN?100f;size:tradeN?1000;srctime:.z.p);
dummyquote:([]sym:quoteN?`A`B`C`D`E;bid:quoteN?100f;bsize:quoteN?1000;ask:quoteN?100f;asize:quoteN?1000;srctime:.z.p);

Highlight the first four lines and select Display from the context menu.

Screenshot

All four lines will execute and the result of the last line of execution will appear in the console. Data from the dummytrade table should be visible.

Screenshot

Once the code is working correctly, add a function to call it later. Switch back to Kx Control and select File > New > Analytic. Name the Analytic loadDummyData and click Add.

Screenshot

The analytic editor appears. Make the following changes:

  1. Add a description in the Analytic Details tab.
  2. In the Parameters tab add maxrows as a parameter with type integer and add a description.
  3. Copy and paste the scratchpad lines into the Contents tab.
  4. Remove the maxrows:10 line.
  5. Add the .dm.pub function. This function takes a table reference and the dummy data. It uses the internal pub-sub model to ensure the data reaches all the interested recipients.
  6. In the Groups tab add dhtDummyData.
{[maxrows]
    tradeN: rand maxrows;
    quoteN: rand maxrows;

    dummytrade:([]sym:tradeN?`A`B`C`D`E;price:tradeN?100f;size:tradeN?1000;srctime:.z.p);
    dummyquote:([]sym:quoteN?`A`B`C`D`E;bid:quoteN?100f;bsize:quoteN?1000;ask:quoteN?100f;asize:quoteN?1000;srctime:.z.p);

    .dm.pub[`dhtTrades; dummytrade];
    .dm.pub[`dhtQuotes; dummyquote];
    }

Screenshot

Screenshot

Screenshot

Screenshot

When finished, click Save in the top right of the editor.