Can i short a textbox by a sum lines? example: I have textbox:
Textbox1.Lines(0)= 1 10
Textbox1.Lines(1)= 1 11
Textbox1.Lines(2)= 2 10
Textbox1.Lines(3)= 3 11
Textbox1.Lines(4)= 2 12
Expected Output: preferably if possible, write the sum that is. with :( sum = x) preferably short by descending, probably an example of sorting code would help me, but I can do that too, but for now I don't know how to order according to the sum of the lines. just to sort them out, this would be a model, but to know the sum of each one as well.
{ LstScan = 2 12, DrwSum = 14 }
{ LstScan = 3 11, DrwSum = 14 }
{ LstScan = 2 10, DrwSum = 12 }
{ LstScan = 1 11, DrwSum = 12 }
{ LstScan = 1 10, DrwSum = 11 }
In c# this would look like:
var list = new[] { "2 12", "3 11", "2 10", "1 11", "1 10" }
.Select(o => Tuple.Create<string, int>(o, o.Split(' ').Sum(x => int.Parse(x))));
var result = list.OrderByDescending(o => o.Item2).ToList();
In vb.net it would be:
Dim list = {"2 12", "3 11", "2 10", "1 11", "1 10"}
.[Select](Function(o) Tuple.Create(Of String, Integer)(o, o.Split(" "c).Sum(Function(x) Integer.Parse(x))))
Dim result = list.OrderByDescending(Function(o) o.Item2).ToList()
Related
I need to select any random value from the below sample json every time i run the code. How can i achieve this in Karate? I need to get any random value and use in another feature file.
def myJson =
"""
{
"sampleJson": {
"random1": "1",
"random2": "2",
"random3": "3",
"random4": "4",
"random5": "5"
}
}
"""
Also refer: https://github.com/intuit/karate#commonly-needed-utilities
* def random = function(max){ return Math.floor(Math.random() * max) + 1 }
* def myJson =
"""
{
"sampleJson": {
"random1": "1",
"random2": "2",
"random3": "3",
"random4": "4",
"random5": "5"
}
}
"""
* def key = 'random' + random(5)
* def result = myJson.sampleJson[key]
* print result
Also see: https://stackoverflow.com/a/70376593/143475
imagine you have website where people post their ads. So, each ad has some selected properties, for example cars has different engine types, gears, colors and etc. Those properties user selects before submiting a listing.
I store selected properties in a jsonb format in listings table, look at the data column:
.
So, each listing contains data like this:
{
"properties":[
{
"id":"1",
"value_id":"1"
},
{
"id":"2",
"value_id":"5"
},
{
"id":"3",
"value_id":"9"
},
{
"id":"4",
"value":"2.0"
},
{
"id":"7",
"value":"2017"
},
{
"id":"6",
"value":"180.000"
}
]
}
Now, the question is:
1) How to filter listings by those id's and value's which are in json? For example, show listings where id = 2 and it's value = 5 AND id = 3 and it's value = 9 and so on. I dont need OR, i need AND. So, filter data by multiple id's and value's.
2) First point + ability to compare id's and value's (greater or lower than).
answering first point, it's probably the first time when I find use for jsonb[]:
t=# with c(a,j) as (values(18,'{
"properties":[
{
"id":"1",
"value_id":"1"
},
{
"id":"2",
"value_id":"5"
},
{
"id":"3",
"value_id":"9"
},
{
"id":"4",
"value":"2.0"
},
{
"id":"7",
"value":"2017"
},
{
"id":"6",
"value":"180.000"
}
]
}'::jsonb), (19,'{"properties":[{"id": "1", "value_id": "1"}]}'))
, m as (select a, array_agg(jb.value)::jsonb[] ar from c, jsonb_array_elements(j->'properties') jb group by a)
select a
from m
where '{"id": "1", "value_id": "1"}'::jsonb = any(ar)
and '{"id": "3", "value_id": "9"}'::jsonb = any(ar);
a
----
18
(1 row)
and for the second requirement - it won't be that short, as you need to compare (and thus parse json):
t=# with c(a,j) as (values(18,'{
"properties":[
{
"id":"1",
"value_id":"1"
},
{
"id":"2",
"value_id":"5"
},
{
"id":"3",
"value_id":"9"
},
{
"id":"4",
"value":"2.0"
},
{
"id":"7",
"value":"2017"
},
{
"id":"6",
"value":"180.000"
}
]
}'::jsonb), (19,'{"properties":[{"id": "1", "value_id": "1"}]}'))
, m as (select a, jb.value->>'id' id,jb.value->>'value_id' value_id from c, jsonb_array_elements(j->'properties') jb)
, n as (select m.*, count(1) over (partition by m.a)
from m
join c on c.a = m.a and ((id::int >= 1 and value_id::int <2) or (id::int >2 and value_id::int <= 9)))
select distinct a from n
where count > 1;
a
----
18
(1 row)
with basic idea to use OR to get possible rows and then check if ALL of OR conditions were met
I am developing angular 2 application, in my current project I implemented the functionality as lookup master and lookup details strategy using API concept.
In My angualr2 application I get the data from those tables using Http Get request, but I want to bind the data in my view like as LookTypevalue when there is an match of LookupMasterId equals to LookupMasterFkId.
My tables structure like this below.
context.LookupMasterTables.AddOrUpdate(
new LookupMasterTable() { ID = 1, LookupType = "AssetType"},
new LookupMasterTable() { ID = 2, LookupType = "IntendedUse" },
new LookupMasterTable() { ID = 3, LookupType = "VehicleYear" },
new LookupMasterTable() { ID = 4, LookupType = "VehicleMake" },
new LookupMasterTable() { ID = 4, LookupType = "VehicleModel" }
);
context.LookupDetailsTables.AddOrUpdate(
new LookupDetailsTable() { ID = 1, LookupValue = "Auto", LookupMasterFKId=1 },
new LookupDetailsTable() { ID = 2, LookupValue = "MotorCycle", LookupMasterFKId = 1 },
new LookupDetailsTable() { ID = 3, LookupValue = "Personal", LookupMasterFKId = 2 },
new LookupDetailsTable() { ID = 4, LookupValue = "Business", LookupMasterFKId = 2 },
new LookupDetailsTable() { ID = 5, LookupValue = "1999", LookupMasterFKId = 3 },
new LookupDetailsTable() { ID = 6, LookupValue = "2000", LookupMasterFKId = 3 },
new LookupDetailsTable() { ID = 7, LookupValue = "2001", LookupMasterFKId = 3 },
new LookupDetailsTable() { ID = 8, LookupValue = "2002", LookupMasterFKId = 3 },
new LookupDetailsTable() { ID = 9, LookupValue = "Honda", LookupMasterFKId = 4 },
new LookupDetailsTable() { ID = 10, LookupValue = "Victory", LookupMasterFKId = 4 },
new LookupDetailsTable() { ID = 11, LookupValue = "Indian", LookupMasterFKId = 4 },
new LookupDetailsTable() { ID = 12, LookupValue = "Harley-Davidson", LookupMasterFKId = 4 },
new LookupDetailsTable() { ID = 9, LookupValue = "Octane", LookupMasterFKId = 5 },
new LookupDetailsTable() { ID = 10, LookupValue = "BMW", LookupMasterFKId = 5 },
new LookupDetailsTable() { ID = 11, LookupValue = "Audi", LookupMasterFKId = 5 },
new LookupDetailsTable() { ID = 12, LookupValue = "Swift", LookupMasterFKId = 5 }
);
My html(view) like this below figure.
Can you please tell me how to do that.
-Pradeep
I'm trying to create a simple chart with two axis and two data series.
When I define bubble series - all works as expected however when both series are defined as line, the dashed lines from the data points to the y axis get confused
Surprisingly, I can't Can't seem to find any examples which show 2* y axis with 2*line series.
My x axis is time based but I can illustrate the problem using a previous JSfiddle answer (jsfiddle.net/NCW89/):
var svg = dimple.newSvg("#chartContainer", 600, 400),
chart = null,
s1 = null,
s2 = null,
x = null,
y1 = null,
y2 = null;
chart = new dimple.chart(svg);
x = chart.addCategoryAxis("x", "Fruit");
y1 = chart.addMeasureAxis("y", "Value");
y2 = chart.addMeasureAxis("y", "Value");
s1 = chart.addSeries("Year", dimple.plot.bubble, [x, y1]);
s1.data = [
{ "Value" : 100000, "Fruit" : "Grapefruit", "Year" : 2012 },
{ "Value" : 400000, "Fruit" : "Apple", "Year" : 2012 },
{ "Value" : 120000, "Fruit" : "Banana", "Year" : 2012 }
];
s2 = chart.addSeries("Year", dimple.plot.bubble, [x, y2]);
s2.data = [
{ "Value" : 110000, "Fruit" : "Grapefruit", "Year" : 2013 },
{ "Value" : 300000, "Fruit" : "Apple", "Year" : 2013 },
{ "Value" : 140000, "Fruit" : "Banana", "Year" : 2013 }
];
chart.draw();
Changing the series from dimple.plot.bubble --> dimple.plot.line will demonstrate the behaviour.
Seems such a commonly required feature that I can't help feeling that I'm missing something obvious.
Thanks
I'm afraid you aren't missing anything it's a bug introduced in a recent version. I'll fix it in version 1.2 coming out in the next week or two. Unfortunately the breaking version was also the one which added the ability to set series specific data. If you want to work around in the meantime you'll need to go back to version 1.1.3 and set your data the old fashioned way:
var svg = dimple.newSvg("#chartContainer", 600, 400),
chart = null,
s1 = null,
s2 = null,
x = null,
y1 = null,
y2 = null,
data = [
{ "Fruit" : "Grapefruit", "Value 1" : 100000, "Year 1" : 2012, "Value 2" : 110000, "Year 2" : 2013 },
{ "Fruit" : "Apple", "Value 1" : 400000, "Year 1" : 2012, "Value 2" : 300000, "Year 2" : 2013 },
{ "Fruit" : "Banana", "Value 1" : 120000, "Year 1" : 2012, "Value 2" : 140000, "Year 2" : 2013 }
];
chart = new dimple.chart(svg, data);
x = chart.addCategoryAxis("x", "Fruit");
y1 = chart.addMeasureAxis("y", "Value 1");
y2 = chart.addMeasureAxis("y", "Value 2");
s1 = chart.addSeries("Year 1", dimple.plot.line, [x, y1]);
s2 = chart.addSeries("Year 2", dimple.plot.line, [x, y2]);
chart.draw();
http://jsfiddle.net/NVV9r/1/
I wonder how we can do the below translation from sql to mongoDB:
Assume the table has below structure:
table
=====
-----
##id contribution time
1 300 Jan 2, 1990
2 1000 March 3, 1991
And I want to find a ranking list of ids in the descending orders of their number of contributions.
'$' This is what I do using sql:
select id, count(*) c from table group by id order by c desc;
How can I translate this complex sql into mongoDB using count(), order() and group()?
Thank you very much!
Setting up test data with:
db.donors.insert({donorID:1,contribution:300,date:ISODate('1990-01-02')})
db.donors.insert({donorID:2,contribution:1000,date:ISODate('1991-03-03')})
db.donors.insert({donorID:1,contribution:900,date:ISODate('1992-01-02')})
You can use the new Aggregation Framework in MongoDB 2.2:
db.donors.aggregate(
{ $group: {
_id: "$donorID",
total: { $sum: "$contribution" },
donations: { $sum: 1 }
}},
{ $sort: {
donations: -1
}}
)
To produce the desired result:
{
"result" : [
{
"_id" : 1,
"total" : 1200,
"donations" : 2
},
{
"_id" : 2,
"total" : 1000,
"donations" : 1
}
],
"ok" : 1
}
Check the mongodb Aggregation
db.colection.group(
{key: { id:true},
reduce: function(obj,prev) { prev.sum += 1; },
initial: { sum: 0 }
});
After you get the result, sort it by sum.