Group By with multiple Objects vb.net - vb.net

I have a list as following
list1 = [
{meal: {id: 1, version: 0}, type: {id: 2, version: 0}, adjCount: 1, systemCount: 0},
{meal: {id: 1, version: 0}, type: {id: 2, version: 0}, adjCount: 2, systemCount: 0},
{meal: {id: 2, version: 0}, type: {id: 1, version: 0}, adjCount: 4, systemCount: 0},
{meal: {id: 2, version: 0}, type: {id: 1, version: 0}, adjCount: 7, systemCount: 0},
]
I'm looking for a result such as it returns both mealId and type id with it's respective totals
As
{meal: {id: 1, version: 0}, type: {id: 2, version: 0}, adjCount: 3, systemCount: 0},
{meal: {id: 2, version: 0}, type: {id: 1, version: 0}, adjCount: 11, systemCount: 0}
I tried Using Linq with following code
List.GroupBy(Function(myItem) New MyObject With {.mealTypeId = myItem.Meal.Id, .countTypeId = MyItem.Count.Id}).
Select(Function(g) New With
{
.MealTypeId = g.Key.MealTypeId,
.CountTypeId = g.Key.CountTypeId,
.AdjustmentCount = g.Sum(Function(i) i.AdjustmentCount),
.SystemCount = g.Sum(Function(i) i.SystemCount)
}
but it doesn't return the expected output. Any Help will be greatly appreciated, I very rarely ask questions here so please forgive any mistakes I might have done in describing the issue.

Related

Filtering numbers or strings in a comma delimited object

I am using multi-select to filter out data.
<Multiselect
v-model="roles"
class="input1"
placeholder="Select Roles"
mode="tags"
:searchable="true"
:options="roleOptions"
/>
<Multiselect
v-model="sub_organization"
class="input1"
placeholder="Select sub-organization"
mode="tags"
:searchable="true"
:options="suborgOptions"
/>
data:() => ({
mode: "tags",
closeOnSelect: false,
roleOptions: [],
suborgOptions: [],
searchable: true,
sub_organization: [],
roles: [],
filteredData: [],
fetchedData: [],
}),
searchResult() {
this.filteredData = this.fetchedData.filter((data) => {
// var intRoles = parseInt(data.roles.split(", "))
// var intSuborgs = parseInt(data.suborgs.split(", "))
return (
// intSuborgs == this.sub_organization &&
// intRoles == this.roles
data.suborgs.includes(this.sub_organization) &&
data.roles.includes(this.roles)
);
});
},
data.roles = {1, 3},
{1, 4, 5, 7},
{10, 14},
{1, 9},
{2, 4, 6, 8},
{4, 5},
{4, 10},
{9, 1, 4}
for example:
when I use includes and I searched 1 it returns all data.roles with 1 in it including 10, 14, 4, 10 etc.
using includes():
searching 1 returns {1, 3}, {1, 4, 5, 7}, {10, 14}, {1, 9}, {4, 10}, {9, 1, 4}
searching 4 returns {1, 4, 5, 7}, {10, 14}, {4, 10}, {9, 1, 4}, {4, 5}, {2, 4, 6, 8}
as you can see I commented out intRoles and intSuborgs, I tried using parseInt and then split it, when I search 1 it returns only the objects that have 1 in index 0
using parseInt and split:
searching 1 returns {1, 3}, {1, 4, 5, 7}, {1, 9}
searching 4 returns {4, 5}, {4, 10},
What I want to happen is when I search 1 it would return only the objects that has 1 in it excluding double digits with 1, or since I am using multi-select searching 1 and 4 returns objects with 1 and 4 in it excluding double digits with 1 and 4 also.

How input data in line chart in Pentaho?

I want to make this chart in Pentaho CDE:
based in this chart (I think that is the most similar from among CCC Components):
(The code is in this link.)
but I don't know how I can adapt my data input to that graph.
For example, I want to consume the data with this format:
[Year, customers_A, customers_B, cars_A, cars_B] [2014, 8, 4, 23, 20]
[2015, 20, 6, 30, 38]
How I can input my data in this chart?
Your data should come as an object such as this:
data = {
metadata: [
{ colName: "Year", colType:"Numeric", colIndex: 1},
{ colName: "customers_A", colType:"Numeric", colIndex: 2},
{ colName: "customers_B", colType:"Numeric", colIndex: 3},
{ colName: "cars_A", colType:"Numeric", colIndex: 4},
{ colName: "cars_B", colType:"Numeric", colIndex: 5}
],
resultset: [
[2014, 8, 4, 23, 20],
[2015, 20, 6, 30, 38]
],
queryInfo: {totalRows: 2}
}

Is it possible to use highcharts heat map chart using rally sdk?

I'm building a rally custom HTML app. I would like to create a heat map chart. How can I do that?
I've tried to create Rally Chart of the type 'heatmap' (code below). As a result, I see the 404 error message in the console:
GET https://rally1.rallydev.com/slm/panel/highcharts/heatmap.js?_dc=1558434971290 404
When I try to use Highcharts library directly I'm getting a conflict with https://rally1.rallydev.com/apps/2.1/lib/analytics/analytics-all.js - highcharts being loaded twice. As a result analytics lib do not load I guess and I get an error like Lumenize.Time undefined.
this.chart = this.add(
Ext.create('Rally.ui.chart.Chart', {
loadMask: false,
chartData: {
series: [{
type:'heatmap',
name: 'Sales per employee',
borderWidth: 1,
data: [[0, 0, 10], [0, 1, 19], [0, 2, 8], [0, 3, 24], [0, 4, 67], [1, 0, 92], [1, 1, 58], [1, 2, 78], [1, 3, 117], [1, 4, 48], [2, 0, 35], [2, 1, 15], [2, 2, 123], [2, 3, 64], [2, 4, 52], [3, 0, 72], [3, 1, 132], [3, 2, 114], [3, 3, 19], [3, 4, 16], [4, 0, 38], [4, 1, 5], [4, 2, 8], [4, 3, 117], [4, 4, 115], [5, 0, 88], [5, 1, 32], [5, 2, 12], [5, 3, 6], [5, 4, 120], [6, 0, 13], [6, 1, 44], [6, 2, 88], [6, 3, 98], [6, 4, 96], [7, 0, 31], [7, 1, 1], [7, 2, 82], [7, 3, 32], [7, 4, 30], [8, 0, 85], [8, 1, 97], [8, 2, 123], [8, 3, 64], [8, 4, 84], [9, 0, 47], [9, 1, 114], [9, 2, 31], [9, 3, 48], [9, 4, 91]],
dataLabels: {
enabled: true,
color: '#000000'
}
}]
},
chartConfig: {
chart: {
marginTop: 40,
marginBottom: 80,
plotBorderWidth: 1
},
title: {
text: 'Sales per employee per weekday'
},
xAxis: {
categories: ['Alexander', 'Marie', 'Maximilian', 'Sophia', 'Lukas', 'Maria', 'Leon', 'Anna', 'Tim', 'Laura']
},
yAxis: {
categories: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
title: null
},
colorAxis: {
min: 0,
minColor: '#FFFFFF',
//maxColor: Highcharts.getOptions().colors[0]
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 280
},
tooltip: {
formatter: function () {
return '<b>' + this.series.xAxis.categories[this.point.x] + '</b> sold <br><b>' +
this.point.value + '</b> items on <br><b>' + this.series.yAxis.categories[this.point.y] + '</b>';
}
},
}
})
);
The problem you are going to hit is that the Highcharts v3.0.10 is bundled into the analytics code. This has been done so that there is a known Highcharts library used with the added Lumenize code - i.e. they match. The analytics library is dynamically loaded if the SDK can't find a Highcharts library as it starts up (i.e. window.Highcharts is undefined).
The result of this is that it looks like it is quite kludgy to change the Highcharts arrangement to add heatmaps. Someone who is better at javascript library loading/overloading might have a different view. You would have to load the heatmap.js file into your app after the app has started (in 'launch'?) to get around the dynamic loading.
I know that this is not directly related to your Highcharts question, but if it is just a 'heatmap' you are after, not necessarily a Highcharts heatmap, I have started to use d3 to visualise stuff in Rally. There is a d3 heatmap example here if you are interested: http://bl.ocks.org/tjdecke/5558084
I have done a bit of work to get d3 working inside a Rally custom app. There are a few examples on my github, but have a look here: https://github.com/nikantonelli/Radial-Density

Active record where.not returns empty array

Following command
Fight.last.fight_logs.where(item_id: nil)
generates sql:
Fight Load (0.3ms) SELECT "fights".* FROM "fights" ORDER BY "fights"."id" DESC LIMIT $1 [["LIMIT", 1]]
FightLog Load (0.2ms) SELECT "fight_logs".* FROM "fight_logs" WHERE "fight_logs"."fight_id" = $1 AND "fight_logs"."item_id" IS NULL LIMIT $2 [["fight_id", 27], ["LIMIT", 11]]
and returns:
#<ActiveRecord::AssociationRelation [#<FightLog id: 30, fight_id: 27, attack: 0, block: 0, item_id: nil, user_id: 1, damage: 11.0, created_at: "2017-11-02 16:20:55", updated_at: "2017-11-02 16:20:57">, #<FightLog id: 31, fight_id: 27, attack: 0, block: 0, item_id: nil, user_id: 20, damage: 3.0, created_at: "2017-11-02 16:20:57", updated_at: "2017-11-02 16:20:57">, #<FightLog id: 33, fight_id: 27, attack: 0, block: 0, item_id: nil, user_id: 1, damage: 1.0, created_at: "2017-11-02 16:21:40", updated_at: "2017-11-02 16:21:40">, #<FightLog id: 32, fight_id: 27, attack: 0, block: 0, item_id: nil, user_id: 20, damage: 7.0, created_at: "2017-11-02 16:21:33", updated_at: "2017-11-02 16:21:40">, #<FightLog id: 34, fight_id: 27, attack: 0, block: 0, item_id: nil, user_id: 1, damage: 12.0, created_at: "2017-11-02 16:21:47", updated_at: "2017-11-02 16:21:48">, #<FightLog id: 35, fight_id: 27, attack: 0, block: 0, item_id: nil, user_id: 20, damage: 14.0, created_at: "2017-11-02 16:21:48", updated_at: "2017-11-02 16:21:48">]>
but
Fight.last.fight_logs.where.not(item_id: 1)
generates sql:
Fight Load (1.0ms) SELECT "fights".* FROM "fights" ORDER BY "fights"."id" DESC LIMIT $1 [["LIMIT", 1]]
FightLog Load (0.8ms) SELECT "fight_logs".* FROM "fight_logs" WHERE "fight_logs"."fight_id" = $1 AND ("fight_logs"."item_id" != $2) LIMIT $3 [["fight_id", 27], ["item_id", 1], ["LIMIT", 11]]
and returns:
#<ActiveRecord::AssociationRelation []>
How it is possible? What i'm doing wrong?
You should specify NULL value in your query since you have it in your database:
Fight.last.fight_logs.where('item_id != ? OR item_id IS NULL', 1)
This is just how SQL works:
select 1 != NULL;
+-----------+
| 1 != NULL |
+-----------+
| NULL |
+-----------+
You can look at this answer to clarify the issue.
Also, I would recommend avoiding using default NULL values in your database, there is nice answer about it. You can simply use default: 0, null: false your case.

rethinkdb: secondary compound indexes / aggregation queries and intermediate documents generation

Let's assume such table content where for the same product_id, we have as many rows than updates during status==1 (published) and finally status==0 (unpublished) and then becomes==2 (deleted)
{id: <auto>, product_id: 1, last_updated: 2015-12-1, status: 1, price: 1}
{id: <auto>, product_id: 2, last_updated: 2015-12-1, status: 1, price: 10}
{id: <auto>, product_id: 1, last_updated: 2015-12-2, status: 1, price: 2}
{id: <auto>, product_id: 1, last_updated: 2015-12-3, status: 0, price: 2}
{id: <auto>, product_id: 2, last_updated: 2015-12-2, status: 0, price: 10}
{id: <auto>, product_id: 3, last_updated: 2015-12-2, status: 1, price: 123}
{id: <auto>, product_id: 1, last_updated: 2015-12-4, status: 2, price: 2}
{id: <auto>, product_id: 2, last_updated: 2015-12-4, status: 2, price: 10}
Now, I am trying to find a way, maybe using a secondary compound index, do get for example, given a date like in col1 (using r.time)
DATE STATUS==1 STATUS==0 STATUS==2
2015-12-1 [101, 102] [] []
2015-12-2 [103, 106] [105] []
2015-12-3 [106] [104, 105] []
2015-12-4 [] [] [107, 108]
The difficulty here, is that a product_id document is still to be considered as the most recent status as long as its last_updated date is less or equal to the provided date.
I try by grouping by product_id, then take the max('last_updated'), then only keep each reduction unique document if status==1
I have in mind to have an index for each status / given_date
Or another solution, would be to insert in another table the result of an aggregation which would only store a unique document per date, containing all the initial documents ids matching the same criteria, and so on...
And then later perform joins using these intermediate records to fetch the values of each product_id at the given date/status.
something like:
{
date: <date_object>,
documents: [
{id: document_id, status: 1},
{id: document_id, status: 1},
{id: document_id, status: 2},
{id: document_id, status: 0},
...
]
}
Please advise
Edit 1:
This is an example of a query I try to run to analyse my data, here it is for example to get an overview of the statuses for each group with more than 1 document:
r.db('test').table('products_10k_sample')
.group({index: 'product_id'})
.orderBy(r.desc('last_updated'))
.ungroup()
.map(function(x){
return r.branch(
x('reduction').count().gt(1),
x('reduction').map(function(m){
return [m('last_updated').toISO8601(), m('status'), m('product_id')]
}),
null
)
})