Platform
Resources
Pricing
Sign in
Get started
Devin Bayly
Workspace
Fork
Public
By
Devin Bayly
Edited
Aug 24, 2023
Insert cell
Insert cell
viewof
file
=
Inputs
.
file
(
{
label
:
"Data"
}
)
Insert cell
data
=
file
.
json
(
)
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
tickX
(
timestamps
,
{
x
:
"timestamp"
}
)
]
}
)
Insert cell
timestamps
=
data
.
map
(
(
e
)
=>
(
{
timestamp
:
parseFloat
(
e
.
timestamp
)
}
)
)
Insert cell
reduction
=
timestamps
.
reduce
(
(
acc
,
cur
)
=>
{
if
(
acc
[
cur
.
timestamp
]
==
undefined
)
{
acc
[
cur
.
timestamp
]
=
0
;
}
acc
[
cur
.
timestamp
]
+=
1
;
return
acc
;
}
,
{
}
)
Insert cell
amounts
=
{
return
Object
.
values
(
reduction
)
;
}
Insert cell
times
=
{
return
Object
.
keys
(
reduction
)
;
}
Insert cell
rdata
=
Array
(
times
.
length
)
.
fill
(
0
)
.
map
(
(
e
,
i
)
=>
(
{
time
:
parseFloat
(
times
[
i
]
)
,
amount
:
amounts
[
i
]
}
)
)
Insert cell
rdata
.
filter
(
(
e
)
=>
e
.
amount
>
4
)
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
dot
(
rdata
,
{
y
:
"amount"
,
x
:
"time"
}
)
]
}
)
Insert cell
extrainfo
=
timestamps
.
reduce
(
(
acc
,
cur
,
i
)
=>
{
if
(
acc
[
cur
.
timestamp
]
==
undefined
)
{
acc
[
cur
.
timestamp
]
=
{
count
:
0
,
inds
:
[
]
}
;
}
acc
[
cur
.
timestamp
]
.
count
+=
1
;
acc
[
cur
.
timestamp
]
.
inds
.
push
(
i
)
;
return
acc
;
}
,
{
}
)
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
file
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
timestamps
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
reduction
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
amounts
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
times
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rdata
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
extrainfo
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML