object-oriented – How to best structure my application when I want to sort a "parent" model based on a property calculated on another "child" model?

Question about OO programming, functional programming, NoSQL, SQL databases and software architecture

Hi all,

I am a mid-level self-taught programmer and am dying to get an answer to this general question about structuring my apps. Having no degree in computer science and only a few programmer friends, I have not been able to get a clear idea of ​​how "correct" or "better" it is to deal with this type of problem.

This type of pattern appears everywhere in my current application and I'm not sure what I should do. The reason is:

I have a database model that is a model of type "container" or "parent", which contains many elements that refer to it. For this, we can use a model "Road", which represents a driver's route for the day.

He has fields like:

- Created time
- Assigned driver
- Notes
- isCompleted
- isReconciled
- serviceCount

I have another database model that is the main "child" that refers to the "parent", in this case, the road. In this case, it is a "service" which represents each of the stops that the driver must perform as part of his itinerary of the day. All services of the relevant route have a reference to the route. The relevant fields of a service are:

- Route <- id referring to the 'parent' model
- Notes
- isCompleted
- isReconciled

In many of these cases, it happens that, if you change a service (the child), you want to update a "higher level" or a "summary value" in the route (the parent).

For example:

- When all services are 'complete', update the route to be 'complete'
- When all services are 'reconciled', update the route to be 'reconciled'
- If you add a service to a route, update the 'service count' on the route

Currently, to handle these kinds of things, I have functions that work normally after each relevant change of a service. This would call something like updateRouteAfterServiceIsModified. It simply updates the route after any changes to the services, to update these summary values.

However, I understand that if I took a more object-oriented approach, I might have some kind of post-backup hook or something similar, so if you change a service, the route will be updated. I can see how this could improve the code organization, but I can also see how it could get more complicated.

One of the things I've been thinking about is never calculating these summary values ​​when it comes to service changes, because they can be determined on the fly, as far as they are inferred properties or calculable. For example:

- To know if the route is complete, just check if all the services are complete
- To know if the route is reconciled, just check if all the services are reconciled
- To know the route count, simply count the number of services, as at the time you need to know

The problem in calculating this data on the fly for me is that I will usually have a list of the 'parent' item. (routes), and I want to do something like Sort by these calculated fields. If the value is not saved on the parent, I have to compute it on the fly to sort the list.

I use Mongo as a data store and aggregations on foreign fields get complicated quite quickly, as well as other relevant calculations to perform the desired sorting. This seems to be an overly complex and potentially non-evolving solution. But I'm not an expert in Mongo, so I'm not sure.

I have never used SQL, for example. PostgreSQL; I have a friend who suggested that this sort of thing is a lot easier in Postgres. Perhaps it is possible that the "normal" thing to do in this situation with Postgres never saves these summary values ​​on the parent, and calculates them simply at the time of sorting, and that Postgres does it effectively. Perhaps it is true that the code does not become rough and that it evolves well. If that's the case, although the application is primarily built, I'd consider switching to Postgres - but I've just never tried it.

In summary, I think there can be 4 possible solutions to this type of problem:

  1. Use a functional programming style and encapsulate or call functions appropriately for "child" mutations to record all desired data on the appropriate "parent" template.

  2. Use an object-oriented programming style to handle these summary / calculated values ​​by saving them to the "parent" model.

  3. It is not necessary to save these values, to calculate them on the fly, Mongo is fine, the aggregations can be very powerful, you just have to master them and build abstractions where it would be useful or simplify your code.

  4. There is no need to save these values, and the key to this process is the use of SQL, which makes sorting easier based on a computed value for a foreign field, so you have to switch over because this makes this type of process trivial.

I do not know if there is a "correct" approach to this, but my experience seems to me to be so common that I would have thought that there would be a consensus within the development community about what I should do.

Any help would be greatly appreciated, even if it was simply to direct me to resources that could be useful!

Google Sheets: Number of queries based on multiple conditions?

I have a spreadsheet that I use for my World of Warcraft guild and I ran into a wall while trying to add new features to it.

For reference, when our guild goes through the dungeons, we fairly distribute the falling objects according to a "countdown" system. That is, everyone starts at 0 and can roll dice against others 0 to try to win an item. If someone wins something, it becomes +1 and then can only roll against other +1's, so a person does not win simply because she's luckier.

So, we have a sheet that records each item that falls, who won it, where it was won and it counts for the system +1 (some items are not worth it for. to be counted). Next to the elements log, there is a query that shows what everyone else is automatically, which looks like this:

Loot Tracker
Name     Count
Jim      2
Bob      1
Liam     1
Dave     1
Luke     1

The request for this is as follows:

= QUERY (A: I, "Select D, count (E) where C =" Victrix "and G = true and A> = date" & TEXT (IF (WEEKDAY (J1,1 ) = 3, J1, J1-WEEKDAY (J1 + 4), "yyyy-mm-dd") & "& # 39; and A <= date" "& text (J1 + 8-WEEKDAY (J1 + 5) ), group "yyyy-mm-dd") & "& # 39; by order D by number (E) desc, label D "name", number (E) "number" ")

We are now at the point where people do not just roll for their own characters, but for their other specializations (something they will not use right away, but no one else will In need for their main character, what is called an "out of specification") and this must also be followed on the loot tracker.

Say I have this dataset:

 |  A         B              C      D
1|  Name      Item           +1     Spec
2|  Jim       Lorem          (✓)    MS
3|  Bob       Ipsum          (✓)    MS
4|  Jim       Dolor          (✓)    OS
5|  Liam      Sit            (✓)    MS
6|  Dave      Amet           (✓)    MS
7|  Luke      Consectetur    (✓)    OS

I've somehow needed a query, or a single formula, that will make the loot tracker work as follows:

Loot Tracker
Name     MS+   OS+
Jim      1     1
Bob      1     0
Liam     1     0
Dave     1     0
Luke     0     1

I hope that makes sense, I have no idea how I would proceed. I've tried separate query formulas on the third column here, but this has not been correctly sorted and aligned with the names. It must first be controlled by MS, then by OS.

Exchange Order – Price Calculation Based on Binance API Transactions Results

I wonder how to calculate a price (per unit) for 1 order that has been filled in 2 transactions.

The 2 trades (GET / api / v3 / myTrades):

 {'commission': '0.00002301',
  'commissionAsset': 'BNB',
  'id': 536694,
  'isBestMatch': True,
  'isBuyer': False,
  'isMaker': False,
  'orderId': 23456244,
  'orderListId': -1,
  'price': '0.01023100',
  'qty': '3.00000000',
  'quoteQty': '0.03069300',
  'symbol': 'WABIBNB',
  'time': 1573580584514},
 {'commission': '0.00019020',
  'commissionAsset': 'BNB',
  'id': 536695,
  'isBestMatch': True,
  'isBuyer': False,
  'isMaker': False,
  'orderId': 23456244,
  'orderListId': -1,
  'price': '0.01014400',
  'qty': '25.00000000',
  'quoteQty': '0.25360000',
  'symbol': 'WABIBNB',
  'time': 1573580584514})

The command: (GET / api / v3 / order):

{'clientOrderId': 'vt0wm640c8DFewafYyrqnW',
 'cummulativeQuoteQty': '0.28429300',
 'executedQty': '28.00000000',
 'icebergQty': '0.00000000',
 'isWorking': True,
 'orderId': 23456244,
 'orderListId': -1,
 'origQty': '28.00000000',
 'origQuoteOrderQty': '0.00000000',
 'price': '0.01013600',
 'side': 'SELL',
 'status': 'FILLED',
 'stopPrice': '0.01032200',
 'symbol': 'WABIBNB',
 'time': 1573580483202,
 'timeInForce': 'GTC',
 'type': 'STOP_LOSS_LIMIT',
 'updateTime': 1573580584514}

I had the habit of calculating the price by taking the cummulativeQuoteQty and divide by the executedQty, leading to 0.01015332.

But honestly, I've never been so sure of that and now I've seen that TabTrader is priced 0.010187.

So my question is now: how to proceed if the price was to be used to calculate a profit?

PS Taking the weighted quantity of prices in the trades leads to another different value:

ipdb> weigted_price_from_trades = (0.01023100 * 3 + 28 * 0.01014400) / 28.

How can I prevent renaming arguments based on[{…},…] to make colored spherical harmonics plots by phase

I'm trying to draw a spherical harmonics colored per phase.

for example.

psi[l_, m_] := SphericalHarmonicY[l, m, [Theta], [Phi]]
sphWithPhase[f_] := 
 SphericalPlot3D[Abs[f]^2, {[Theta], 0, Pi}, {[Phi], 0, 2 Pi}, 
  ColorFunction -> 
   Function[{x, y, z, [Theta], [Phi], r}, Evaluate[Hue[Arg[f]]]], 
  PlotRange -> All, ColorFunctionScaling -> False]
sphWithPhase[psi[1, -1]]

But it does not work. TracePrint shows that Function [] renames its arguments so that theta and phi do not match the traced variables.

Whereas, for example

SphericalPlot3D[Abs[psi[1, 1]]^2, {[Theta], 0, Pi}, {[Phi], 0, 2 Pi}, 
 ColorFunction -> 
  Function[{x, y, z, [Theta], [Phi], r}, 
   Evaluate[Hue[Arg[psi[1, 1]]]]]]

it works.

Can any one help me explain that, I find the help pages confusing?

Thank you.

t sql – Database Compatibility Level Based on SQL Server Version

We need to look for databases whose compatibility level is incorrect for a given instance. For example, on a SQL Server 2016 instance, if there are databases whose compatibility level is not 130, we must list them. Similarly, on SQL Server 2017, if there are databases whose compatibility level is not 140, we must list them.

The script will be useful.

Number Theory – Has anyone studied spaces based on the number of centers that circles have on them?

It's been a while since I'm far from math so be nice if it is not very rigorous or if I redefined objects already defined. The essential question that brought me to this was the following. In the plan, each circle has a center. On the surface of the sphere, each circle has two centers. Ok, so let's formalize this notion.

Let $ (X, d) $ to be a metric space and let $ C_r (x) = {y in mathbb {R} ^ n | d (x-y) = r } $. Let $ D subseteq mathbb {R} $ be the set of all the distances between two points of $ X $. Then consider the following function:

$$ f: X times Rightarrow P (X) $$

$$ (x, r) mapsto {z in X | exists in D text {with} C_s (z) = C_r (x) } $$

We know that $ x in f (x, r), forall (x, r) in X times D $. So, this set is never empty and contains the point of origin. It is also reflexive in the sense that if $ y in f (x, r) $ for some people $ r in D $ then $ x in f (y, s) $ for some people $ s in D $. It would be nice if we could make an equivalence relationship. It can be said that a metric space $ (X, d) $ is ordinary if $ f (x, r) = f (x, s) forall r, s in mathbb {D} $. For a regular space $ (X, d) $ we can define the following equivalence relation:

$$ x sim y ssi exists, s in D text {with} C_r (x) = C_s (y) $$

Let's go back to our examples:

a) $ mathbb {R} ^ n $ with the metrics induced by everything $ mathbb {L} _p $ standard. Each equivalence class contains only the point itself.

b) The surface of a sphere with the distance "shortest path on the surface". Equivalence classes are sets of antipodal points.

c) a cone. I believe the center of the base and the vertex of the cone belong to the same class of equivalence, while each other point belongs to its own class.

We can say that a regular metric space is uniform if each class of equivalence is of equal size. For a regular uniform metric space, we can call the size of the equivalence class the degree of that. Thus, the first two examples would be regular uniform metric spaces, while the third would be regular but not uniform. The degree of $ mathbb {R} ^ n $ would be 1, while the degree of the surface of the unit sphere would be 2.

Here are some obvious questions that I have not found answers to.

  1. Are there any other regular non-trivial regular metric spaces?

  2. Can we find a regular metric space for each degree $ n $?

  3. What can we say about p-adic numbers $ mathbb {Q} _p $? They would not be regular in the sense above. Consider for example the set of points that are the distance 1 to 0. All other numbers will then be a center of these numbers. We can make the same argument for the set of points that are distance $ frac {1} {p} $ from 0. If it's an equivalence relation, then from the above to the sets, we should get all the points are in the same class of. ;equivalence. But looking at the points game with the distance 1 to 0, we see that these points are not the center of his own game, as for example $ | 5 | _3 = $ 1 and $ | 2 | _3 = $ 1 But $ | 5-2 | _3 neq 1 $. But I guess they're uniform.

  4. What can we say about the surface of $ S ^ n $? What can we say about a torus? A torus of the genus 2? etc.

  5. Are there equivalent definitions of uniformity or regularity?

  6. Is there any other condition than the regularity that would make this notion a class of equivalence?

  7. What can we say about the set of spaces on which this notion is a class of equivalence?

confidentiality – Have projects already been put in place to create a stable directory that is not based on a transparent blockchain?

Stablecoins have similar use cases to Makerdao CDP Dai, as does a room for privacy protection like Monero. But is there a project combining these 2 technologies to create a private stablecoin where you can not see the amounts sent and where and from where they come from?

Formulas – Mobile lines of Google form responses to a new sheet based on a specific answer in a column

I have a Google form that collects the answers of a Google form. According to the answers in column C (Col3), I would like the entire line to be imported into a completely different Google sheet.

I imagined a formula that moves only the first line, but the following lines that are submitted in my form and that meet my criteria are not imported.

Here is the current formula:

= Request (IMPORTRANGE ("1W9pMF4qrQM5VMN9ST47HYyvpj0iT9ls9_KwZVwxV0Y", "Form responses! A2: M100"), "select Col1, Col2, Col3, Col4 where Col4 =" BMS "", 1)

What should I do for this to continue adding the submitted data in the following lines?

[EU/FR] CPanel Reseller based on cloud⚡100% NVMe⚡CloudLinux⚡LiteSpeed⚡FREE Auto Transfers⚡20% off !!

R9HOST, reliability 9x

R9Host provides high performance, reliable and fast hosting solutions since 2014 and performance is its priority. Our main goal is to continually improve the performance, reliability and usability of our hosting service, while keeping them affordable and profitable.

SSD cPanel Reseller Features
✓ Last material
✓ Powered by HA compatible cloud
✓ Super fast SSD-NVMe drives
✓ Latest version of cPanel
✓ Last CloudLinux kernel
✓ LiteSpeed ​​Web Server
✓ Choice of several versions of PHP
✓ Choice of several versions of Node.JS NEW

✓ Softaculous 1-Click Installer
✓ LiteSpeed ​​Cache for WordPress
✓ Unlimited MariaDB databases
✓ Unlimited subdomains, parked domains, email accounts and FTP
✓ Valid unlimited SSL certificate FREE
✓ CloudFlare FREE
✓ FREE and unlimited automated account transfers NEW

✓ On sale activated
✓ private name servers
✓ cPanel / WHM in white label
✓ 20Gbps DDoS Protected Servers
✓ The best European data centers with low network latency
✓ 99.99% uptime guarantee
✓ 30-day money back guarantee
✓ Phone, ticket and live chat support

Are you going to a better host?

Using our new migration tool, you can migrate all your accounts and entire reseller with our one-click migration, which is immediately accessible from your client area. The tool recovers all accounts under your reseller account with another host and automatically transfers them to our servers. This saves time for migration and allows you to continue your business seamlessly and effortlessly.

Amazing Reseller Plans SSD

Basic SSD Reseller

10 GB of SSD storage
10 cPanel accounts
Unlimited monthly traffic
$ 4.99 $ 3.99 Monthly
Order now >>

Standard SSD Reseller

25 GB of SSD storage
20 cPanel accounts
Unlimited monthly traffic
€ 8.99 $ 7.19 Monthly
Order now >>

Advanced SSD Reseller

40 cPanel accounts
Unlimited monthly traffic
$ 16.99 $ 13.59 Monthly
Order now >>

Ultimate SSD Reseller

80 cPanel accounts
Unlimited monthly traffic
$ 29.99 $ 23.99 Monthly
Order now >>

Save 20% automatically by clicking on the order links above.

See all plans and features at https://www.r9host.com/ssd-reseller-hosting/

Payment method accepted: PayPal, All major credit / debit cards
Note: For security reasons, we do not accept bitcoin.

We will be happy to hear your feedback on our plans and prices, https://www.facebook.com/r9host/

You have a question?

Contact us via live chat or send a ticket to the address https://my.r9host.com
Call us on +44 (0) 208 089 3387

Grow your business over a hassle-free platform!