60 lines
2.9 KiB
Markdown
60 lines
2.9 KiB
Markdown
Looks like I need to parse the file, process data while parsing and prepare it for fast reading.
|
|
|
|
Let's start with reading the data first.
|
|
|
|
One consideration, from the task details, I am not sure should I create a service for this,
|
|
but since it says that other components need to read from this one, looks like web service is a valid option.
|
|
I will create micro micro-service.
|
|
|
|
I will use standard web service code structure (controller, service, model).
|
|
It is not necessary in this case, but if project grow up just a bit,
|
|
it would be helpful to have clean design.
|
|
|
|
I will be using Lombok to avoid boilerplate code in controller, service and model classes.
|
|
|
|
Introducing ActivityCsvParser to read CSV file.
|
|
Having enhancement so it is not only reading CSV, but collecting activities by Case ID.
|
|
I am doing this to avoid multiple iteration through the list of parsed items.
|
|
|
|
I did intuitive way implementation with following steps:
|
|
reading activities, grouping, finding all variants and finding top variants,
|
|
but it is not performing well (takes around 150ms to finish).
|
|
|
|
After getting proper inner analysis, I noticed that ObjectMapper was taking more time than Gson
|
|
for translating object to Json string, so I replaced it.
|
|
|
|
Also, I noticed that first run is taking much more time than any following run.
|
|
That makes sense since in first run, Java is initializing all the necessary classes.
|
|
Any following run is dramatically faster. And real case scenario would be
|
|
this service to be running and other services to call it.
|
|
So I created performance test "ProcessIntelligencePTest"
|
|
where I am calling function 100 times and calculate the average time.
|
|
|
|
While looking for the best solution, I had idea to cache the response in the very beginning.
|
|
That idea make service works much better in non cached scenario,
|
|
since Java initialized all the classes necessary while running first caching method.
|
|
I will leave it, just to make performance better.
|
|
|
|
Later on, I had to remove the feature of mapping cases while reading CSV file,
|
|
since I am reading CSV file only once and use it as a database.
|
|
I am doing this to make solution according to task description.
|
|
|
|
On second thinking about solution, I would say that "component"
|
|
that would be interacting with this service might be another class,
|
|
so I am removing micro-service approach and making this solution
|
|
as a class ("ProcessIntelligence.java") to avoid over-engineering.
|
|
It is very easy to create micro-service if necessary.
|
|
|
|
I copied provided CSV file into standard Java resource folder,
|
|
where I believe it belongs, so if you want to change input data,
|
|
please use resource folder for that.
|
|
|
|
### How to run
|
|
You can run solution once, by executing command:
|
|
`gradlew run` on Windows or `./gradlew run` on Linux
|
|
|
|
### Notes
|
|
If you are changing any code, and you want to build the project (`gradlew clean build`),
|
|
please run command `gradlew spotlessApply` before building
|
|
since I am using plugin to avoid non formatted code to be pushed.
|