{
"cells": [
{
"cell_type": "markdown",
"id": "unsigned-pocket",
"metadata": {},
"source": [
"# Tzolk’in Calendar\n",
"\n",
"For more information, visit the [Github project page](https://github.com/Release-Candidate/tzolkin-calendar)\n",
"\n",
"Convert gregorian dates to Tzolk’in dates and search for the gregorian dates of a Tzolk’in date.\n",
"\n",
"## To see the Interactive Elements\n",
"\n",
"Go to the menu and select **Kernel** -> **Restart & Run All** (or **Kernel** -> **Restart Kernel and Run All Cells...**)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "chicken-billy",
"metadata": {},
"outputs": [],
"source": [
"# needed for the HTML (Javascript) to hide all input cells.\n",
"from IPython.display import HTML"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "native-jamaica",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"The Python code of this notebook is by default hidden.\n",
"To toggle on/off the raw code, click here."
],
"text/plain": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"HTML('''\n",
"\n",
"The Python code of this notebook is by default hidden.\n",
"To toggle on/off the raw code, click here.''')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "cardiovascular-netherlands",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"# These are needed for the interactive widgets used in this notebook.\n",
"from ipywidgets import interact, fixed\n",
"import ipywidgets as widgets\n",
"\n",
"# Python date objects and functions.\n",
"import datetime"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "dimensional-tablet",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"# The Tzolk’in package.\n",
"import tzolkin_calendar\n",
"\n",
"# The module holding the Tzolk’in class `Tzolkin`.\n",
"from tzolkin_calendar import tzolkin"
]
},
{
"cell_type": "markdown",
"id": "synthetic-bridge",
"metadata": {},
"source": [
"## Gregorian to Tzolk’in Converter\n",
"\n",
"Select a date by clicking the calendar icon or writing it into the field.\n",
"The Tzolk’in date of this day is displayed below the field."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "endless-airplane",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "eb3a7907861a47ad8b894200fbe20ea5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(DatePicker(value=datetime.date(2021, 3, 24), description='Pick a Date'), Output()), _dom…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"interact(\n",
" tzolkin.Tzolkin.fromDate,\n",
" date=widgets.DatePicker(\n",
" description='Pick a Date',\n",
" disabled=False,\n",
" value=datetime.date.today()\n",
" )\n",
");"
]
},
{
"cell_type": "markdown",
"id": "romantic-norman",
"metadata": {},
"source": [
"## Search Tzolk’in Dates\n",
"\n",
"Select a Tzolk’in date using the two sliders and you get a list of gregorian dates of days with this Tzolk’in date."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "efficient-timber",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "080e8ce8be764176b634771f05feebad",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(IntSlider(value=1, description='Day Number:', max=13, min=1), SelectionSlider(descriptio…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def new_tzolkin(number, name_str):\n",
" date_list_next = tzolkin.Tzolkin(number=number, name_str=name_str).getNextDateList(list_size=90)\n",
" date_list_last = tzolkin.Tzolkin(number=number, name_str=name_str).getLastDateList(list_size=90)\n",
" date_list = date_list_last + date_list_next\n",
" date_list.sort()\n",
" \n",
" for idx in range(0, len(date_list), 9):\n",
" print(\"{date1} {date2} {date3} {date4} {date5} {date6} {date7} {date8} {date9}\".format(\n",
" date1=date_list[idx].strftime(\"%d.%m.%Y\"),\n",
" date2=date_list[idx+1].strftime(\"%d.%m.%Y\"),\n",
" date3=date_list[idx+2].strftime(\"%d.%m.%Y\"),\n",
" date4=date_list[idx+3].strftime(\"%d.%m.%Y\"),\n",
" date5=date_list[idx+4].strftime(\"%d.%m.%Y\"), \n",
" date6=date_list[idx+5].strftime(\"%d.%m.%Y\"),\n",
" date7=date_list[idx+6].strftime(\"%d.%m.%Y\"),\n",
" date8=date_list[idx+7].strftime(\"%d.%m.%Y\"),\n",
" date9=date_list[idx+8].strftime(\"%d.%m.%Y\"),\n",
" )\n",
" )\n",
" \n",
" \n",
"interact(\n",
" new_tzolkin, \n",
" name_str= widgets.SelectionSlider(\n",
" options=tzolkin_calendar.day_names.values(),\n",
" value='Imix',\n",
" description='Day Name',\n",
" disabled=False,\n",
" continuous_update=True,\n",
" orientation='horizontal',\n",
" readout=True\n",
" ), \n",
" number=widgets.IntSlider(\n",
" value=1,\n",
" min=1,\n",
" max=13,\n",
" step=1,\n",
" description='Day Number:',\n",
" disabled=False,\n",
" continuous_update=True,\n",
" orientation='horizontal',\n",
" readout=True,\n",
" readout_format='d'\n",
" )\n",
");\n"
]
},
{
"cell_type": "markdown",
"id": "diagnostic-voice",
"metadata": {},
"source": [
"## Search Tzolk’in Dates and Filter\n",
"\n",
"Select a Tzolk’in date using the two sliders and you get a list of gregorian dates of days with this Tzolk’in date.\n",
"In the field `Filter` you can add a part of a date to filter the output. \n",
"\n",
"E.g. \"2021\" only shows results in the year 2021"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "controlling-audit",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "be6f3932750f47e792fe5360813cb328",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(IntSlider(value=1, description='Day Number:', max=13, min=1), SelectionSlider(descriptio…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def new_tzolkin2(number, name_str, filter_str):\n",
" date_list_next = tzolkin.Tzolkin(number=number, name_str=name_str).getNextDateList(list_size=100*9 + 1)\n",
" date_list_last = tzolkin.Tzolkin(number=number, name_str=name_str).getLastDateList(list_size=300*9)\n",
" date_list = date_list_last + date_list_next[1:]\n",
" date_list.sort()\n",
" \n",
" \n",
" if filter_str != \"\":\n",
" date_str_list = []\n",
" for date in date_list:\n",
" if date.strftime(\"%d.%m.%Y\").find(filter_str) != -1:\n",
" date_str_list.append(date)\n",
" for date in date_str_list:\n",
" print(date.strftime(\"%d.%m.%Y\"))\n",
" else:\n",
" for idx in range(0, len(date_list), 9):\n",
" print(\"{date1} {date2} {date3} {date4} {date5} {date6} {date7} {date8} {date9}\".format(\n",
" date1=date_list[idx].strftime(\"%d.%m.%Y\"),\n",
" date2=date_list[idx+1].strftime(\"%d.%m.%Y\"),\n",
" date3=date_list[idx+2].strftime(\"%d.%m.%Y\"),\n",
" date4=date_list[idx+3].strftime(\"%d.%m.%Y\"),\n",
" date5=date_list[idx+4].strftime(\"%d.%m.%Y\"), \n",
" date6=date_list[idx+5].strftime(\"%d.%m.%Y\"),\n",
" date7=date_list[idx+6].strftime(\"%d.%m.%Y\"),\n",
" date8=date_list[idx+7].strftime(\"%d.%m.%Y\"),\n",
" date9=date_list[idx+8].strftime(\"%d.%m.%Y\"),\n",
" )\n",
" )\n",
"\n",
" \n",
" \n",
" \n",
"interact(\n",
" new_tzolkin2, \n",
" name_str= widgets.SelectionSlider(\n",
" options=tzolkin_calendar.day_names.values(),\n",
" value='Imix',\n",
" description='Day Name',\n",
" disabled=False,\n",
" continuous_update=True,\n",
" orientation='horizontal',\n",
" readout=True\n",
" ), \n",
" number=widgets.IntSlider(\n",
" value=1,\n",
" min=1,\n",
" max=13,\n",
" step=1,\n",
" description='Day Number:',\n",
" disabled=False,\n",
" continuous_update=True,\n",
" orientation='horizontal',\n",
" readout=True,\n",
" readout_format='d'\n",
" ), \n",
" filter_str=widgets.Text(\n",
" value='01.01.',\n",
" placeholder='Filter',\n",
" description='Filter',\n",
" disabled=False\n",
" )\n",
");"
]
},
{
"cell_type": "markdown",
"id": "destroyed-formation",
"metadata": {},
"source": [
"This Notebook is licensed under the MIT license, see [LICENSE](https://github.com/Release-Candidate/tzolkin-calendar/blob/main/LICENSE)\n",
"© Roland Csaszar 2021"
]
}
],
"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.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}