stacked bar chart with time series and lines chart as the second axis - charts

I am working with time series data in csv file and I want to have stacked bar chart by time series.
my data looks like this:
|Year |Major | Moderate | Sample depth
|1900 | 12 | 32 | 5
|1901 | 16 | 25 | 6
|1903 | 18 | 12 | 10
|1908 | 20 | 25 | 21
|1910 | 15 | 32 | 22
|1911 | 26 | 24 | 22
|1913 | 22 | 22 | 25
|1918 |20 | 35 | 27
......
I want to have values of Major and Moderate in stacked bar chart and want to add the sample depth to the second axis.
Can anyone provide me with scripts. I am very much appreciated.

Related

Reformatting table in SQL

I have a table in sql
Table Link
is there a way to reformat this table with contract_kind as rows and percentile values as columns without me having to create 4 tables with where clauses and joining them. Using Postgres.
TLDR: just use the crosstab function as per documentation
Long reply:
I recreated a similar case with
create table test (id int, contract_kind text, percentile int, cut_off_time float);
insert into test values
(1,'TEMPLATE',25,1.91),
(2,'TEMPLATE',50,51.93),
(3,'TEMPLATE',75,158.41),
(4,'TEMPLATE',90,343.01),
(5,'TEMPLATE_EDITABLE',25,26),
(6,'TEMPLATE_EDITABLE',50,27),
(7,'TEMPLATE_EDITABLE',75,28),
(8,'TEMPLATE_EDITABLE',90,29),
(9,'UPLOAD_EDITABLE',25,10),
(10,'UPLOAD_EDITABLE',50,20),
(11,'UPLOAD_EDITABLE',75,30),
(12,'UPLOAD_EDITABLE',90,40),
(13,'UPLOAD_SIGN',25,40),
(14,'UPLOAD_SIGN',50,77),
(15,'UPLOAD_SIGN',75,99),
(16,'UPLOAD_SIGN',90,133);
result:
id | contract_kind | percentile | cut_off_time
----+-------------------+------------+--------------
1 | TEMPLATE | 25 | 1.91
2 | TEMPLATE | 50 | 51.93
3 | TEMPLATE | 75 | 158.41
4 | TEMPLATE | 90 | 343.01
5 | TEMPLATE_EDITABLE | 25 | 26
6 | TEMPLATE_EDITABLE | 50 | 27
7 | TEMPLATE_EDITABLE | 75 | 28
8 | TEMPLATE_EDITABLE | 90 | 29
9 | UPLOAD_EDITABLE | 25 | 10
10 | UPLOAD_EDITABLE | 50 | 20
11 | UPLOAD_EDITABLE | 75 | 30
12 | UPLOAD_EDITABLE | 90 | 40
13 | UPLOAD_SIGN | 25 | 40
14 | UPLOAD_SIGN | 50 | 77
15 | UPLOAD_SIGN | 75 | 99
16 | UPLOAD_SIGN | 90 | 133
(16 rows)
Now to use the crosstab you need to create the tablefunc extension.
create extension tablefunc;
and then you can use it to pivot the data
select * from
crosstab('select percentile, contract_kind, cut_off_time from test order by 1,2')
as ct(percentile int, template float, template_editable float, upload_editable float, upload_sing float);
result
percentile | template | template_editable | upload_editable | upload_sing
------------+----------+-------------------+-----------------+-------------
25 | 1.91 | 26 | 10 | 40
50 | 51.93 | 27 | 20 | 77
75 | 158.41 | 28 | 30 | 99
90 | 343.01 | 29 | 40 | 133
(4 rows)

create line plot from table in tableau

I've got data that look similar to this
+------------+--------------+---------+---------+---------+---------+
| funding_id | amountOnHand | rate_1d | rate_1w | rate_1m | rate_1y |
+------------+--------------+---------+---------+---------+---------+
| USDOIS | 100 | 18 | 9 | 12 | 2 |
| USDOIS | 106 | 3 | 6 | 16 | 2 |
| USDOIS | 103 | 1 | 7 | 5 | 15 |
| USDOIS | 108 | 1 | 11 | 11 | 13 |
| JPYOIS | 100 | 0 | 19 | 16 | 15 |
| JPYOIS | 106 | 9 | 10 | 10 | 5 |
| JPYOIS | 103 | 4 | 9 | 11 | 6 |
| JPYOIS | 109 | 9 | 18 | 14 | 2 |
| EUROIS | 104 | 3 | 6 | 19 | 6 |
| EUROIS | 103 | 3 | 11 | 19 | 3 |
| EUROIS | 104 | 9 | 1 | 8 | 15 |
| EUROIS | 107 | 18 | 4 | 1 | 5 |
+------------+--------------+---------+---------+---------+---------+
I create weighted rates per funding id using the aggreation: SUM([rate_1d]*[initial])/SUM([initial])
And then use tableau to create a text table and get something similar to the following table (note that sometimes an entire row is null. that's ok)
+------------+------------------+------------------+------------------+------------------+
| funding_id | weighted_rate_1d | weighted_rate_1w | weighted_rate_1m | weighted_rate_1y |
+------------+------------------+------------------+------------------+------------------+
| AUDOIS | 3.0 | 8.0 | 6.0 | 3.0 |
| CADOIS | 20.0 | 3.0 | 17.0 | 0.0 |
| EUROIS | 9.0 | 0.0 | 19.0 | 7.0 |
| GBP CORP | | | | |
| GBPOIS | 12.0 | 19.0 | 14.0 | 16.0 |
| JPYOIS | 10.0 | 7.0 | 18.0 | 3.0 |
| USDOIS | 19.0 | 7.0 | 5.0 | 7.0 |
+------------+------------------+------------------+------------------+------------------+
What I'd like to do is create a line plot showing time on the x axis (so 1d/1w/1m/1y) and rate on the y axis, with each line colored by funding_id
Is there any way to do this?
Go to data source pane -> Select the measures weighted rate 1d, 1w, 1m etc..,
-> Then right click and select pivot this would convert column data to row data i.e.., pivot field names and pivot field values
-> Go back to your worksheet and drag the pivot field names to columns shelf and pivot field values to rows shelf, within the marks card change the chart type option from automatic to line chart and you're done.
Add more aesthetics to your chart as per your requirement.
Hope this helps.!
The solution is to use the "measure name" and "measure value" fields at the bottom of the "dimensions" and "measures" panels in the data selection area (no need to create a table at all)
so the steps are:
1) create 4 aggregations (weighted_rate_1d, etc)
2) create a new worksheet
3) drag Measure Names (found under Dimensions) to the Columns shelf
4) right click it, and filter out everything except the aggregations
5) drag "Measure Values" to the rows shelf
6) in the "marks" area just to the left of the plot (where you can change color, shape, etc) use the drop down menu to change the bar plot to a line plot
7) just below this, you'll see the measure values listed in green boxes- drag them around to reorder to it goes 1d, 1w, 1m, 1y (by default, 1w and 1m are switched because they're in alphabetic order)
8) drag funding_id to the color panel

Dynamic groups in Postgresql data

I have a PostgreSQL 9.1 database with a table containing measurement data, which contains setpoint information. For example temperature setpoints. The measurements are taken when at a setpoint, after which the following setpoint will be set. A setpoint can be reached multiple times, e.g. -25, 25, 75, 125, 75, 25 degree Celcius. In this case 25 and 75 degree Celcius are reached multiple times.
Now I want to group the data per setpoint, but not group data together of another setpoint that has the same value but is reached at a later point in time.
Example data:
| id | setpoint | value |<dyn.group>|
| 1 | -25 | 5.324 | 1
| 2 | -25 | 6.343 | 1
| 3 | -25 | 6.432 | 1
| 4 | 25 | 3.432 | 2
| 5 | 25 | 4.472 | 2
| 6 | 25 | 6.221 | 2
| 7 | 75 | 5.142 | 3
| 8 | 75 | 7.922 | 3
| 9 | 75 | 3.832 | 3
|10 | 125 | 8.882 | 4
|11 | 125 | 9.742 | 4
|12 | 125 | 7.632 | 4
|13 | 75 | 5.542 | 5
|14 | 75 | 2.452 | 5
|15 | 75 | 1.332 | 5
|16 | 25 | 3.232 | 6
|17 | 25 | 4.132 | 6
|18 | 25 | 5.432 | 6
Normal group by clauses will fail, because setpoint can be there multiple times, but should not be put together.
Looking with LEAD and LAG to the previous/next values is also not desired, because changes will most likely be similar (e.g. if setpoint 75 is repeated, then most likely the step from 25->75 will also be repeated).
The expected outcome is the 4th column (<dyn.group>). With that column I can for example average on these groups.
It can be done with a custom aggregation function to generate the "group index" value and then a "group by" clause in that value.

Slony replication stopped working

I inherited a 5 node postgres cluster running postgres 8.4 and slony 1.2.21. We are in the process of migrating the application to all new code and have not wanted to do very little maintenance on the cluster. Yesterday we decided to take down two nodes out of the cluster which were not being used. We used the slonik script to DROP NODE for the two nodes in the cluster. This seemed to work correctly and we shut down the nodes today. However I noticed this morning that our master database where the collect writes is not replicating the changes to the rest of the servers. I have tried everything I can think of but it appears but nothing seems to work.
When I run a query to collect the status I see that events are not being acknowleged since yesterday. The st_last_received has not changed at all.
st_origin | st_received | st_last_event | st_last_event_ts | st_last_received | st_last_received_ts | st_last_received_event_ts | st_lag_num_events | now
-----------+-------------+---------------+----------------------------+------------------+----------------------------+----------------------------+-------------------+-------------------------------
25 | 24 | 26196903 | 2016-11-29 17:39:06.859051 | 26187885 | 2016-11-29 12:51:45.396619 | 2016-11-28 11:11:48.909855 | 9018 | 2016-11-29 17:39:07.247598-05
25 | 27 | 26196903 | 2016-11-29 17:39:06.859051 | 26187885 | 2016-11-28 11:11:49.203193 | 2016-11-28 11:11:48.909855 | 9018 | 2016-11-29 17:39:07.247598-05
25 | 26 | 26196903 | 2016-11-29 17:39:06.859051 | 26187885 | 2016-11-28 11:11:50.253235 | 2016-11-28 11:11:48.909855 | 9018 | 2016-11-29 17:39:07.247598-05
I first restarted the slony daemons on all the nodes and have subsequently done this multiple times. I have set debugging to level 4 for debug logging and have combed through them without finding a single issue.
I have looked through all the .sl_ tables for anything that might tell me why it is not working.
Our configuration is as follows for the important replication set.
select * from _ads.sl_set;
set_id | set_origin | set_locked | set_comment
--------+------------+------------+-----------------
1 | 25 | | mgt tables
select * from _ads.sl_subscribe ;
sub_set | sub_provider | sub_receiver | sub_forward | sub_active
---------+--------------+--------------+-------------+------------
1 | 25 | 26 | t | t
1 | 25 | 27 | t | t
2 | 25 | 27 | t | t
1 | 25 | 24 | t | t
select * from _ads.sl_listen ;
li_origin | li_provider | li_receiver
-----------+-------------+-------------
24 | 24 | 25
26 | 26 | 25
27 | 27 | 25
27 | 25 | 26
26 | 25 | 27
27 | 25 | 24
24 | 25 | 27
24 | 25 | 26
26 | 25 | 24
26 | 24 | 25
27 | 26 | 25
26 | 27 | 25
24 | 26 | 25
27 | 24 | 25
24 | 27 | 25
25 | 25 | 24
25 | 25 | 26
25 | 25 | 27
Any advice, assistance, or an idea on where to look would be greatly appreciated. I am in full on panic mode now.

Cognos Calculate Variance Crosstab (Relational)

I have a simple crosstab such as this:
Trans | Pants | Shirts |
| 2013 | 2014 | 2013 | 2014 |
---------------------------------------
Jan | 33 | 37 | 41 | 53 |
Feb | 31 | 33 | 38 | 43 |
Mar | 26 | 29 | 51 | 56 |
Pants and Shirt belong to the data item: Category
Years belong to the data item: Years
Months belong to the data item: Months
Trans (transactions) belongs to the data item: Trans
Here is what is looks like in report studio:
Trans | <#Category#> | <#Category#> |
| <#Years#> | <#Years#> | <#Years#> | <#Years#> |
-----------------------------------------------------------
<#Months#>| <#1234#> | <#1234#> | <#1234#> | <#1234#> |
I want to be able to calculate the variance of pants and shirts between the years. To get something like this:
Trans | Pants | Shirts |
| 2013 | 2014 | YOY Variance | 2013 | 2014 | YOY Variance |
---------------------------------------------------------------------
Jan | 33 | 37 | 12.12 | 41 | 53 | 29.27 |
Feb | 31 | 33 | 6.45 | 38 | 43 | 13.16 |
Mar | 26 | 29 | 11.54 | 51 | 56 | 9.80 |
I've tried inserting a data item for YOY Variance with the expression below just to see if I can even get the 2014 value but cannot, some odd reason it only returns the 2013 values:
Total([Trans] for maximum[Year],[Category],[Months])
Any ideas? Help?
(I'm assuming you don't have a DMR.)
There is no easy/clean way to do this in Cognos. In your query, you'll have to build a calculation for each year in your output. So, something like this for 2013:
total (if [Years] = 2013) then ([Trans]) else (0))
And basically the same for 2014.
Cut the Trans piece out of your crossab. Then you'll nest those two calcs under your years. To get rid of all the zeroes or nulls, select the two columns. From the menu, select Data,
Suppress,Suppress Columns Only.
Finally, you will drop a calc in next to your Years in the crosstab (not under them). The expression will be ([2014 trans] - [2013 trans])/[2014 trans] (or whatever you end up naming your calcs). Format it as a percent, and you should be good to go.
Told you it was a pain!