Spaces:
Sleeping
Sleeping
Create ingest/timeline.py
Browse files- ingest/timeline.py +31 -0
ingest/timeline.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import plotly.graph_objects as go
|
| 2 |
+
from datetime import datetime
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def build_timeline_figure(results):
|
| 6 |
+
dates = []
|
| 7 |
+
labels = []
|
| 8 |
+
|
| 9 |
+
for r in results:
|
| 10 |
+
try:
|
| 11 |
+
dates.append(datetime.fromisoformat(r["date"]))
|
| 12 |
+
except Exception:
|
| 13 |
+
continue
|
| 14 |
+
labels.append(r["title"])
|
| 15 |
+
|
| 16 |
+
fig = go.Figure(
|
| 17 |
+
data=[
|
| 18 |
+
go.Scatter(
|
| 19 |
+
x=dates,
|
| 20 |
+
y=list(range(len(dates))),
|
| 21 |
+
mode="markers",
|
| 22 |
+
text=labels
|
| 23 |
+
)
|
| 24 |
+
],
|
| 25 |
+
layout=go.Layout(
|
| 26 |
+
title="Document Release Timeline",
|
| 27 |
+
xaxis_title="Release Date",
|
| 28 |
+
yaxis_title="Document Index"
|
| 29 |
+
)
|
| 30 |
+
)
|
| 31 |
+
return fig
|