D
D
ddd3292019-11-26 07:24:36
Software design
ddd329, 2019-11-26 07:24:36

How can such calculations be organized?

Greetings!
At the moment, I have implemented a program for calculating some values ​​​​using formulas. Data is taken from three different sources: "Source 1", "Source 2" and "Source 3". At the checkout time, for example, at 15:00, we turn to the sources in turn, request data from them and start the calculation, after which the result is saved to the database.
There was a problem that at one source the data arrives with a delay of 2 hours, but the customer agreed that at 15:00 we would calculate the data at 13:00, but still the system does not work at 100% - always somewhere then yes, there are delays, you need to resume data, recalculate, etc.
The second version of the program was made, where I tried to implement the idea of ​​"reactivity", something similar to Excel, i.e. when the data is loaded, then dependent on them should be recalculated. But the implementation didn't turn out very well...
Now I'm thinking of making a third implementation based on events, i.e. for example, we loaded data from the first source, then we publish the event "Data from the first source was loaded for the period [from ..., to ...]" to the bus, the handler receives it, makes a calculation and publishes a new event "Such and such a value was calculated ...", another handler receives it, does its calculations and publishes a new event, and so on.
Do you think the third option is viable?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Robur, 2019-11-26
@Robur

I think yes.
Hope this really helps you.

D
Dimonchik, 2019-11-26
@dimonchik2013

it is also useful to familiarize yourself with default values
​​​​and the book "notes of the automator"

A
Anton Konovalov, 2019-11-26
@akonovalov

In banking software (and in any accounting software, perhaps) - a table is often made for the current balance in the database. Any posting, any document leads to the replenishment of this table. Of course, in the context of the specifics of the wiring, type of document, etc. That is, as a kind of meaningful intermediate result, thanks to which you can know the balances at any point in time. Not 100% sure this is exactly what you need, but think along these lines as similar questions have already been addressed by others.

S
Sergey, 2019-11-26
@begemot_sun

Your last option is essentially the same reactive approach. Why didn't he suit you?

G
grinat, 2019-11-26
@grinat

In fact, it should have been done that way from the very beginning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question