-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
61 lines (51 loc) · 1.77 KB
/
run.py
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
import random
import pandas as pd
from datetime import datetime
import plotly
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Generate Data
x = pd.date_range(datetime.today(), periods=100).tolist()
y = random.sample(range(1, 300), 100)
# Plot figure
fig = go.Figure([go.Bar(x=x, y=y)])
# Asthetics of the plot
fig.update_layout(
{"plot_bgcolor": "rgba(0, 0, 0, 0)", "paper_bgcolor": "rgba(0, 0, 0, 0)"},
autosize=True,
margin=dict(l=50, r=50, b=50, t=50, pad=4, autoexpand=True),
# height=1000,
# hovermode="x",
)
# Add title and dynamic range selector to x axis
fig.update_xaxes(
title_text="Date",
rangeselector=dict(
buttons=list(
[
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all"),
]
)
),
)
# Add title to y axis
fig.update_yaxes(title_text="Count")
# Write out to file (.html)
config = {"displayModeBar": False, "displaylogo": False}
plotly_obj = plotly.offline.plot(
fig, include_plotlyjs=False, output_type="div", config=config
)
with open("_includes/plotly_obj.html", "w") as file:
file.write(plotly_obj)
# Grab timestamp
data_updated = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
# Write out to file (.html)
html_str = (
'<p><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM8 0a8 8 0 100 16A8 8 0 008 0zm.5 4.75a.75.75 0 00-1.5 0v3.5a.75.75 0 00.471.696l2.5 1a.75.75 0 00.557-1.392L8.5 7.742V4.75z"></path></svg> Latest Data: '
+ data_updated
+ "</p>"
)
with open("_includes/update.html", "w") as file:
file.write(html_str)