Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions SOLUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,62 @@ SOLUTION

Estimation
----------
Estimated: n hours
Estimated: 3 hours

Spent: x hours
Spent: 1 hour 20 min

Coment: Testing was minimal so im not sure all the edge cases are covered, i removed some data from DB to test the "n/a" requirement.

Solution
--------
Comments on your solution

Solution solves all 3 requirments given. Im sure there is a better way of doing this but it woud requirte more time to think. The main problem is the 3rd point witch requires me to "make up" data in the DB this can also be done in code with some injections to the data given by DB.

I tested the solution to folowing cases:
-clean database (as provided by default)
-inserted new user with no history
-inserted new history with no user
-inserted new user with duplicated name

Test cases
--------


Scenario: All data is avavible and properly connected (history is available)
When Business Analyst request a report
Then the script displays sum of all views on the screen in the format provided by the task

Scenario: All data is avavible and properly connected (history is available)
When Business Analyst request a report
Then the script displays sum of all views on the screen gruped by month independant of the year

Scenario: All data is avavible and properly connected (history is not available)
When Business Analyst request a report
Then the script displays sum of all views on the screen gruped by month independant of the year
And for the user with no history all the months will be summed as "n/a"

Scenario: All data is avavible but there are some views in the table with no conection to the profiles
When Business Analyst request a report
Then the script displays sum of all views on the screen gruped by month independant of the year
And the the data with no connection to the profiles will not be used in the calculations

Scenario: All data is avavible but there are some missing month for the user profile
When Business Analyst request a report
Then the script displays sum of all views on the screen gruped by month independant of the year
And the user with no history for specific month will have that month summed "n/a"

Scenario: All data is avavible and properly connected (history is available)
When Business Analyst request a report
Then the script displays sum of all views on the screen gruped by month independant of the year, grouping must be done on profile_id but displayed as profile_name as names can duplicate

Edge cases
--------
Current solution treats 0 views as "n/a", possible modifications.
Duplicated usernames

Other Notes
--------
Localy I removed all the data in january using : DELETE FROM views WHERE MONTH(date) = 1, to test the "n/a" requirement
I added a new user caled "test" and "Karl Lagerfeld"
I added a new history item with non existing profile_id
45 changes: 44 additions & 1 deletion src/Command/ReportYearlyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,54 @@ protected function execute(InputInterface $input, OutputInterface $output)
/** @var $db Connection */
$io = new SymfonyStyle($input,$output);
$db = $this->getContainer()->get('database_connection');


/*
$profiles = $db->query('SELECT profile_name FROM profiles')->fetchAll();

// Show data in a table - headers, data
$io->table(['Profile'], $profiles);
*/

$profiles = $db->query('
SELECT
`data`.`profile_name`,
IF ( SUM(Jan) != 0, SUM(Jan), "n/a") AS Jan,
IF ( SUM(Feb) != 0, SUM(Feb), "n/a") AS Feb,
IF ( SUM(Mar) != 0, SUM(Mar), "n/a") AS Mar,
IF ( SUM(Apr) != 0, SUM(Apr), "n/a") AS Apr,
IF ( SUM(Maj) != 0, SUM(Maj), "n/a") AS Maj,
IF ( SUM(Jun) != 0, SUM(Jun), "n/a") AS Jun,
IF ( SUM(Jul) != 0, SUM(Jul), "n/a") AS Jul,
IF ( SUM(Aug) != 0, SUM(Aug), "n/a") AS Aug,
IF ( SUM(Spe) != 0, SUM(Spe), "n/a") AS Spe,
IF ( SUM(Oct) != 0, SUM(Oct), "n/a") AS Oct,
IF ( SUM(Nov) != 0, SUM(Nov), "n/a") AS Nov,
IF ( SUM(`Dec`) != 0, SUM(`Dec`), "n/a") AS `Dec`
FROM(
SELECT
`profiles`.`profile_name`,
`profiles`.`profile_id`,
IF ( MONTH(date) = 1, SUM(views), 0) AS Jan,
IF ( MONTH(date) = 2, SUM(views), 0) AS Feb,
IF ( MONTH(date) = 3, SUM(views), 0) AS Mar,
IF ( MONTH(date) = 4, SUM(views), 0) AS Apr,
IF ( MONTH(date) = 5, SUM(views), 0) AS Maj,
IF ( MONTH(date) = 6, SUM(views), 0) AS Jun,
IF ( MONTH(date) = 7, SUM(views), 0) AS Jul,
IF ( MONTH(date) = 8, SUM(views), 0) AS Aug,
IF ( MONTH(date) = 8, SUM(views), 0) AS Spe,
IF ( MONTH(date) = 8, SUM(views), 0) AS oct,
IF ( MONTH(date) = 8, SUM(views), 0) AS Nov,
IF ( MONTH(date) = 8, SUM(views), 0) AS `Dec`
FROM `profiles`
LEFT JOIN `views` ON `profiles`.`profile_id` = `views`.`profile_id`
GROUP BY `profiles`.`profile_id`, MONTH(`views`.`date`)
ORDER BY `profiles`.`profile_name`
) AS data
GROUP BY `data`.`profile_name`, `data`.`profile_id`
')->fetchAll();

$io->table(['Profile',"Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Spe","Oct","Nov","Dec"], $profiles);

}
}