MongoDB running sum over 3 days per ID

I have the following json file (small sample) which consists of purchase records of 4 different customers across different dates. I am required to use MongoDB/nosql to identify which customers have made at least a total of 8 new purchases over a consecutive period of 3 days.

In this case, customer ABC made 32 total purchases from 2020-05-01 to 2020-05-03 (3 consecutive days). Customer GHI also had 20 purchases from 2020-07-28 to 2020-07-30 (3 consecutive days). So my output should only contain customers ABC and GHI. What would be the code to get the output? Many thanks!

{"cust_id":"ABC", "date":"2020-05-01", "new_purchase":2},  {"cust_id":"ABC", "date":"2020-05-02", "new_purchase":16},  {"cust_id":"ABC", "date":"2020-05-03", "new_purchase":14},  {"cust_id":"ABC", "date":"2020-05-04", "new_purchase":0},  {"cust_id":"ABC", "date":"2020-05-05", "new_purchase":5},  {"cust_id":"DEF", "date":"2020-05-11", "new_purchase":3},  {"cust_id":"DEF", "date":"2020-05-12", "new_purchase":0},  {"cust_id":"DEF", "date":"2020-05-13", "new_purchase":0},  {"cust_id":"DEF", "date":"2020-05-14", "new_purchase":0},  {"cust_id":"DEF", "date":"2020-05-15", "new_purchase":1},  {"cust_id":"GHI", "date":"2020-07-28", "new_purchase":0},  {"cust_id":"GHI", "date":"2020-07-29", "new_purchase":3},  {"cust_id":"GHI", "date":"2020-07-30", "new_purchase":17},  {"cust_id":"GHI", "date":"2020-07-31", "new_purchase":0},  {"cust_id":"GHI", "date":"2020-08-01", "new_purchase":1},  {"cust_id":"JKL", "date":"2020-06-04", "new_purchase":7},  {"cust_id":"JKL", "date":"2020-06-05", "new_purchase":0},  {"cust_id":"JKL", "date":"2020-06-06", "new_purchase":0},  {"cust_id":"JKL", "date":"2020-06-07", "new_purchase":0},  {"cust_id":"JKL", "date":"2020-06-08", "new_purchase":0},  {"cust_id":"JKL", "date":"2020-06-08", "new_purchase":2} 

Does an out-of-sight creature affected by the Fear spell have to keep running if they fail the saving throw?

Imagine a (D&D 5e) spellcaster casts Fear on an enemy, and the enemy fails their Wisdom saving throw. On its turn, the enemy drops what it’s holding and takes the Dash action, running away from the spellcaster and around a corner, putting it out of sight of the spellcaster. The enemy ends its turn out-of-sight of the spellcaster, so it can make the Wisdom saving throw again; again, it fails. On its next turn does the enemy have to continue running away? Even though it’s out of sight of the spellcaster? My reading of the spell is yes: they have to continue to run away until they succeed on the save (or the spellcaster drops the spell for some other reason). Is this right, or can the enemy remain in place out-of-sight? (They obviously can’t approach closer to the spellcaster because they’re affected by the frightened condition.)

Is it normal to be running out of spells?

I’ve just started playing D&D with a group, this is my first campaign for everyone in the group. I’m playing an elf Wizard and I feel like I’m struggling with attacks, and am not sure if I’m missing something. I’ve essentially 2 means of attack:

  1. Shortsword – but I need to be in close, and have little HP so use very infrequently.
  2. Spells – I’ve been using some spells, but I find that I quickly run out of spell slots. I’ve just leveled up to level 2 which helps but I’m quite quickly down to cantrips (of which I believe I’ve got 1 ranged attack – ray of frost).

So I quickly find myself in a predicament. I can just keep on ray of frosting monsters, or risk the chance of dying in close combat. Is this pretty typical, or have I missed something?

I should add that I’m hoping to buy a longbow at some point (but I couldn’t afford one last time we were at a shop) and in the current campaign we’ve had 3 encounters so far and will be continuing the next session straight from this one so I don’t have a chance for a long rest.

Finding the worst case running time of this piece of code?

I am working with this code:

function strange (list a[0..n-1] of integers such that abs(a[i]) ≤ n for every 0 ≤ i ≤ n - 1, list b[0..2n] of zeroes)  for i ← 0 to n - 1 do        a[i] ← a[i] + n for i ← 0 to n - 1 do        for j ← 0 to abs(a[i] - 1) do                b[j] ← b[j] + 1 return b 

I am trying to figure out the worst running time for the code above and so far I’m guessing that the first for loop will run n times, but not sure how to prove this. For the second and third for loop, I’m unsure how to approach this. If possible, could someone help me solve this?

Running PHP echo $_SERVER [‘DOCUMENT_ROOT’]; Shows Apache Default Path

Trying to get set up and running on a new hosting company after the old one announced they are discontinuing their service at the end of the year, I am having difficulty getting the sites to run. I narrowed it down to Apache’s DocumentRoot for each domain showing the Apache default path rather than showing the path to the individual site’s file location. In other words, when I run echo $ _SERVER ['DOCUMENT_ROOT']; in a test script, it shows the path as /etc/apache2/htdocs when it should show /home/username/public_html/domain.com. They seem unable to fix it so can DocumentRoot be changed through cPanel for each domain?

Difficulty understanding the use of arbitrary function for the worst case running time of an algorithm

In CLRS the author said

"Technically, it is an abuse to say that the running time of insertion sort is $ O(n^2)$ , since for a given $ n$ , the actual running time varies, depending on the particular input of size $ n$ . When we say “the running time is $ O(n^2)$ ,” we mean that there is a function $ f(n)$ that is $ O(n^2)$ such that for any value of $ n$ , no matter what particular input of size $ n$ is chosen, the running time on that input is bounded from above by the value $ f(n)$ . Equivalently, we mean that the worst-case running time is $ O(n^2)$ . "

What I have difficulties understanding is why did the author talked about an arbitrary function $ f(n)$ instead of directly $ n^2$ .

I mean why didn’t the author wrote

"When we say “the running time is $ O(n^2)$ ,” we mean that for any value of $ n$ , no matter what particular input of size $ n$ is chosen, the running time on that input is bounded from above by the value $ cn^2$ for some +ve $ c$ and sufficiently large n. Equivalently, we mean that the worst-case running time is $ O(n^2)$ ".

I have very limited understanding of this subject so please forgive me if my question is too basic.