Skip to content

Commit af24c3e

Browse files
authored
Shift plotting updates updates 2024 (#153)
* new plotting features. * added 2022 plotting.
1 parent 1274a01 commit af24c3e

File tree

5 files changed

+214
-86
lines changed

5 files changed

+214
-86
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ instance/
7171

7272
# Sphinx documentation
7373
docs/_build/
74+
doc/_build/
7475
doc_build/
7576

7677
# PyBuilder

scripts/__init__.py

Whitespace-only changes.

scripts/parse_md_table.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from collections.abc import Sequence
2+
from pathlib import Path
3+
4+
import pandas as pd
5+
6+
def parse_file(file_path: Path) -> pd.DataFrame:
7+
""" Parses a markdown file, containing a shift-table, into a pandas dataframe.
8+
9+
Args:
10+
file_path (Path): Path to the markdown file.
11+
12+
Returns:
13+
pd.DataFrame: DataFrame containing the shift table.
14+
"""
15+
header, data = get_table_parts(file_path.read_text().split("\n"))
16+
df = pd.DataFrame(
17+
columns=parse_line(header[0]),
18+
data=[parse_line(line) for line in data],
19+
)
20+
return df
21+
22+
23+
def parse_line(line: str):
24+
"""Convert a single line of a table into a list of parts.
25+
26+
Args:
27+
line (str): Line of the table.
28+
29+
Returns:
30+
List[str]: List of the table row entries.
31+
"""
32+
return [part.strip() for part in line.split("|")][1:-1]
33+
34+
35+
def get_table_parts(content: Sequence[str]):
36+
""" Splits a markdown table into header and data. """
37+
header = []
38+
data = []
39+
header_finished = False
40+
41+
for line in content:
42+
line = line.strip()
43+
44+
if not line.startswith("|"):
45+
if not data:
46+
continue
47+
else:
48+
break
49+
50+
if ":---" in line:
51+
header_finished = True
52+
continue
53+
54+
if not header_finished:
55+
header.append(line)
56+
else:
57+
data.append(line)
58+
59+
return header, data
60+
61+

scripts/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
titlecase
2+
pandas
3+
matplotlib

0 commit comments

Comments
 (0)