Selecting consecutive rows with same values and one that differs

So there is this question that explains how to do it but what I want is to find the duration from idle to active for a given userID and status for example for Brown it should show something like this:

userID        status     Duration_in_this_status (min)  ------  -------------------   ------ Brown         idle             40 Brown         idle             ? 

The ? inidcated that it is the time from this

userID  tStamp                status ------  -------------------   ------ Jason   2017-10-18 03:20:00   idle   Brown   2017-10-18 03:20:28   idle   Brown   2017-10-18 03:25:28   idle   Brown   2017-10-18 04:00:28   active     Brown   2017-10-18 04:10:28   active     -> Brown   2017-10-18 04:35:28   idle   Brown   2017-10-18 04:45:28   idle   

till now.

I tried to modify the answer from the above question but all I could managae was create a variable @next_time and increase it when the if goes to @groupNumber +1 but I couldn’t work it out because all it does it increases the year by one.

   SELECT userID, status, TIMESTAMPDIFF(minute, MIN(tStamp), MAX(tStamp)) AS  duration     FROM (        SELECT        t.*         , @groupNumber := IF(@prev_userID != userID OR @prev_status !=  status, @groupNumber + 1 and @next_time=@next_time+1, @groupNumber) AS gn     , @prev_userID := userID     , @prev_status := status     , @next_time   := tStamp     FROM t     , (SELECT @groupNumber := 0, @prev_userID := NULL, @prev_status := NULL) var_init_subquery     ORDER BY userID, tStamp ) sq GROUP BY gn, userID, statu 

So can any one help me to get that next value using these user-defined variables? Thanks

MySQL version 8.0.16

Optimising query for date based selecting

I am looking to speed up querying of records from a specific date range.

My table has millions of rows and the dates are in Unix epoch format, in text format IIRC ( i don't work weekends so can't be certain)

I am pulling in a single schedule record, which has an unique ID field attributed to it.

This ID field is recognised in a separate table called movement, and this movement field stores movement and timing data for the schedule.

Each schedule has its associated movement rows (usually…

Optimising query for date based selecting

Selecting objects to maximize value while under multiple constraints

I think it will be best to explain the problem first and then explain what I am thinking:

I have a dataset similar to the following:

fruit,calories,cost apple,100,1 apple,200,1.5 apple,150,2 pear,300,3 pear,100,.5 pear,250,2 orange,100,1 orange,120,1 orange,400,2 

And I am trying to maximize my calories while keeping my cost within a certain range. At this point it is just a knapsack problem, but what if I have to have 1 apple, 1 pear, and 2 oranges, or some other arbitrary set of fruit numbers?

I can’t really wrap my head around how this should work, given the extra constraint. I’ve thought about trying to merge my cost and calories into 1 metric somehow, but I am pretty sure that can’t work since it loses.

My most recent thought is potentially keeping track of fruit count in a list, and if the proper amount of fruit has been reached it will skip to the next fruit. I am thinking about this in a similar way to a knapsack with 3 constraints, weight, value, and size, but the size is just fruit count essentially.

Hoping someone on here can tell me if I am heading in the right direction or if there is an algorithm that does this that I can look into.

Thank you!

Hierarchical list for selecting an element

The user is trying to select an element which will be used in a form. So it could be like selecting interests in an app where you can pick the more general case (e.g. sports) or the more specific (e.g. baseball).

I have hierarchical data where:
* Exactly one node may be selected.
* Users can select nodes anywhere in the tree
* Leaf nodes must be selectable
* Parent nodes may be selectable. Selecting a parent node represents a selection of all of its leaf node descendants.
* Selectable parent nodes are uncommon.
* The depth of the data is deeper than can be readily shown on the screen all at once.

I am developing an interface for browsing this data. This data needs to be usable on both desktop and mobile interfaces on the web.

I am thinking of modeling an interface after what Apple does with hierarchical menus, like the one below. The differences in my case are primarily that:
* The items can have three states: selectable node, refinable node, and nodes with both capabilities. How do I make this look uncluttered?
* My design must operate reasonably on both desktop and mobile. How do I design the refinement signifier in an unobtrusive way that is clear even on desktop views.
* My lists have a lot of heterogenous content. This happens only rarely in Apple menus, like the shut down button in the second screenshot. How do I show heterogenous content without looking disjoint?
iOS settings menu

Notice the blue row at the bottom representing differing content.
iOS shut down screen

What I’ve been thinking of so far is similar to the Apple design. These next two screenshots show the top level of the hierarchy here, and…
Top level of hierarchy

…the screen after food is selected.
Refinement of hierarchy

I like the multi-screen approach to this design for my use case, so I am primarily looking for feedback on exactly what icons/buttons to put in, and how to separate out content. I’m particularly interested in examples on the web and high fidelity mock examples, but I’m open to lower fidelity feedback as well.

The one structural thing that I think could be changed is in the combination case where a parent node can also be selected. Conceptually I’ve illustrated it here:
Alternate design to combination case

I’d like to draw attention to the fact that this makes the rows less crowded, and seem more homogenous. But I’m not sure exactly how to design the current level selection mechanism. How could I clearly indicate that the current level can be selected? Relatedly, how do I indicate the situation where the current level can’t be selected?

Bundle Product Price is Not Updating On Product Page – near to add to cart button. When Selecting Options

I have created a bundle product with 2 options.

One option is a dropdown menu (required).

The 2nd option is a checkbox (required).

When I select my options the price in the right column is not updated.

Once added to cart the price reflected is correct.

Magento version is 2.2.7

Any ideas?

(I have overrides luma theme)

Auto populate a lookup field with multiple entries after selecting multiple entries from a lookup

Please excuse me for the vaugness, required due to the type of work.

I have a list that indicates upcoming work on various items. When the work is finished on those items, drawings need updated. As it is, I have the items showing the date that the work is finished and a lookup that lists the various work numbers being performed on that item. The work being performed affects various drawings, so I have another lookup that looks up all the drawings. I want the first lookup for the work numbers to cascade to the drawings lookup, so that when I select the work numbers, only the drawings that are affected will auto populate. I do not have access to InfoPath or SPD (my company restricted that). So, all I can do is put script in a webpart. Any ideas?

I have found script that works when the first lookup is just one item, it will then show only the items that apply in the next lookup. I can’t seem to find anything that will let me select multiple items in the first lookup and display all applicable items in the second.

Best practice for selecting multiple items in map view

I’m working on an app (touch input) in which it should be possible to select one or more items. Think about google maps: you search for ‘restaurant’ and a couple of restaurants are shown on the map, now you want to select 3 of them.

Right now I’m thinking about

  • press to view one item
  • press+hold > give feedback to the user > press to select multiple items > CTA to view items.

This is not an ideal solution and I’ll need to explain this interaction to the user at first use.

I’m wondering if someone has another idea or suggestion that is more user-friendly and intuitive?

Selecting rows in a table based on same cell values in a column and looping through the table

I have a Workbook with 2 Sheets. One Sheet is a table that gets updated every month with invoicing information and one sheet is a preset for an invoice.

I have working VBA code that takes a (manual) selection of rows and then copies the relevant information from these rows to the preset invoice in the second sheet. This then gets automatically exported as a PDF and saved to a folder.

This code/module works flawlessly. The selection of rows is based on a transaction number that is in a column. I select (manually) all rows with the same transaction number.

Now instead of manually going through the rows and selecting the relevant rows based on a transaction number and then starting the module, I’d like to automate this process.

What I have so far:

Sub PrintAll()      Dim i As Long, j As Long     Dim Arr     Dim DB As Worksheet      Set DB = Sheets("Data")      '~~> Set Range here     Arr = DB.Range("A2:X400").Value      For i = 1 To UBound(Arr, 1)         For j = 2 To UBound(Arr, 2)              If Arr(i, 7) = Arr(i + 1, 7) Then                 Arr(i, j).Select                 Call InvoiceCreator.InvoiceCreator             End If          Next j     Next i End Sub ```  The idea is to select an array based on an if statement that the values in column 7 are the same and then running the module based on the selected array. This might be completely wrong so I'm asking you guys for your experience regarding this.