Closed Vincent-SD closed 2 years ago
Thanks @Vincent-SD !
RE: Dictionaries, Lists and types
public Dictionary<string, Dictionary<int, object>>
to public Dictionary<string, List<string>>
then (this is what you propose here, right?).RE: Logging "We could create only one string to log into csv and sql. The string could be formatted as following: "value11;value12;value13\nvalue21;value22;value23\n""
Dictionary<string, List<string>>
and raw string - and the phase out the Dictionary later, if we discover that we have no use case for it anymore.When adapting the php file to the new format, we can create a different URL, e.g. logtodbV2021.php
- and keep backwards compatibility this way (for a period, both logging formats might be in use while we transition apps).
"If we log all the data to csv and sql at the end, we could create an asynchronous process to make it faster."
RE: Refactoring "We could put all the code about logging into LogCollection "
RE: Dictionaries, Lists and types
"This sounds like a good step 1. Let's convert public Dictionary<string, Dictionary<int, object>>
to public Dictionary<string, List<string>>
then (this is what you propose here, right?)."
RE: Logging
"As a starting point, maybe we can log to both Dictionary<string, List<string>>
and raw string - and the phase out the Dictionary later, if we discover that we have no use case for it anymore."
"Are you thinking it will be faster because we can use multi-threading here? Or do you mean, that it will feel faster because we don't block the main loop (e.g. so we can show a progress bar)?"
I don't now if it is really possible, but it could be a good approach to optimize the system. We could also increase the number of threads depending on the size of the dictionary.
RE: Refactoring
Here are the functions that will be in the LoggingManager. Actually, the functions will be almost the same, we will just change what happens in these functions. The idea is just to organize the code to make it more readable.
We could rename the LogCollection class into LogWritter or something like this.
RE: Logging I agree, so let's log in the dictionary as before and also log to a formatted string as explained in the issue ? ("value11;value12;value13\nvalue21;value22;value23\n") Sounds good.
Both in fact. If we use multi threading to create the "big string" from the dictionary, we could.. Cool. Let's keep this as a backup solution, in case creating the "big string" on the fly affects performance too much.
RE: Refactoring
Looks good. But we could still let users send data to Logging Manager in any format (object
) and we could parse it to a string when storing it in LogCollection. Just so users can continue to pass float, int
etc to the logging manager. This way we can always ensure that numbers are properly formatted with decimals, e.g. always use 4.123
and never to 4,123
(this commonly happened in danish computers) etc.
In terms of delegating responsibility, here is my proposal:
let me know if you have questions about it, or counter proposal :-)
Test in the following applications:
Before we start updating the Logging Manager, let's discuss a few things.
Optimization
Dictionaries, Lists and types
Sometimes, in the code, dictionaries with Integers as key are used. Maybe we could use Lists instead.
Lists in C# keep the order and we don't have to get one specific element. We only need to iterate over the data and save it to a file or create a string, so I think a list is suitable for this purpose.
For instance, this line :
could be replaced by this :
Data type
The data is currently saved in memory as objects. We could probably save this data directly as strings, it will prevent the program from converting it later when logging to csv or sql.
Logging
Now, we are logging data over time using a dictionary. Each time we log a line, we only add it to the dictionary. There are several potential features that we can discuss here (with the ability to enable/disable features):
Refactoring
We could put a lot of code directly in the LogCollection class to organize the manager better. I think that the manager only have to be the interface between the user and the logger.