-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcard_elements.py
More file actions
64 lines (50 loc) · 1.93 KB
/
card_elements.py
File metadata and controls
64 lines (50 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from dash import html
from data_retrieval import get_recent_data
def multi_card(df, buoy_ids):
"""
Create a list of HTML card elements displaying the last data row for each specified buoy ID.
Args:
df (pd.DataFrame): Multi-index DataFrame containing SWIFT data.
buoy_ids (list of str): List of buoy IDs to retrieve data for.
Returns:
list: List of Dash HTML components representing the data for each buoy ID.
"""
cards = []
for buoy_id in buoy_ids:
recent_data = get_recent_data(df, buoy_id)
if recent_data is not None:
formatted_time = recent_data["time"]
card_content = f"ID: {buoy_id} | {formatted_time}"
cards.extend([html.P(card_content), html.Br()])
else:
card_content = f"ID: {buoy_id} | Data not found"
cards.extend([html.P(card_content), html.Br()])
return cards
def single_card(df, buoy_id):
"""
Create a list of HTML card elements displaying the last data row for a buoy ID.
Args:
df (pd.DataFrame): Multi-index DataFrame containing SWIFT data.
buoy_id (str): Buoy ID to retrieve data for.
Returns:
list: List of Dash HTML components representing the data for a buoy ID.
"""
cards = []
recent_data = get_recent_data(df, buoy_id)
if recent_data is not None:
card_content = html.P(
[
f'Significant Wave Height: {recent_data["significant_height"]:.3f}',
html.Br(),
f'Peak Period: {recent_data["peak_period"]:.3f}',
html.Br(),
f'Peak Direction: {recent_data["peak_direction"]:.3f}',
html.Br(),
f'Timestamp: {recent_data["time"]}',
]
)
cards.append(card_content)
else:
card_content = html.P([f"ID: {buoy_id} | Data not found", html.Br()])
cards.append(card_content)
return cards