Sum of groupBy elements using PipeTransform - asp.net

I did a groupBy in an Angular project and in back-end, using ASP.NET Web Api to retrieve data for the groupBy functionality. I used this link to make it work - Angular groupBy that uses PipeTransform interface for the implementation. It works fine and the current output is as follows right now:
Jack
ID - Date - Points
1001 - 04/01/2020 - 10
1001 - 05/01/2020 - 10
John
ID - Date - Points
1002 - 04/01/2020 - 10
1002 - 05/01/2020 - 20
So the following is the data structure:
data = [
{ "id": "1001", "name": "Jack", "date": "2020-01 - 05T00: 00: 00", "points": 10 },
{ "id": "1001", "name": "Jack", "date": "2020-01 - 04T00: 00: 00", "points": 10 },
{ "id": "1002", "name": "John", "date": "2020-01 - 05T00: 00: 00", "points": 20 },
{ "id": "1002", "name": "John", "date": "2020-01 - 04T00: 00: 00", "points": 10 }
];
In the front-end, I did this to render the view:
<div class="col-xs-12 table-responsive">
<table *ngIf="data" class="table table-responsive" border="0">
<tbody *ngFor="let details of data | groupBy: 'name'">
<tr>
<th colspan="2">
<h2>{{details.key}}</h2> <!--Here name is shown-->
</th>
</tr>
<tr>
<th>Sl No.</th>
<th>Id</th>
<th>Name</th>
<th>Date</th>
<th>Points</th>
</tr>
<tr *ngFor="let value of details.value; let i = index">
<td>{{i + 1}}</td>
<td>{{value.id}}</td>
<td>{{value.name}}</td>
<td>{{value.date | date :'dd-MMM-yyyy'}}</td>
<td>{{value.points}}</td>
</tr>
<tr>Total Points: {{sum}}</tr> <!--Expecting total points for groupBy-->
</tbody>
</table>
</div>
My expected output is as follows:
Jack
ID - Date - Points
1001 - 04/01/2020 - 10
1001 - 05/01/2020 - 10
______________________________
Total Points: 20
John
ID - Date - Points
1002 - 04/01/2020 - 10
1002 - 05/01/2020 - 20
______________________________
Total Points: 30
I am new to stackblitz and unable to build the project to render. Here is the link that I tried with the code - Angular groupBy with stackblitz
N.B: I tried to do the sum in the TypeScript file like this but this does total calculation of the points, not groupBy:
public sum: number = 0;
GetUserPoints() {
debugger;
for (let i = 0; i <= this.data.length; i++) {
this.sum += this.data[i].points;
console.log(this.data.length);
}
}

if you want to keep this dynamic and reusable by using pipes, you could achieve calculating the sum of points by creating a PluckPipe and SumPipe like i did in this stackblitz
Then just use <tr>Total Points: {{details.value | pluck:'points' | sum}}</tr> in your template
example: https://stackblitz.com/edit/angular-iurvtc
btw: your stackblitz did not render because there were spaces in the timestamps.

Related

How can I create a GTM data layer variable that pull the last item in a product array

I have a eCommerce data layer that looks like this:
products: [
{
name: "T10 (Fri - Sun) Adult",
id: "1123",
price: "260",
brand: "f1",
category: "Austrian Formula 1 Grand Prix 2022",
quantity: 1
},
{
name: "Red Bull: CDE (Fri - Sun) Adult",
id: "1123",
price: "251",
brand: "f1",
category: "Austrian Formula 1 Grand Prix 2022",
quantity: 1
},
{
name: "Steiermark (South-West) (Fri - Sun) Adult",
id: "1123",
price: "420",
brand: "f1",
category: "Austrian Formula 1 Grand Prix 2022",
quantity: 1
}
]
When creating a data layer variable in GTM, I know I can create products.0.name and the result will be 'T10 (Fri - Sun) Adult.' Or products.2.name would result in 'Steiermark (South-West) (Fri - Sun) Adult.' But, if we assume I don't always know how many items will be in the product array, how can I create a variable that always pulls the final product (in the above example Steiermark (South-West) (Fri - Sun) Adult)?
UPDATE
I have tried products.slice(-1).name
view here
But that is giving a 'undefined' response
view here
Just use .slice(-1) on your array. Here:
You can also use .pop(), but pop mutates, therefore, no pops.

get all possible keys / key paths in a json string in r

How can I get all the different possible json paths in a json string? Often I get huge
For example, I would like to get something back like:
result = data.frame(paths = c('name',
'name.first'
,'name.last'
,'address'
,'address.city'
,'address.state'
,'age'
,'income'
,'block'))
result
given something like this...
myjson='{
"name": {
"first": "jack",
"last": "smith"
},
"address": {"city": "bigtown", "state": "texas"},
"age": "21",
"income": "123",
"block" :["abc","xyz"]
}'
I've tried experimenting with jsonlite::fromJson but that doesn't seem to get me to what I'm after exactly.
This will get you the full paths:
data.frame(result = names(as.data.frame(jsonlite::fromJSON(myjson))))
result
1 name.first
2 name.last
3 address.city
4 address.state
5 age
6 income
7 block
If you need all partial paths along with all full paths:
data.frame(
result = sort(unique(
c(names(fromJSON(myjson)),
names(as.data.frame(jsonlite::fromJSON(myjson))))))
)
result
1 address
2 address.city
3 address.state
4 age
5 block
6 income
7 name
8 name.first
9 name.last

how can I put my canvas next to my table automatically if the screen is wide enough and else underneath each other?

I have a table with data and a graph (chart.js) visualizing this data.
The graph is in a "canvas"-type.
I can't get them to be next to each other.
I tried:
float:left
putting them both in the same div
column-count
... all giving wrong results.
Float:left puts only a bit of the graph next to the table, in the same div gives no change at all and column-count behaves somewhat like float-left.
<script src="/Chart.js"></script>
<article>
<h2>my data</h2>
<table><caption>nice data</caption><thead>
<tr><th>some value</th><th>%</th><th>more values</th></tr></thead>
<tbody>
<tr><td>€ 100,00</td><td>17,59%</td><td>10 0 09 39 09 </td></tr>
<tr><td>€ 250,00</td><td>5,86%</td><td>0 79 7 35 5 </td></tr>
<tr><td>€ 10 000,00</td><td>5,48%</td><td>09 09 36 56 05 </td></tr>
<tr><td>€ 100 000,00</td><td>5,01%</td><td>79 35 85 94 03 </td></tr>
<tr><td>€ 107,50</td><td>4,11%</td><td>89 69 49 09 53 </td></tr>
<tr><td>€ 1 000,00</td><td>3,06%</td><td>28 06 15 51 20 </td></tr>
<tr><td>€ 2 500,00</td><td>2,79%</td><td>10 39 77 17 25 </td></tr>
</tbody></table>
<div style="height:80vh;"><canvas id="bedrag_perc"></canvas></div>
<script>
var ctx = document.getElementById("bedrag_perc");
var myChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: [100, 107, 250, 1000, 10000, 100000, 3.14],
datasets: [{
label: 'so much data',
data: ['17.59', '4.11', '5.86', '3.06', '5.48', '5.01', '41.11'],
}]
},
options: {
animation: { duration: 0 },
responsive: true,
maintainAspectRatio: false
}
});
</script>
</article>
I would like to have the graph next to the table if the screen is wide enough, else underneath each other (responsive web design).
The actual result is that only half of the chart is next to the table.
i have used bootstrap to make it work. below is the link. hope it helps.
http://jsfiddle.net/3vxtw786/1/999

Positionating and arrow direction in GraphViz

I'm trying to migrate some realy old documentation to our internal wiki using GraphViz.
I'm not used to the Dot language, and needs some help
See following example:
I have experiment a lot, but the best I have come up to so far is this:
digraph CentralPmr {
fontname="Helvetica";
shape=box;
node[shape=box];
graph [splines=ortho]
sg [label="TTD storage group for\nthe logged values"]
vc [label="Value catalogue"]
tc1 [label="Time catalogoue (1)"]
tc2 [label="Time catalogoue (2)"]
sv_ [shape=point,width=0.01,height=0.01];
sv [label=""]
ie [shape=none, label="Initiating event"]
c1 [shape=none, label="The set of values, defined\nby the value catalogue, which\nare freezed out of the TTD\nstorage group of the actual log."]
c2 [shape=none, label="Time catalogue defining\nat what time around the\ninitiating event values\nshould be collected."]
sgf [shape=record, label="{<f0> 1|2|3|4|..}|{ | | | | }"]
sg -> sv_ [penwidth=4, dir=none];
sv_ -> sv -> tc2 [penwidth=4]
sv -> sgf:f0 [penwidth=4]
{vc, tc1} -> sg
c1 -> sv [style=dashed, arrowhead="open"];
{rank=min; ie}
{rank=same; sg c1}
{rank=same; vc sgf}
{rank=max; rc2}
}
It don't have to be exactly the same as the source, but I want it to be understandable.
The problems is:
How do I place the text between "Value catalogue" and "Time catalogue (1)"?
[Edit] How do I force the arrow to "TTD storage group for PMR-freezed value" to go from the side, and not from the above? It is a virtualization of a memory area, and the arrow are pointing to a specific memory post. In other images, it can point to a other memory post in the memory area (eg. 2 , 3, 4..).
Is it possible to create a zigzag line from the "Initiating event"?
How do I place the legends in the bottom that explains the different types of lines?
[edit] How do I add the comments above, under and to the right of the "TTD storage group for PMR-freezed values"?
[Edit] How do I make the "TTD storage group for PMR-freezed value" wider?
This is on top of my first answer in a way that editing that one would create too much confusion. I have tried to take all your needs into consideration and it only works (I believe) if you give up the splines=ortho requirement. Pls refer to the comments below my first answer. Here we go:
digraph CentralPmr {
fontname="Helvetica";
shape=box;
node[shape=box];
// graph [splines=ortho]
sg [label="TTD storage group for\nthe logged values", width = 2.5]
sv[ label="", width = 2]
ie [ shape=none, label="Initiating event", fontsize = 18 ]
c1 [ shape=none, label="The set of values, defined\nby the value catalogue, which\nare freezed out of the TTD\nstorage group of the actual log." ]
sgf[shape=box, margin=0, label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
<TD BORDER="0" COLSPAN="2">TTD storage group for<BR/>PMR freezed values</TD>
</TR>
<TR>
<TD PORT="f1">1</TD>
<TD BORDER="0" ROWSPAN="6">The set of<BR/>values is<BR/>stored in<BR/>the TTD<BR/>storage<BR/>group</TD>
</TR>
<TR>
<TD>2</TD>
</TR>
<TR>
<TD>3</TD>
</TR>
<TR>
<TD>4</TD>
</TR>
<TR>
<TD>-</TD>
</TR>
<TR>
<TD>-</TD>
</TR>
<TR>
<TD BORDER="0" COLSPAN="2">Up to nine freezing areas<BR/>for defined central PMR</TD>
</TR>
</TABLE>>];
TTD [shape=none, margin=0, label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="12">
<TR>
<TD PORT="f1">Value catalogue</TD>
</TR>
<TR>
<TD BORDER="0"></TD>
</TR>
<TR>
<TD PORT="f2">Time catalogue (1)</TD>
</TR>
<TR>
<TD BORDER="0">Time catalogue defining<BR/>at what time around the<BR/>initiating event values<BR/>should be collected</TD>
</TR>
<TR>
<TD PORT="f3">Time catalogue (2)</TD>
</TR>
</TABLE>>];
connector_1[ shape = point height = 0 width = 0 margin = 0 ]
ie -> connector_1[ style = dotted, arrowhead = none ];
{ rank = same; connector_1 c1 }
connector_1 -> c1[ style = invis, minlen = 4 ];
c1 -> sv[ style = dashed, arrowhead = open ];
connector_2[ shape = point height = 0 width = 0 margin = 0 ]
connector_1 -> connector_2[ style = dotted ];
{ rank = same; sg connector_2 sv }
sg -> connector_2[ minlen = 3, penwidth = 4, arrowhead = none ];
connector_2 -> sv[ minlen = 3, penwidth = 4 ];
sg:sw -> TTD:f1:nw[ weight = 5 ];
sg:w -> TTD:f2:w;
sv:sw -> TTD:f3:e[ penwidth = 4 ];
sv:sw -> sgf:f1:w[ penwidth = 4 ];
node[ shape = plaintext ];
leg2[ label = "Data flow" ];
leg4[ label = "Reference" ];
leg6[ label = "Comment" ];
node [ shape = point height = 0 width = 0 margin = 0 ];
leg1 leg3 leg5
TTD:sw -> leg1[ style = invis ];
{ rank = same; leg1 leg2 leg3 leg4 leg5 leg6 }
edge[ minlen = 2 ];
leg1 -> leg2[ penwidth = 4 ];
leg3 -> leg4[ style = dotted ];
leg5 -> leg6[ style = dashed, arrowhead = open ];
}
yields
Not sure whether I understand completely what you want but below my take on it. This is just a first attempt, much more fine-tunig can be done. I would probably use HTML-like nodes where text and "box" need to be closer, in particular for that "TTD Storage Group for PMR freezed values" in the original graph.
My answers to your questions would be:
How do I place the text between "Value catalogue" and "Time catalogue (1)"?
--- See below. I have put it between the two time catalogues as in the original graph but easy to move around.
How do I force the arrow to the record go from the side, and not from the above?
--- See below. You could also use rankdir = LR; to change the orientation if that is your question.
Is it possible to create a zigzag line from the "Initiating event"?
--- There are ways, but a lot of effort (like creating a custom shape). Nothing "out of the box", to the best of my knowledge.
How do I place the legends in the bottom?
I don't really understand, but in general, the answer would be HTML-like labels when we talk about nodes.
Her is what I have done:
digraph CentralPmr
{
fontname="Helvetica";
shape=box;
node[shape=box];
graph [splines=ortho]
sg [label="TTD storage group for\nthe logged values"]
vc [label="Value catalogue"]
tc1 [label="Time catalogoue (1)"]
tc2 [label="Time catalogoue (2)"]
sv_ [shape=point,width=0.01,height=0.01];
sv [label="", width = 2]
ie [shape=none, label="Initiating event"]
c1 [shape=none, label="The set of values, defined\nby the value catalogue, which\nare freezed out of the TTD\nstorage group of the actual log."]
c2 [shape=none, label="Time catalogue defining\nat what time around the\ninitiating event values\nshould be collected."]
sgf [shape=record, label="{<f0> 1|2|3|4|..}|{ | | | | }"]
connector_1[ shape = point height = 0 width = 0 margin = 0 ]
ie -> connector_1[ style = dotted, arrowhead = none ];
{ rank = same; connector_1 c1 }
connector_1 -> c1[ style = invis ];
c1 -> sv[ style = dashed, arrowhead = open ];
connector_2[ shape = point height = 0 width = 0 margin = 0 ]
connector_1 -> connector_2[ style = dotted ];
{ rank = same; sg connector_2 sv }
sg -> connector_2[ minlen = 3, penwidth = 4, arrowhead = none ];
connector_2 -> sv[ minlen = 3, penwidth = 4 ];
vc -> tc1 -> c2 -> tc2[ style = invis, weight = 10 ];
sg -> vc;
sg -> tc1;
sv -> tc2[ penwidth = 4 ];
sv -> sgf;
}
yields

Customize Table in Bootstrap

I am creating an ecommerce website using the current Bootstrap version. On the admin panel I am trying to show all the product infos within a table in such a way that it looks like this :
+______+_____________+_____+_______+_____+
| name | description | qty | price | sku |
+______+_____________+_____+_______+_____+
| P1 | Description | 10 | 200 | 2ds |
+______+_____________+_____+_______+____ +
| Image 1 , Image 2 , Image 3, ...... |
+______+_____________+_____+_______+____ +
| P2 | Description | 14 | 500 | 3ds |
+______+_____________+_____+_______+____ +
| Image 1 , Image 2 , Image 3, ...... |
+______+_____________+_____+_______+____ +
| P3 | Description | 45 | 234 | 4xs |
+______+_____________+_____+_______+____ +
| Image 1 , Image 2 , Image 3, ...... |
+______+_____________+_____+_______+____ +
And so on. Hope I can make you understand what I am trying to do here. After every product row comes the product images.. then again another product row and its corresponding images and so on....
What I have tried :
<table class="table table-striped text-center">
<thead>
<tr>
<th>Name</th>
<th>Category</th>
<th>Description</th>
<th>Stock Qty</th>
<th>Shown Qty</th>
<th>Sale Price</th>
<th>Original Price</th>
<th>SKU</th>
<th>Image</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some Product</td>
<td>T Shirt</td>
<td>Description</td>
<td>24</td>
<td>500</td>
<td>BKSTU56V57</td>
</tr>
<tr><img src=".." /><img src="...."></tr>
</tbody>
</table>
And it's not working. taking the images to the top even before the <th>
You're missing the <td> element. Try this with column span:
<tr><td colspan="6"><img src=".." /><img src="...."></td></tr>

Resources