Add parser for whole trainings notes data
This commit is contained in:
parent
3aac4e760f
commit
a5a8f7295f
8 changed files with 1192 additions and 34 deletions
|
|
@ -7,14 +7,15 @@ from obsidian.py_models import Approach, Exercise, Training
|
||||||
from apple.mapper import unique_apple_exercises_mapper
|
from apple.mapper import unique_apple_exercises_mapper
|
||||||
|
|
||||||
current_directory = os.path.dirname(os.path.abspath(__file__))
|
current_directory = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
PROJECT_ROOT_DIR = os.getcwd()
|
||||||
|
|
||||||
|
|
||||||
def get_current_path():
|
def get_current_path():
|
||||||
return current_directory
|
return os.path.join(PROJECT_ROOT_DIR, "data")
|
||||||
|
|
||||||
|
|
||||||
def get_obsidian_examples_file(example_file_name: str):
|
def get_obsidian_examples_file(example_file_name: str):
|
||||||
return os.path.join(get_current_path(), f"examples/{example_file_name}")
|
return os.path.join(get_current_path(), f"{example_file_name}")
|
||||||
|
|
||||||
|
|
||||||
def read_example_file(example_file_name: str):
|
def read_example_file(example_file_name: str):
|
||||||
|
|
@ -105,7 +106,7 @@ def parse_training_exercises(exercise_line: str) -> Exercise:
|
||||||
|
|
||||||
|
|
||||||
def parse_training_data():
|
def parse_training_data():
|
||||||
training_data: str = filter_training_data(read_example_file("full.txt"))
|
training_data: str = filter_training_data(read_example_file("apple.md"))
|
||||||
lines = training_data.splitlines()
|
lines = training_data.splitlines()
|
||||||
current_training = None
|
current_training = None
|
||||||
trains = []
|
trains = []
|
||||||
|
|
|
||||||
1127
data/apple.md
Normal file
1127
data/apple.md
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,3 @@
|
||||||
# ToDo's
|
|
||||||
#ToDo/Refactor
|
|
||||||
Привести формат дат к одинаковому значению
|
|
||||||
# 2025-08-16 (solo-85)
|
# 2025-08-16 (solo-85)
|
||||||
|
|
||||||
| Упражнение | Вес | Подходы |
|
| Упражнение | Вес | Подходы |
|
||||||
|
|
@ -51,7 +48,6 @@
|
||||||
| Жим от груди сидя в тренажёре (кирпичики) | 50-60-65-70 | 12-12-12-12 |
|
| Жим от груди сидя в тренажёре (кирпичики) | 50-60-65-70 | 12-12-12-12 |
|
||||||
| Пресс на скамейке | | 12 |
|
| Пресс на скамейке | | 12 |
|
||||||
|
|
||||||
Свело мышцы пресса - скипнул последние подходы
|
|
||||||
# 2025-08-05 (solo-80)
|
# 2025-08-05 (solo-80)
|
||||||
|
|
||||||
| Упражнение | Вес | Подходы |
|
| Упражнение | Вес | Подходы |
|
||||||
|
|
|
||||||
18
main.py
18
main.py
|
|
@ -1,4 +1,18 @@
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from apple.notes_parser import parse_training_data
|
from apple.notes_parser import parse_training_data as aptd
|
||||||
|
from obsidian.notes_parser import parse_training_data as optd
|
||||||
|
from obsidian.py_models import Training
|
||||||
|
|
||||||
pprint(parse_training_data())
|
o_dates = [train.date for train in optd()]
|
||||||
|
print(len(o_dates))
|
||||||
|
|
||||||
|
a_dates = [train.date for train in aptd()]
|
||||||
|
print(len(a_dates))
|
||||||
|
|
||||||
|
def print_train(training: Training):
|
||||||
|
print(f"Training date: {training.date}")
|
||||||
|
for ex in training.exercises:
|
||||||
|
print(f" {ex.name}")
|
||||||
|
|
||||||
|
for tr in aptd():
|
||||||
|
print_train(tr)
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,20 @@ from datetime import datetime
|
||||||
from obsidian.mapper import obsidian_unique_exercies_mapping
|
from obsidian.mapper import obsidian_unique_exercies_mapping
|
||||||
|
|
||||||
from obsidian.py_models import Approach, Exercise, Training
|
from obsidian.py_models import Approach, Exercise, Training
|
||||||
|
from utils.date_refactor import parse_training_date
|
||||||
|
|
||||||
current_directory = os.path.dirname(os.path.abspath(__file__))
|
current_directory = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
PROJECT_ROOT_DIR = os.getcwd()
|
||||||
|
|
||||||
def get_current_path():
|
|
||||||
return current_directory
|
def get_data_path():
|
||||||
|
notes_data_dir = os.path.join(PROJECT_ROOT_DIR, "data")
|
||||||
|
return notes_data_dir
|
||||||
|
|
||||||
|
|
||||||
def get_obsidian_examples_file(example_file_name: str):
|
def get_obsidian_examples_file(example_file_name: str):
|
||||||
return os.path.join(get_current_path(), f"examples/{example_file_name}")
|
return os.path.join(get_data_path(), f"{example_file_name}")
|
||||||
|
|
||||||
|
|
||||||
def read_example_file(example_file_name: str):
|
def read_example_file(example_file_name: str):
|
||||||
|
|
@ -88,7 +92,7 @@ def filter_training_data(training_data: str):
|
||||||
|
|
||||||
|
|
||||||
def parse_training_data():
|
def parse_training_data():
|
||||||
training_data: str = filter_training_data(read_example_file("full.txt"))
|
training_data: str = filter_training_data(read_example_file("obsidian.md"))
|
||||||
lines = training_data.splitlines()
|
lines = training_data.splitlines()
|
||||||
current_training = None
|
current_training = None
|
||||||
trains = []
|
trains = []
|
||||||
|
|
@ -99,7 +103,9 @@ def parse_training_data():
|
||||||
if header_parsed:
|
if header_parsed:
|
||||||
trains.append(current_training)
|
trains.append(current_training)
|
||||||
current_training = Training(
|
current_training = Training(
|
||||||
date=datetime.strptime(date, "%d.%m.%Y").date(), exercises=[]
|
# date=datetime.strptime(date, "%d.%m.%Y").date(), exercises=[]
|
||||||
|
date=parse_training_date(date),
|
||||||
|
exercises=[],
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
|
@ -107,7 +113,7 @@ def parse_training_data():
|
||||||
current_training.exercises.append(exr)
|
current_training.exercises.append(exr)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return trains
|
return trains[1:]
|
||||||
|
|
||||||
|
|
||||||
def remap_unique_exercises(obsidian_trainings: List[Training]) -> List[Training]:
|
def remap_unique_exercises(obsidian_trainings: List[Training]) -> List[Training]:
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ dependencies = [
|
||||||
"pydantic>=2.11.7",
|
"pydantic>=2.11.7",
|
||||||
"pytest>=8.3.4",
|
"pytest>=8.3.4",
|
||||||
"sqlalchemy>=2.0.37",
|
"sqlalchemy>=2.0.37",
|
||||||
"psycopg2>=2.9.10",
|
"psycopg2-binary>=2.9.10",
|
||||||
"python-dotenv>=1.0.1",
|
"python-dotenv>=1.0.1",
|
||||||
"asyncpg>=0.30.0",
|
"asyncpg>=0.30.0",
|
||||||
"grpcio>=1.70.0",
|
"grpcio>=1.70.0",
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,21 @@
|
||||||
|
import re
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
|
|
||||||
def parse_training_date(date: str) -> date:
|
def parse_training_date(raw_date: str) -> date:
|
||||||
"""
|
patterns = [
|
||||||
Regex для поиска некорректных форматов даты
|
r"^(?P<day>[0-9]{2})\.(?P<month>[0-9]{2})\.(?P<year>[0-9]{4})*",
|
||||||
|
r"^(?P<year>[0-9]{4})\-(?P<month>[0-9]{2})\-(?P<day>[0-9]{2})*",
|
||||||
|
r"^(?P<year>[0-9]{4})\.(?P<month>[0-9]{2})\.(?P<day>[0-9]{2})*",
|
||||||
|
r"^(?P<day>[0-9]{2})\.(?P<month>[0-9]{2})\.(?P<year>[0-9]{4})*",
|
||||||
|
]
|
||||||
|
|
||||||
Obsidian - даты до 02.06.2025
|
for pattern in patterns:
|
||||||
^#\s(?P<day>[0-9]{2})\.(?P<month>[0-9]{2})\.(?P<year>[0-9]{4})*
|
match = re.match(pattern, raw_date)
|
||||||
|
if match:
|
||||||
|
day = int(match.group("day"))
|
||||||
|
month = int(match.group("month"))
|
||||||
|
year = int(match.group("year"))
|
||||||
|
return date(year, month, day)
|
||||||
|
|
||||||
Obsidian - даты после 02.06.2025
|
raise ValueError(f"Не удалось найти дату в строке: {raw_date}")
|
||||||
^#\s(?P<year>[0-9]{4})\-(?P<month>[0-9]{2})\-(?P<day>[0-9]{2})*
|
|
||||||
|
|
||||||
Apple - скорее всего все заметки
|
|
||||||
^.*(?P<day>[0-9]{2})\.(?P<month>[0-9]{2})\.(?P<year>[0-9]{4})*
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
|
||||||
22
uv.lock
22
uv.lock
|
|
@ -1,5 +1,5 @@
|
||||||
version = 1
|
version = 1
|
||||||
revision = 3
|
revision = 2
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -44,7 +44,7 @@ dependencies = [
|
||||||
{ name = "asyncpg" },
|
{ name = "asyncpg" },
|
||||||
{ name = "grpcio" },
|
{ name = "grpcio" },
|
||||||
{ name = "grpcio-tools" },
|
{ name = "grpcio-tools" },
|
||||||
{ name = "psycopg2" },
|
{ name = "psycopg2-binary" },
|
||||||
{ name = "pydantic" },
|
{ name = "pydantic" },
|
||||||
{ name = "pytest" },
|
{ name = "pytest" },
|
||||||
{ name = "python-dotenv" },
|
{ name = "python-dotenv" },
|
||||||
|
|
@ -56,7 +56,7 @@ requires-dist = [
|
||||||
{ name = "asyncpg", specifier = ">=0.30.0" },
|
{ name = "asyncpg", specifier = ">=0.30.0" },
|
||||||
{ name = "grpcio", specifier = ">=1.70.0" },
|
{ name = "grpcio", specifier = ">=1.70.0" },
|
||||||
{ name = "grpcio-tools", specifier = ">=1.70.0" },
|
{ name = "grpcio-tools", specifier = ">=1.70.0" },
|
||||||
{ name = "psycopg2", specifier = ">=2.9.10" },
|
{ name = "psycopg2-binary", specifier = ">=2.9.10" },
|
||||||
{ name = "pydantic", specifier = ">=2.11.7" },
|
{ name = "pydantic", specifier = ">=2.11.7" },
|
||||||
{ name = "pytest", specifier = ">=8.3.4" },
|
{ name = "pytest", specifier = ">=8.3.4" },
|
||||||
{ name = "python-dotenv", specifier = ">=1.0.1" },
|
{ name = "python-dotenv", specifier = ">=1.0.1" },
|
||||||
|
|
@ -170,12 +170,22 @@ wheels = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "psycopg2"
|
name = "psycopg2-binary"
|
||||||
version = "2.9.10"
|
version = "2.9.10"
|
||||||
source = { registry = "https://pypi.org/simple" }
|
source = { registry = "https://pypi.org/simple" }
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/62/51/2007ea29e605957a17ac6357115d0c1a1b60c8c984951c19419b3474cdfd/psycopg2-2.9.10.tar.gz", hash = "sha256:12ec0b40b0273f95296233e8750441339298e6a572f7039da5b260e3c8b60e11", size = 385672, upload-time = "2024-10-16T11:24:54.832Z" }
|
sdist = { url = "https://files.pythonhosted.org/packages/cb/0e/bdc8274dc0585090b4e3432267d7be4dfbfd8971c0fa59167c711105a6bf/psycopg2-binary-2.9.10.tar.gz", hash = "sha256:4b3df0e6990aa98acda57d983942eff13d824135fe2250e6522edaa782a06de2", size = 385764, upload-time = "2024-10-16T11:24:58.126Z" }
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://files.pythonhosted.org/packages/ae/49/a6cfc94a9c483b1fa401fbcb23aca7892f60c7269c5ffa2ac408364f80dc/psycopg2-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:91fd603a2155da8d0cfcdbf8ab24a2d54bca72795b90d2a3ed2b6da8d979dee2", size = 2569060, upload-time = "2025-01-04T20:09:15.28Z" },
|
{ url = "https://files.pythonhosted.org/packages/3e/30/d41d3ba765609c0763505d565c4d12d8f3c79793f0d0f044ff5a28bf395b/psycopg2_binary-2.9.10-cp313-cp313-macosx_12_0_x86_64.whl", hash = "sha256:26540d4a9a4e2b096f1ff9cce51253d0504dca5a85872c7f7be23be5a53eb18d", size = 3044699, upload-time = "2024-10-16T11:21:42.841Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/35/44/257ddadec7ef04536ba71af6bc6a75ec05c5343004a7ec93006bee66c0bc/psycopg2_binary-2.9.10-cp313-cp313-macosx_14_0_arm64.whl", hash = "sha256:e217ce4d37667df0bc1c397fdcd8de5e81018ef305aed9415c3b093faaeb10fb", size = 3275245, upload-time = "2024-10-16T11:21:51.989Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/1b/11/48ea1cd11de67f9efd7262085588790a95d9dfcd9b8a687d46caf7305c1a/psycopg2_binary-2.9.10-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:245159e7ab20a71d989da00f280ca57da7641fa2cdcf71749c193cea540a74f7", size = 2851631, upload-time = "2024-10-16T11:21:57.584Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/62/e0/62ce5ee650e6c86719d621a761fe4bc846ab9eff8c1f12b1ed5741bf1c9b/psycopg2_binary-2.9.10-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3c4ded1a24b20021ebe677b7b08ad10bf09aac197d6943bfe6fec70ac4e4690d", size = 3082140, upload-time = "2024-10-16T11:22:02.005Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/27/ce/63f946c098611f7be234c0dd7cb1ad68b0b5744d34f68062bb3c5aa510c8/psycopg2_binary-2.9.10-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3abb691ff9e57d4a93355f60d4f4c1dd2d68326c968e7db17ea96df3c023ef73", size = 3264762, upload-time = "2024-10-16T11:22:06.412Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/43/25/c603cd81402e69edf7daa59b1602bd41eb9859e2824b8c0855d748366ac9/psycopg2_binary-2.9.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8608c078134f0b3cbd9f89b34bd60a943b23fd33cc5f065e8d5f840061bd0673", size = 3020967, upload-time = "2024-10-16T11:22:11.583Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/5f/d6/8708d8c6fca531057fa170cdde8df870e8b6a9b136e82b361c65e42b841e/psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:230eeae2d71594103cd5b93fd29d1ace6420d0b86f4778739cb1a5a32f607d1f", size = 2872326, upload-time = "2024-10-16T11:22:16.406Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/ce/ac/5b1ea50fc08a9df82de7e1771537557f07c2632231bbab652c7e22597908/psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:bb89f0a835bcfc1d42ccd5f41f04870c1b936d8507c6df12b7737febc40f0909", size = 2822712, upload-time = "2024-10-16T11:22:21.366Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/c4/fc/504d4503b2abc4570fac3ca56eb8fed5e437bf9c9ef13f36b6621db8ef00/psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:f0c2d907a1e102526dd2986df638343388b94c33860ff3bbe1384130828714b1", size = 2920155, upload-time = "2024-10-16T11:22:25.684Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/b2/d1/323581e9273ad2c0dbd1902f3fb50c441da86e894b6e25a73c3fda32c57e/psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:f8157bed2f51db683f31306aa497311b560f2265998122abe1dce6428bd86567", size = 2959356, upload-time = "2024-10-16T11:22:30.562Z" },
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/08/50/d13ea0a054189ae1bc21af1d85b6f8bb9bbc5572991055d70ad9006fe2d6/psycopg2_binary-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:27422aa5f11fbcd9b18da48373eb67081243662f9b46e6fd07c3eb46e4535142", size = 2569224, upload-time = "2025-01-04T20:09:19.234Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue