Skip to content

Commit 6b3255a

Browse files
committed
better analytics timeline
1 parent 4b13d2d commit 6b3255a

File tree

3 files changed

+49
-27
lines changed

3 files changed

+49
-27
lines changed

run/models/contract.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = (sequelize, DataTypes) => {
100100
if (!earliestBlock)
101101
return [];
102102

103-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
103+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
104104

105105
return sequelize.query(`
106106
WITH days AS (
@@ -176,7 +176,7 @@ module.exports = (sequelize, DataTypes) => {
176176
if (!earliestBlock)
177177
return [];
178178

179-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
179+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
180180

181181
const [cumulativeSupply,] = await sequelize.query(`
182182
WITH days AS (

run/models/workspace.js

+46-24
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ module.exports = (sequelize, DataTypes) => {
320320
if (!earliestBlock)
321321
return [];
322322

323-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
323+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
324324

325325
const [transactions,] = await sequelize.query(`
326326
SELECT
@@ -358,7 +358,7 @@ module.exports = (sequelize, DataTypes) => {
358358
if (!earliestBlock)
359359
return [];
360360

361-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
361+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
362362

363363
const [deployedContractCount,] = await sequelize.query(`
364364
SELECT
@@ -397,23 +397,34 @@ module.exports = (sequelize, DataTypes) => {
397397
if (!earliestBlock)
398398
return [];
399399

400-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
400+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
401401

402402
const [cumulativeDeployedContractCount,] = await sequelize.query(`
403403
WITH days AS (
404404
SELECT
405405
d::date as day
406406
FROM generate_series(:from::date, :to::date, interval '1 day') d
407+
),
408+
counts AS (
409+
SELECT
410+
day::timestamptz AS counts_date,
411+
count(1) AS count
412+
FROM transaction_events, days
413+
WHERE timestamp <= days.day + interval '1 day'
414+
AND "to" IS NULL
415+
AND "workspaceId" = :workspaceId
416+
GROUP BY day
417+
ORDER BY day ASC
418+
),
419+
filled AS (
420+
SELECT
421+
time_bucket_gapfill('1 day', counts_date) AS date,
422+
locf(avg(count))
423+
FROM counts
424+
WHERE counts_date >= :from::date and counts_date < :to::date
425+
GROUP BY date
407426
)
408-
SELECT
409-
day::timestamptz AS date,
410-
count(1) AS count
411-
FROM transaction_events, days
412-
WHERE timestamp <= days.day
413-
AND "to" IS NULL
414-
AND "workspaceId" = :workspaceId
415-
GROUP BY day
416-
ORDER BY day ASC
427+
SELECT date, coalesce(locf, 0)::integer count FROM filled
417428
`, {
418429
replacements: {
419430
from: new Date(earliestTimestamp),
@@ -441,21 +452,32 @@ module.exports = (sequelize, DataTypes) => {
441452
if (!earliestBlock)
442453
return [];
443454

444-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
455+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
445456

446457
const [cumulativeWalletCount,] = await sequelize.query(`
447458
WITH days AS (
448459
SELECT
449460
d::date as day
450461
FROM generate_series(:from::date, :to::date, interval '1 day') d
462+
),
463+
counts AS (
464+
SELECT
465+
day::timestamptz AS counts_date,
466+
count(distinct "from")
467+
FROM transaction_events, days
468+
WHERE timestamp <= days.day + interval '1 day' AND "workspaceId" = :workspaceId
469+
GROUP BY day
470+
ORDER BY day ASC
471+
),
472+
filled AS (
473+
SELECT
474+
time_bucket_gapfill('1 day', counts_date) AS date,
475+
locf(avg(count))
476+
FROM counts
477+
WHERE counts_date >= :from::date and counts_date < :to::date
478+
GROUP BY date
451479
)
452-
SELECT
453-
day::timestamptz AS date,
454-
coalesce(count(distinct "from"), 0) AS count
455-
FROM transaction_events, days
456-
WHERE timestamp <= days.day AND "workspaceId" = :workspaceId
457-
GROUP BY day
458-
ORDER BY day ASC
480+
SELECT date, coalesce(locf, 0)::integer count FROM filled
459481
`, {
460482
replacements: {
461483
from: new Date(earliestTimestamp),
@@ -482,7 +504,7 @@ module.exports = (sequelize, DataTypes) => {
482504
if (!earliestBlock)
483505
return [];
484506

485-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
507+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
486508

487509
const [uniqueWalletCount,] = await sequelize.query(`
488510
SELECT
@@ -520,7 +542,7 @@ module.exports = (sequelize, DataTypes) => {
520542
if (!earliestBlock)
521543
return [];
522544

523-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
545+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
524546

525547
const [avgGasPrice,] = await sequelize.query(`
526548
SELECT
@@ -558,7 +580,7 @@ module.exports = (sequelize, DataTypes) => {
558580
if (!earliestBlock)
559581
return [];
560582

561-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
583+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
562584

563585
const [avgTransactionFee,] = await sequelize.query(`
564586
SELECT
@@ -596,7 +618,7 @@ module.exports = (sequelize, DataTypes) => {
596618
if (!earliestBlock)
597619
return [];
598620

599-
const earliestTimestamp = earliestBlock.timestamp > new Date(from) ? earliestBlock.timestamp : new Date(from);
621+
const earliestTimestamp = +new Date(from) == 0 ? earliestBlock.timestamp : new Date(from);
600622

601623
let query = `
602624
SELECT

src/components/ExplorerAnalytics.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</v-col>
3535

3636
<v-col cols="12" md="6">
37-
<Line-Chart :title="'Deployed Contracts Count'" :xLabels="charts['deployedContractCount'].xLabels" :data="charts['deployedContractCount'].data" :tooltipUnit="'contracts'" :index="6" />
37+
<Line-Chart :title="'Deployed Contracts Count'" :xLabels="charts['deployedContractCount'].xLabels" :data="charts['deployedContractCount'].data" :tooltipUnit="'contract'" :index="6" />
3838
</v-col>
3939

4040
<v-col cols="12" md="6">

0 commit comments

Comments
 (0)