How can I control how Jasper Reports combines data for a single value in a time series? - jasper-reports

I have a time series and I'd like to:
a) Know how Jasper Reports (or JFreeChart) will combine my data for a single point on the chart by default
and
b) Be able to change how that combination is performed
For instance, let's say that I have samples of data once per second, and my time series is configured for "minute". That means that I have 60 pieces of real data for each single value shown on the chart. I'd like to be able to control how that mapping is done (e.g. average, maximum, etc.).
I looked around for documentation on how to see the default or modify how the plot works, but I wasn't able to find anything. Perhaps my search terms (chart, time series, etc.) were too generic.

Related

Modeler question: Is there a function in SPSS for multiple 'if' statements? Forecasting dates

I am trying to build a forecast for interest expense for floating debt in my company.
I have been given a set of ResetDates which help me match a given rate based on when the ResetDate is.
I have been successful in forecasting one period, but I need a much longer set of periods to satisfy my requirements.
I've tried derive nodes and nested if statements as well as filler nodes.
I am given this data to work with, I can only look at one ResetDate ahead.
Here you will find the data I used: Columns A/B/C/D is what i'm given, Column E (or 5th column from left to right) is what I want to derive as my output
I want to use 'InterestPayDate' and derive:
if it's more than 'NextReset' , the add 90 days to the 'NextReset' to create 'NextReset2'
That is as far as I can get.... where my problem lies is I want to look at NextReset2 and derive:
if 'InterestPayDate' is more than 'NextReset2', then add 90 days to 'NextReset2', if it's less than 'NextReset2', keep the current value for 'NextReset2'
Output should look like Column E here
Not sure if I need to dig deeper into the logical functions, in all honesty, I've just picked up SPSS and I am really trying to learn. Hopefully, you can point me in the right direction.
Thank you.
After computing the first NextReset2, you need to use a Filler node like the one below to change the value of the field.
You might need more than one identical nodes like this - one for each potential 90-day period that you are looking to extend the NextReset2 date. In your sample data, you will need at least two Filler nodes to get the correct value of NextReset2 for the last of the records.
There might be a more elegant way to do it, but this will work and it's easy enough to make copies of a node and string them together like this.
Please also see a sample IBM SPSS Modeler stream showing this approach here and using your sample data.

How to pass a vector from tableau to R

I have a need to pass a vector of arguments to Rserve from tableau. Specifically, I am using IRR calculations in R (on Rserve), and i want to pass vector of cash-flows that are as columns in my table (instead of rows/measure). So, i want to collect all those CF in a vector and pass it on to Rserve. Passing them one at a time slows down IO.
SCRIPT_REAL("r_func(c(.arg1, .arg2, .arg3))",sum(cf1), sum(cf2), sum(cf3))
cf1..cfn are cashflows corresponding to various periods. Above code works well when cf are few but takes a long time when i have few hundereds. Further, time spent is not in calculation but IO when communicating with remote Rserve. If i have a local Rserve, this calculation happens under few seconds while on remote, it takes well over a minute.
Also, want to point out that tableau / Rserve, set one argument after another and that takes time. My expectation is that once i have a vector, it would be just 1 transfer and setting of arguments, and therefore this should speed up
The first step in understanding how Tableau interacts with R or Python, is understanding how Tableau's table calcs work.
Tableau Script_XXX() functions are table calculations which means that you invoke them on a vector of aggregate query results and the corresponding R or Python code needs to return a vector usually of the same size. (I think you may be able to return a scalar or smaller vector which gets replicated to appear like a vector of the same size as the argument -- but not certain)
You can control how your data is partitioned into vectors, and also the ordering of data in the vectors, by editing the table calc to specify the partitioning and addressing for that calc.
Partitioning determines how your aggregate query results are broken up into vectors for calculation purposes. Addressing determines how the elements of each vector are ordered. You can either do that based on the physical layout of the table structure, or (better) based on the specific dimensions.
See the Tableau on-line help for table calcs for more info, and look online training videos from Tableau or blog entries (especially from anyone named Bora)
One way to test your understanding of these concepts is create a Tableau table (i.e., a viz with a mark type of text) with several dimensions on row and column shelves. Then create calculated fields for INDEX() and SIZE() and display them on text. Finally, change the partitioning and addressing in different ways by editing those table calcs. Try several different permutations. When you can confidently predict what those functions will produce for different settings, then you're ready to do more complex tasks - such as talking to R.
It is also instructive to experiment with FIRST(), LAST(), LOOKUP(), WINDOW_SUM() etc -- and finally dig into PREVIOUS_VALUE(). Warning, PREVIOUS_VALUE() is a bit odd, and does not behave the way you probably assume it does. Still, it is a useful technique that can implement a recursive calculation, and is about as close to a for loop as Tableau gets.

How do I save forecasted values to use in calculations in Tableau?

I have a report that uses a couple years of historical data and uses the Tableau forecasting to show expected values for the next three months. I would like to be able to save these values for a few reasons.
I need to do calculations on the forecasted values. Multiple different people will be using this forecast and will need different calculations. Some will need to calculate 70% of the forecasted value, and some will need to calculate different percentages. I'd like to have a parameter for them to enter the percent and be able to create a calculation using the parameter and the forecasted value.
I would like to be able to save forecasted values to later show the difference between what was forecasted and what actually happened. I understand you can export your data from your forecast and import that as another data source to show actuals vs forecast, but I need to do it all automatically with no manual intervention.
Is this possible? I haven't found any way to save the values or do calculations on the values that are forecasted. I am using Tableau 10.5
Tableau will never save data. Probably easiest to create the forecast values in the datasource and then report. It's very simple to have "actual" values and "forecast" values so you can compare

How to calculate and total length of time with only timestamps?

I am working with Crystal Reports 2016. I have some datetime values that represent when something changes. I have a numeric value of what changes at the datetime value. In this case, some network connections are changing states between 3 values (0, 1, 2). I'd like to calculate the periods, and totals of the periods; then chart the ratio of the periods to each other, and the time of the report. I've gotten some of this done, but I think I took the wrong approach, because the last bit isn't working.
I have formulas for Online, Offline, and Partially Online, (respectively) like so:
If {CRV_AttributeLog.AnalogValue}=2
Then {CRV_AttributeLog.LogTimeStamp}
If {CRV_AttributeLog.AnalogValue}=0
Then {CRV_AttributeLog.LogTimeStamp}
If {CRV_AttributeLog.AnalogValue}=1
Then {CRV_AttributeLog.LogTimeStamp}
I have formulas to calculate the periods between the states:
Online
abs(dateDiff("s", next({#TimeStampPartiallyOnline}), {#TimeStampOffline})) +
abs(dateDiff("s", next({#TimeStampPartiallyOnline}), {#TimeStampOnline}))
Offline
abs(dateDiff("s", next({#TimeStampOffline}), {#TimeStampOnline})) +
abs(dateDiff("s", next({#TimeStampOffline}), {#TimeStampPartiallyOnline}))
Partially Online
abs(dateDiff("s", next({#TimeStampPartiallyOnline}), {#TimeStampOffline})) +
abs(dateDiff("s", next({#TimeStampPartiallyOnline}), {#TimeStampOnline}))
I cannot make a summary of the formulas that calculate the period, presumably because I have the first set of formulas that are effectively variables; Crystal Reports does not like the nesting of formulas. I can't just copypasta replace the formula name with the if ... then expression; that gives me an error when I check it for errors (a field must be here). I thought about having the if statement up front and only doing operations if it was an offline record, but then I can't reference the other timestamps.
I can put the time periods into a chart, and that will add them up. However, the calculated time is not representative of all the time for the period the report is executed, so, while the ratios are still mostly good, due to idiosyncrasies of the data, the resulting chart is not 100% correct. For edge cases, I am not able to calculate a total of how long the connection is offline. For example, if a connection was offline for the entire length of the report, there will be many time stamps that it is offline, but because there are no time stamps where it is online, the offline period is 0, throwing off the chart.
How can I calculate these periods and then compare them to the length of time of the report? I have already created a formula that gives me the length of time in the report (the divisor aka numerator), but I need the dividend (denominator) for my calculation.
Is there a better way to approach this problem?
Crystal Reports calculations that use the Next() function have to wait until after all of the sorting, grouping and totaling are done. They work, but they strictly limit what you can do with the results in Crystal. The best approach is to write the SQL query so that each record is linked to the next record. That way the dataset that Crystal sees includes both the beginning of the period and the end of the period in the same record. How you write that SQL would be a good separate question.
For edge cases when there is no value, I think you would want to use IF-THEN logic to replace the missing value with either the beginning of the target period or the end of the target period.

Combining several data series to the same value in Grafana

I'm looking for a function in Grafana which looks like it should be trivial, but until now I haven't been able to find out how, if at all, it is possible to do.
With the recent templating options, I can easily create my dashboard once, and quickly change the displayed data to look at different subsets of my data, and that's great.
What I'm looking for is a way to combine this functionality to create interactive graphs that show aggregations on different subsets of my data.
E.g., the relevant measurement for me is a "clicks per views" measurement.
For each point in the series, I can calculate this ratio for each state (or node) in code before sending it to the graphite layer, and this is what I've been doing until now.
My problem starts where I want to combine several states together, interactively: I could use the "*" in one of the nodes, and use an aggregate function like "avg" or "sum" to collect the different values covered in the sub-nodes together.
Problem is, I can't just use an average of averages - as the numbers may be calculated on very different sample sizes,the results will be highly inaccurate.
Instead, I'd like to send to the graphite the "raw data" - number of clicks and number of views per state for each point in the series, and have grafana calculate something like "per specified states, aggregate number of clicks AND DIVIDE BY aggregate number of views".
Is there a was to do this? as far as I can tell, the asPercent function doesn't seem to do the trick.
You can use a query like this in edit mode:
SELECT (aggregate_function1(number_of_clicks)/aggregate_function2(number_of_views)) as result
FROM measurement_name
WHERE $timeFilter
GROUP BY time($_interval), state.