Skip to content

Instantly share code, notes, and snippets.

@sherdim
Created November 16, 2017 15:20
Show Gist options
  • Save sherdim/d57f091b19605a4a4f1bde1d1637e060 to your computer and use it in GitHub Desktop.
Save sherdim/d57f091b19605a4a4f1bde1d1637e060 to your computer and use it in GitHub Desktop.
Vacancy calculator / Калькулятор отпуска
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"import locale\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'ru_RU.UTF-8'"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"locale.setlocale(locale.LC_TIME, 'ru_RU.UTF-8')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"dolzhnost = 'доцент'\n",
"n = 56 if dolzhnost == 'доцент' else 28\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Найдем первый понедельник сентября."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(Timestamp('2018-09-03 00:00:00'), 'Monday')"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"year = pd.Timestamp.now().year+1\n",
"ddSeptember = pd.DatetimeIndex(freq='d',start=pd.datetime(year,9,1), end=pd.datetime(year,9,30))\n",
"dwork = ddSeptember[ddSeptember.weekday == 0][0]\n",
"dwork, dwork.weekday_name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Пятница накануне - последний день каникул."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(Timestamp('2018-08-31 00:00:00'), 'Friday')"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dlast = dwork - pd.Timedelta(3,'d')\n",
"dlast, dlast.weekday_name"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(Timestamp('2018-07-06 00:00:00'), Timestamp('2018-08-31 00:00:00'))"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dfirst = dlast - pd.Timedelta(n,'d')\n",
"dfirst, dlast"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"см. http://strftime.org"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('Пт.', 'Пятница')"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dfirst.strftime('%a'), dlast.strftime('%A')"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Отпуск в 2018 году: с 06.07 по 31.08\n"
]
}
],
"source": [
"print('Отпуск в {} году: с {:%d.%m} по {:%d.%m}'.format(year, dfirst, dlast))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
},
"toc": {
"colors": {
"hover_highlight": "#DAA520",
"running_highlight": "#FF0000",
"selected_highlight": "#FFD700"
},
"moveMenuLeft": true,
"nav_menu": {
"height": "12px",
"width": "252px"
},
"navigate_menu": true,
"number_sections": false,
"sideBar": true,
"threshold": 4,
"toc_cell": false,
"toc_section_display": "block",
"toc_window_display": false,
"widenNotebook": true
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment