5 Replies Latest reply on Dec 4, 2015 7:52 AM by Shawn Wallwork

    JavaScript API question...

    Shawn Wallwork

      Hi folks,

       

      Before I finally sit down and learn JavaScript, I wanted to confirm that I can accomplish the following scenerio using the JavaScript API (or other API).

       

      On an unattended computer

       

      • Refresh an extract every 5 minutes, then
      • Check Gross Sales for each of 5 different teams
      • Determine if a team has exceeded a benchmark
      • If a team has exceeds a benchmark play a sound file
      • Also Flash the marks (racecar shapes) for the teams exceeding the benchmark

       

      As I said this is all time-based, there are no user actions involved.

       

      Assuming this can be done, if you have links to any code I can appropriate, I'd be very grateful!

       

      Thanks,

       

      --Shawn

        • 1. Re: JavaScript API question...
          Russell Christopher

          Hey Shawn -

           

          This is an interesting mix of requirements that you might be able to approximate, but will be fairly unnatural (and therefore more difficult). You'll also need to lean on multiple scripting technologies and APIs.

           

          So, first: You're using Tableau as a operational monitoring tool in near-real time: that's not what we do (Yada, yada, yada - you've heard me make this speech many times, so I won't bore you)....but the side effect is that your life is going to be more difficult.

           

          At the highest level, here's how you might approach each "thing". I'm going to assume you're thinking about doing this work with Server and NOT just Desktop (since you can't use any APIs against Desktop):

           

          Refresh Extract: A batch script which fires every x minutes via some sort of Windows Scheduler. You'll essentially execute tabcmd refreshextract

           

          Check Gross Sales: A real pain in the ***. You'll have to have JavaScript API which refreshes your viz every x minutes (not too hard, but this action won't be "synced" to happen right after the extract refresh happens). You'll then need need to use the API to select marks (tons of examples around on how to do this - just use the tutorial) and read the "value pairs" which represent each team....your code will then take the values and compare then against the benchmark

           

          Play a sound: Can't help you much here but I bet there are tons of JQuery Add-ins and HTML5 mechanisms that you could use to do this work...it would happen if a simple if (<mark value> >= benchmark ) type of statement.

           

          Flash Marks: Difficult. We don't flash. I can think of a couple ways to approach this, but it would be fuggly:

          • JS API code which executes every 2-5 seconds which changes a parameter in the viz which drives color of your marks (1=red, 2 = black). Just swap back and forth, back and forth....Will beat the **** out of your server and you'll see the "spinner" too, so it will be odd. Don't do this
          • Use a parameter to (one time only) change the SIZE or COLOR of the marks to make them stand out. Mike Kovner demonstrated this in the "You Did What" TC presentation with marks representing US states

           

          I understand that part of your goal is to learn JS and other dev-ish technology, but if this were MY problem to solve, I'd probably just use the new VizAlerts script which can do data driven alerts and "be done with it". Send the email to say "team X is below / above <some benchmark" and that's it...game set match

          1 of 1 people found this helpful
          • 2. Re: JavaScript API question...
            Jonathan Drummey

            Hi Shawn,

             

            Jive just ate my first response, let's try again, I've got a few ideas:

             

            1) If the view is relatively simple, don't use Tableau at all, instead:

             

            a) build a view or stored proc that you can connect to live (ideal) or a script does all the processing and dumps into a CSV

            b) use one of the JS data viz APIs (D3, plot.ly, etc.) to render the viz and then other JS code to make sounds, flash marks, etc.

             

            The concept here is the same as the "Don't try to make Tableau be Excel" mantra that you and I keep repeating. In this case it's "Don't try to make Tableau into a real-time flashing bleeping and blooping engine of celebration."

             

            2) Speaking of that, if at all possible if you have to use Tableau avoid the extract and use step 1a) above. The reason why is that every extra step in the process is another point of failure - what happens if the extract actually fails, or takes more than 5 minutes, refreshes but doesn't get updated data, etc.? Your code would need extra steps to handle that for the extract. One way to do this is by creating an extra worksheet that displays a value when the extract is successful in all respects and then a script using tabcmd that downloads that CSV and checks the values before proceeding with other steps.

             

            3) This alternative is based on seeing Jeffrey Shaffer and Allan Walker do ridiculous things with Javascript, not any particular knowledge of JS on my part. This does not need the Tableau JS API at all.

             

            a) Use step 1a above if possible. If you have to use an extract, use the ideas above in step 2 to validate.

            b) Have Tableau render the worksheet using a batch script via tabcmd to dump a PNG.

            c) If Tableau is necessary for some of the computations, have Tableau render a CSV using tabcmd to dump the CSV that has the information necessary for the blinking & flashing. Otherwise have the code in step a) generate that info.

            d) Build JS code to display the PNG from step b) in a DIV container that has an overlaid DIV container that uses the information from step c) to do whatever flashing and beeping is necessary. This last step depends on the data & Tableau viz to be consistent enough that the JS-generated overlay would be placed in the right locations.

             

            Jonathan

            1 of 1 people found this helpful
            • 3. Re: JavaScript API question...
              allan.walker.0

              ***Shawn Wallwork's requirements***

               

              On an unattended computer

               

              • Refresh an extract every 5 minutes, then

               

              function() TDE API on a scheduled basis (however, 5 minutes? how big is the diff?) - basically a conditional CRON

               

              • Check Gross Sales for each of 5 different teams
              • Determine if a team has exceeded a benchmark

               

              function() recursive loop statement that applies conditional logic

               

              • If a team has exceeds a benchmark play a sound file

               

              function() IF THEN play media

               

              • Also Flash the marks (racecar shapes) for the teams exceeding the benchmark

               

              function() conditional loop parameter invert color

               

              As I said this is all time-based, there are no user actions involved.

               

              Assuming this can be done, if you have links to any code I can appropriate, I'd be very grateful!

               

              NYC Taxis

              1 of 1 people found this helpful
              • 4. Re: JavaScript API question...
                Shawn Wallwork

                Thanks guys, this is all great stuff! You've certainly got me going in the right direction. And reminded me of the "...yada, yada, yada..." and I especially liked the "Don't try to make Tableau into a real-time flashing bleeping and blooping engine of celebration."

                 

                I'll pass these along to my client.

                 

                Cheers,

                 

                --Shawn

                • 5. Re: JavaScript API question...
                  Shawn Wallwork

                  Allan thanks for the reply. Once I get further into understanding what you're saying here, I'll email you with questions.

                   

                  Thanks again.

                   

                  Cheers,

                   

                  --Shawn