I have the following collection;
Collection Property1 Property2
---------------------------------
Coll1 blue hot
Coll1 red cold
Coll1 yellow orange
Coll1 false false
Coll2 dog cat
Coll2 out in
Coll2 house car
Coll3 yellow red
Coll3 brick mortar
Coll3 winter winter
Coll3 summer summer
Coll3 ski snow
Coll3 cyan brown
How do I count how many elements that are in Coll1 (the number of collections will be dynamic so the filter also has to be)?
I guess I am looking for something like how many elements has a unique collection ID
I haven't seen a hashtable in PowerShell that would output as what you have shown in your question, but usually the way is like the following:
Get-Foo | Group-Object Collection -NoElement
Related
I need a function that collects the titles from patches and exists and print if there are 2 or more titles that contains one of the $SearchTitles. If I have 2 geo and one Dictionary I want to know about it. If I have 2 Dictionary I want to know. Just one function with 3 inputs (patches,exists.$SearchTitles)
The duplication can be found in patches or in exists or in both
The main goal here is to let the user know if there are more than one title that contains one of the $Searchstring and print the number of the patch.
For an example if 'Dictionary Update' shows in 2 patch's titles I want to print who holds this.
Currently the function combined 2 variables $patches, $exists that holds a list of numbers (I collect them from excel). and for each one of them get the title from the TFS.
I don't know how to search for $Searchstring and get the patches that holds the same title
Need to compare between all the patches only when there is duplicate of Dictionary Update or Geo Location Enrichment
$Searchstring = "Dictionary Update", "Geo Location Enrichment"
$pathesList = #($patches, $exists)
function Duplicatepatches($pathesList) {
foreach ($pathList in $pathesList) {
foreach ($patch in $pathList) {
$Title += (Get-VSTeamWorkItem -Id $patch.Patch).fields.'system.Title'
}
}
$Title
}
$patches =
Patch
-----
1315415
$exists =
Patch
-----
1301707
1292054
1293404
1295392
1298589
1296128
1308438
1310686
Assuming I have a list of objects from the type shirt, and each shirt has a color property.
Is there a way to create a rule which will get only shirts of the same color (no matter what the color is)?
You're looking for the collect function. (Link is to the Drools documentation, scroll down a bit to find "collect".) Like its name indicates, it collects things that match a condition.
Let's assume a simple class Shirt with a String color variable. Let's also assume that there are a variety of shirt instances in working memory.
rule "Collect shirts by color"
when
Shirt( $color: color )
$shirts: List() from collect( Shirt( color === $color ) )
then
// $shirts will now contain all shirts of $color
end
This rule will individually consider each shirt, and then collect all of the other shirts which have the same color. So if you have Red, Blue, and Green shirts, you'll enter the right hand side at least once with $shirts of that single color.
Of course the problem here is that you'll trigger the rule on a per-shirt basis instead of on a per-color basis. So if you have two Red shirts, you'll trigger the 'then' clause with all red shirt twice (once for each red shirt, since each red shirt will independently meet the first criteria.)
If you don't mind this, then you can use this as-is. But if you just want your consequences to fire once per shirt color, we have to be a bit more tricksy.
In order for colors to be the first class citizen, we'll need to extract the distinct set (not list!) of shirt colors, and then use those to collect our lists as needed. Here I use the accumulate function; you can read more about that at the same link I shared previously to the Drools documentation (accumulate is directly after collect.)
rule "Get shirt colors"
when
// Get all unique shirt colors
$colors: Set() from accumulate( Shirt( $color: color), collectSet( $color ))
// Get one of those colors
$color: String() from $colors
// Find all shirts of that color
$shirts: List() from collect( Shirt( color === $color ) )
then
// $shirts is all shirts of $color
end
In this second rule, you will only trigger the right hand side once per color because we started by distilling all possible colors into a distinct set of unique ones.
Doing the opposite is even simpler. If all you need to do is confirm there is at least one shirt that is not the same color, we just need to get all of the colors and verify that there's at least 2 different colors present.
rule "At least one shirt of a different color"
when
$colors: Set( size > 1 ) from accumulate(
Shirt( $color: color),
collectSet( $color )
)
then
// $colors contains more than 1 color, so there's at
// least 1 shirt present that is not the same color
// as the rest
end
I have a collection dinosaurs with documents of this structure:
doc#1:
name: "Tyrannosaurus rex",
dominantColors: [
"beige",
"blue",
"green"
]
doc#2:
name: "Velociraptor",
dominantColors: [
"green",
"orange",
"white"
]
I want to query the collection by color name (for example: green) to get documents sorted by color's position in dominantColors array. First get the documents in which green occurs higher in the array, then those in which it is lower. So, in the provided case I would get doc#2 first, then doc#1.
Each dominantColors array contains 3 elements, with elements sorted from most dominant to least.
I am looking through documentation, but am not able to find a solution. Maybe I need a different data structure altogether?
Cloud Firestore doesn't support querying arrays by ranked index. The only way you can query an array is using an array-contains type query.
What you could do instead is organize your colors using maps where the color is the key and their rank is the value:
name: "Tyrannosaurus rex",
dominantColors: {
"beige": 1,
"blue": 2,
"green": 3
}
Then you can order the query by the value of the map's property. So, in JavaScript, it would be something like this:
firebase
.collection('dinosaurs')
.where('dominantColors.green', '>', 0)
.orderBy('dominantColors.green')
I got a question, I've been searching high and low for this but cant find an answer (also my coding skills are zero to none)..
In powershell I have 2 variables, for example say $apples and $oranges.
They both contain a list of values that are not yet split and $oranges sometimes contains an empty value, like
$apples = red green blue yellow purple
$oranges = car bike chair shirt
They are in the correct order
Now what I'm trying to achieve is split the values inside the variables, but only print those values inside $apples that have a value greater than 2 characters in $oranges
So that it skips "blue" because in $oranges that spot is empty and the output in the text file would become something like this:
Apples red
Oranges car
Apples green
Oranges bike
Apples yellow
Oranges chair
Apples purple
Oranges shirt
Is there any mastermind out there that could help me?
I edited your question to make any sense, you can't set a string containing spaces to a var without quoting. I still don't know what the meaning of that sentence is.
This script:
$apples = ("red green blue yellow purple").split(' ')
$oranges = ("car bike chair shirt").split(' ')
for ($i=0;$i -le $apples.Length; $i++){
if ($oranges[$i]){
"Apples {0}" -f $apples[$i]
"Oranges {0}" -f $oranges[$i]
""
}
}
Returns this output:
> .\SO_42469662.ps1
Apples red
Oranges car
Apples green
Oranges bike
Apples yellow
Oranges chair
Apples purple
Oranges shirt
i am discovering OrientDB and i have a problem :
I have two vertex definition :
Product
Criterion
And one Edge definition:
- IsRelatedToEdge
Thanks to IsRelatedToEdge, I can link one product to many criterion
In my example, i have populated the database with 5 products
shoe-1
shoe-2
shoe-3
hat-1
hat-2
and 4 criterions :
blue
red
hat
shoe
Then I linked products with criterion this way:
shoe-1 <=> shoe
shoe-1 <=> blue
shoe-2 <=> shoe
shoe-2 <=> red
shoe-3 <=> shoe
shoe-3 <=> blue
hat-1 <=> shoe
hat-1 <=> blue
hat-2 <=> hat
hat-2 <=> red
so we have 2 blue shoe, 1 blue hat, 1 red shoe, 1 red hat.
I cannot figure out how to find all blue shoes.
EDIT : I have found a 'solution' but it doesn't looks good :
select from Product where
in('IsRelatedToEdge')[name="blue"].size() = 1 and
in('IsRelatedToEdge')[name="shoe"].size() = 1
IMO, the power of OrientDB lies in the graph abilities, and queries on a table/index do not really leverage this. I feel the best way to do this query is to get the shoe criterion, then get all of the products that have an edge to the criterion. From those products (ie all the shoes), you can now filter for ones that also have an edge to the blue criterion. One way to write this is as follows...
select *
from (select expand(both('IsRelatedToEdge')) from Criterion where name = 'Shoe')
let $blue_criterion = (select from Criterion where name = 'Blue')
where both('IsRelatedToEdge') contains $blue_criterion[0]
Taking the above thought process further though, you could consider rearranging your data for better/easier querying. For example, you could make a Hat and Shoe class that are both subclasses of Product. That way to query on shoes, you query against the Shoe vertex class only. Similarly, you can make different criterion subclass, such as Color. To get blue shoes with such a config, the query would like the following...
select *
from Shoes
let $blue_criterion = (select from Color where name = 'Blue')
where both('IsRelatedToEdge') contains $blue_criterion[0]
You could even make more specific edges to take this a step further.
After studying neRok'solutions, i came at this solutions:
select expand($result)
let
$crit1 = (select expand(out('IsRelatedToEdge')) from Criterion where name='blue'),
$crit2 = (select expand(out('IsRelatedToEdge')) from Criterion where name='shoe'),
$result = intersect($crit1, $crit2)
With this kind of query, I can add another criterion.
Imagine if we have anotehr criterion named adidas and i want to have all blue adidas shoes :
select expand($result)
let
$crit1 = (select expand(out('IsRelatedToEdge')) from Criterion where name='blue'),
$crit2 = (select expand(out('IsRelatedToEdge')) from Criterion where name='shoe'),
$crit3 = (select expand(out('IsRelatedToEdge')) from Criterion where name='adidas'),
$result = intersect($crit1, $crit2, $crit3)