Is there a pattern for choosing one of a set of options at random when their selection criteria are equal?

I want to choose between several options, and if the criteria I’m using for selection happen to be equal, I want one at random (reasonably so, so it’s equal-chance each time, rather than arbitrary). This is easily done with nested ifs, but it gets pretty ugly and ends up duplicating code.

A simplified example case, in case that’s not clear.

extern crate rand;

fn main() {
    let a = 5;
    let b = 5;

    if a > b {
        println!("Do the thing where a is bigger");
    } else if b < a {
        println!("Do the thing where b is bigger");
    } else { 
        if rand::random::<bool>() {
            // I don't want to duplicate the code here!
            println!("Do the thing where a is bigger");
        } else {
            // Or here!
            println!("Do the thing where b is bigger");
        }
    }

}

(rust playground)

Is there a better way to do this which doesn’t require duplicating code? In this simplified example I’m only choosing between two possibilities, but it could actually be a longer list. (What about acting based on the highest of a, b, c, d, where it’s possible that there’s a two, three, or four-way tie?)

I happen to be learning Rust so if there’s any clever language features that’d be cool, but I’m also interested in the general case if possible.

magento2 – Magento 2.3.5 – Data Migration – Products out of Stock Criteria (Configurable Products mostly)

Another issue regarding data migration from Magento 1.7.0.2 to Magento 2.3.5.

  • What are the conditions for products to display ‘out of stock’ in Magento 2? I am clearly missing something!

Description:

I see that all the configurable products now show ‘out of stock’ when going to the product page on Magento 2. I am unable to figure out what conditions are used for displaying ‘out of stock’.

Basically, I want to ensure that the configurable products show their simple related products in the dropdown options (Magento default themes). The options are not currently shown because of this issue.

I tried the following:

  • Checked Tables inventory_stock, inventory_stock_1, cataloginventory_stock_item, cataloginventory_stock_status, inventory_stock,cataloginventory_stock_status.
  • Only cataloginventory_stock_status has qty of 0.
  • None of the tables that use stock_status are ever set to 0, everything is always 1.
  • I even ran update quantity on cataloginventory_stock_status:

UPDATE cataloginventory_stock_status SET qty = 999999 WHERE qty = 0;

  • Refreshing after clearing cache still showing out of stock, then immediately after reindexing bin/magento indexer:reindex I check cataloginventory_stock_status again, the qty value is set back to 0!

Also:

  • I noticed that the cataloginventory_stock_status_idx table is always empty even reindexing. Is this table even used?
  • I have also tried to see the effect of Manage Stock = 0, but even then those products still show ‘Out of Stock’.

I would really appreciate a solution where I can run MySQL queries (since this is a data migration) if possible.

Thanks!

“Additional content download” requested on some higher spec android phones after reinstalling/deleting game app data- what criteria would there be?

I had two phones both fine and then something changed so that on the higher spec it has to download additional content which is a real pain as it takes at upto and over 10mins depending on network and cannot use mobile data. The older spec has no extras requested, the curious thing is the game started offering a low Res version but my low spec by default uses the standard res version.

Im wondering what it is about the low spec that tells either Google play or the app developer what the phone can handle. I need to replace the low spec due to a broken port but would like to get a faster phone which still avoids this additional content.

The game is large, CSR2 and the low spec has 2GB ram, 16GB storage (no media is stored, no extra apps besides the game so space isnt an issue) running only android 6 with no more updates only security.

Ive asked game support and all theyve said is they recommend 2GB ram or more, android4.4 or better and 3GB or more available space to play the game (nothing about this additional content).

microsoft excel – Count first cells in a range of rows, which are higher than 0 and meet criteria

For each column, I would like to count the amount of cells, which are higher than 0, appear for the first time in the row, and meet a criteria in one of the columns.

In this example, I would like to count the number of new customers for each months, the number of new customers in a specific region, and the number of customers in a specific industry.

example

Can someone help?
Thanks

mysql – SUM the rows of a table only if one row has matching criteria with the rest of the rows

Sorry if the title is a little strange, but I can hardly even explain myself about it.

I am trying to create a database of football statistics. At the moment, I have a table & # 39; boxscore & # 39; like this one:

id_boxscore  id_player  id_team  goals  fouls
-----------  ---------  -------  -----  -----
1            1          1        1      3
1            2          1        3      5
1            3          2        2      8
2            4          5        0      6
2            4          5        0      6
3            2          1        5      9
3            3          1        11     4

So, for some advanced data calculations, I need to know the team totals of the games the player has participated in. The right query should give me something like this if, for example, I select the accumulated statistics of id_player = 1:

id_player  accGoals   accFouls
---------  ---------  --------
1          4          8

Right now my request looks like this:

SELECT SUM(b.goals) FROM boxscore as b, (SELECT b.id_boxscore from boxscore as b 
WHERE b.id_player = 1) AS c WHERE b.id_boxscore=c.id_boxscore 

But gives me the accumulated statistics of the games where the player with the identifier 1 played (both of his team and of the opponent):

id_player  accGoals   accFouls
---------  ---------  --------
1          6          22

Ideas? I'm sure it's really simple but I'm at an impasse right now.

Thanks in advance!

Microsoft Excel – Classification of values ​​according to criteria, a solution?

I want to get a ranking like this ?? in this case, there are criteria and repeated names, each name must have its exclusive classification without interfering with the others under different names, a solution? Classification must be based on the value corresponding to the name, from highest to lowestenter description of image here

Show child terms of taxonomy term in display filter criteria

I have a view block, and I would like to display the child of the current taxonomy (with context filter) in the filter criteria.

For example, I have these categories of parents and this child.

-category1

–childcategory1

–childcategory2

–childcategory3

-category2

–childcategory1

Then, in the category 1 page, the only filter option that will be displayed in the category 1 page is the child1 category, the child2 category, the child3 category and not all of the available child categories.

SQL criteria – Date on the day of the fiscal year

I hope I can get this across correctly. Here is my current statement for obtaining cumulative data (based on today's date) for the past three years:

    SELECT

        getdate()                       AS Last_Refreshed
,       S.Cust#                         AS INVOICE_CUST_NO
,       S.Item#                         AS ITEM_NO
,       S."Fiscal Year"                 AS Fiscal_Year
,       S."Fiscal Month"                AS Fiscal_Month
,       SUM(S."Total Sale")             AS Total_Sales


FROM "shipping" S   

LEFT JOIN CustStats CS  
ON S.Cust#   = CS.Cust#

LEFT JOIN Calendar C  
ON S."Ship Date"   = C.CAYMD7

WHERE  CS."Master Group#" IN ('900001', '900002', '900016', '900020', '900021', '900023', '900027')  AND   S."Fiscal Year" >= '17'

AND (S."Formatted Date" BETWEEN DATEADD(yy, DATEDIFF(yy,0,DATEADD(yy, -2, GETDATE())), 0) AND DATEADD(yy, -2, GETDATE())

OR S."Formatted Date" BETWEEN DATEADD(yy, DATEDIFF(yy,0,DATEADD(yy, -1, GETDATE())), 0) AND DATEADD(yy, -1, GETDATE())

OR S."Formatted Date" BETWEEN DATEADD(yy, DATEDIFF(yy,0,DATEADD(yy, -3, GETDATE())), 0) AND DATEADD(yy, -3, GETDATE())

OR S."Formatted Date" BETWEEN DATEADD(yy, DATEDIFF(yy,0,DATEADD(yy, -0, GETDATE())), 0) AND DATEADD(yy, 0, GETDATE())
)



GROUP BY 

        S.Cust#  
,       S.Item#                       
,       S."Fiscal Year"                 
,       S."Fiscal Month" 

With this calendar table is a field called "CAFDOY" which is the fiscal day of the year for our business. Each day is in this calendar for previous years, each line identifying a fiscal day of the year. What I'm trying to do is change the code to get away from the calendar year and only use the sales data for the same number of tax days each year. Therefore, the "formatted date" of S. would only appear on fiscal day 35 in 2018 if today's date was equal to fiscal day 35.

I just can't wrap my head properly to get there via Cast or Case or whatever.

usability – What would be the criteria for successful user tests for 2FA authentication

The questions you ask are more survey oriented and that would be my method of getting the answer to the questions you are asking.

If a survey is too abrupt, just monitor the number of users who log in using 2FA, compared to those who started the process and did not finish it, those who have read the information and have not continued and those who continue to ignore the offer, then you can contact these people to understand what blockers are using to use the service.

Excel – CountIF in VBA with range defined using columns and criteria defined by cells

I am trying to convert a recorded macro script into one that will work in a loop. The code below is a subsection of a script, there are earlier variables RowCount and columnCount declared and defined using lines that are not contained in the script.

'For each column, copy distinct values and paste into origin_analysis sheet
Dim s1 As Worksheet, s2 As Worksheet, x As Long, y As Long
x = 1
y = 1
Do Until x = columnCount
Set s1 = Sheets("origin_data")
Set s2 = Sheets("origin_analysis")
s1.Columns(x).Copy s2.Columns(x)
s2.Columns(y).RemoveDuplicates Columns:=1, Header:=xlNo
Cells(6, y + 1).WorksheetFunction.CountIf(Sheets("origin_data").Range(columns(x)),Sheets("origin_analytics").Cells(6, y))
Selection.AutoFill Destination:=Range(Cells(6, y + 1), Cells(RowCount, y + 1))
x = x + 1
y = y + 2
Loop

The original recorded version of it that works once is below, it includes other formatting elements that don't worry me about this exercise. I believe the problem I have is in the cells WorksheetFunction waiting for an "=" and I don't know why.

Sub analyticsColumn()
'
' analyticsColumn Macro
'

'
Range("B6").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(origin_data!C(-1),origin_analysis!RC(-1))"
Range("B6").Select
Selection.AutoFill Destination:=Range("B6:B312")
Range("B6:B312").Select
Columns("B:B").Select
Selection.FormatConditions.AddDatabar
Selection.FormatConditions(Selection.FormatConditions.Count).ShowValue = True
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1)
    .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
    .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
End With
With Selection.FormatConditions(1).BarColor
    .Color = 2668287
    .TintAndShade = 0
End With
Selection.FormatConditions(1).BarFillType = xlDataBarFillSolid
Selection.FormatConditions(1).Direction = xlContext
Selection.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
Selection.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone
Selection.FormatConditions(1).AxisPosition = xlDataBarAxisAutomatic
With Selection.FormatConditions(1).AxisColor
    .Color = 0
    .TintAndShade = 0
End With
With Selection.FormatConditions(1).NegativeBarFormat.Color
    .Color = 255
    .TintAndShade = 0
End With
Range("B6").Select
End Sub