Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tasks solved #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Tasks solved #1

wants to merge 2 commits into from

Conversation

kasimjan
Copy link

No description provided.

Copy link
Member

@rabbl rabbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kassymzhan, thank you for working on our Test-Task and providing us your approach. For us it is essentially important to give you a valuable feedback regarding your code to solve the task.

First of all, your solution fulfills all requirements. You have solved the task in time and you have worked with the hints we gave you. The navbar is in place and works as expected and you have added the functionality correctly.

I have made some comments and provided some improvements which are (in my opinion) making the code more readable, maintainable and easier to test (when units tests would be in place).

If you want you can comment or improve your solution with my hints.

Thank you,
Ralf

@@ -10,10 +10,11 @@
"@types/node": "^16.18.12",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.10",
"dayjs": "^1.11.7",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to use a date-library!

src/App.tsx Outdated
let month = test.getMonth();
test.setDate(test.getDate() + 1);
return test.getMonth() !== month;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is a nice helper function to get the last day of the month.
The calculation is also a valuable approach to get the las day of the month.

I'd use this method more generic, to get the last day of the selected timespan.
So you can save some lines of code and tests further down.

I'd go with something like this:

const isLastDayOf = (dateString: string, dateResolution: IDateResolution) => {
        if (dateResolution === 'daily') {
            return true;
        }

        if (dateResolution === 'weekly') {
            return dayjs(dateString).format('d') === '0';
        }

        return ...
};

and also there is a nice approach dayjs offers you to compare against the last day of month:


dayjs(dateString).format('DD') === dayjs(dateString).endOf('month').format('DD');

src/App.tsx Outdated
import './App.css';
import FileUploader from "./components/FileUploader";
import Papa from "papaparse";
import TableView from "./components/TableView";
import ChartView from './components/ChartView';
const dayjs = require('dayjs')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import is more useful here:

import dayjs from "dayjs";

src/App.tsx Outdated
import './App.css';
import FileUploader from "./components/FileUploader";
import Papa from "papaparse";
import TableView from "./components/TableView";
import ChartView from './components/ChartView';
const dayjs = require('dayjs')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To not redefine the date-resolution again and agin I'd go for a new type here:

type IDateResolution = 'daily' | 'weekly' | 'monthly';

src/App.tsx Outdated
const [data, setData] = useState<IDataShape[]>([]);
const [sortBy, setSortBy] = useState<'daily' | 'weekly' | 'monthly'>('daily')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new type you can use directly here:

    const [sortBy, setSortBy] = useState<IDateResolution>('daily');

src/App.tsx Outdated
sun: 0,
}

if (sortBy === 'weekly') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you early return, this line is not needed anymore

src/App.tsx Outdated
// @ts-ignore
weather[data[i].weather] += 1

if (week_day === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can use the isLastDayOf function from the top.

if (isLastDayOf(data[i].date, sortBy)) {

src/App.tsx Outdated
weather.fog = 0;
}
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else and all after this can be removed now.

weather.fog = 0;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until here!

src/App.tsx Outdated
}
} else {
for (let i = 0; i < data.length; i++) {
total_days += 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen there is a last empty line which has invalida data, so I vaildated this here and checked if it is an empty string.

            if (0 === data[i].date.length) {
                continue;
            }

@kasimjan
Copy link
Author

kasimjan commented Feb 20, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants