Skip to content

Commit

Permalink
chore: Add isRough to stats
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed May 23, 2024
1 parent 20b4ecc commit 4525e04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/lib/components/View.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
const svg2roughjs = new Svg2Roughjs('#container');
svg2roughjs.svg = graphDiv;
await svg2roughjs.sketch();
graphDiv?.remove();
graphDiv.remove();
const sketch = document.querySelector<HTMLElement>('#container > svg');
if (!sketch) {
throw new Error('sketch not found');
Expand Down Expand Up @@ -146,9 +146,9 @@
console.error('view fail', error_);
error = true;
}
const timeTaken = Date.now() - startTime;
saveStatistics(code, timeTaken);
recordRenderTime(timeTaken, () => {
const renderTime = Date.now() - startTime;
saveStatistics({ code, renderTime, isRough: state.rough });
recordRenderTime(renderTime, () => {
$inputStateStore.updateDiagram = true;
});
};
Expand Down
18 changes: 13 additions & 5 deletions src/lib/util/stats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { browser } from '$app/environment';
import { env } from './env';
import type PlausibleInstance from 'plausible-tracker';
import { env } from './env';
export let plausible: ReturnType<typeof PlausibleInstance> | undefined;

export const initAnalytics = async (): Promise<void> => {
Expand Down Expand Up @@ -47,15 +47,23 @@ export const countLines = (code: string): number => {
return (code.match(/\n/g)?.length ?? 0) + 1;
};

export const saveStatistics = (graph: string, renderTime: number): void => {
const graphType = detectType(graph);
export const saveStatistics = ({
code,
renderTime,
isRough
}: {
code: string;
renderTime: number;
isRough: boolean;
}): void => {
const graphType = detectType(code);
if (!graphType) {
return;
}
const length = countLines(graph);
const length = countLines(code);
const lengthBucket = getBucket(length);
const renderTimeMsBucket = getBucket(renderTime);
logEvent('render', { graphType, length, lengthBucket, renderTimeMsBucket });
logEvent('render', { graphType, length, lengthBucket, renderTimeMsBucket, isRough });
};

const getBucket = (length: number): string => {
Expand Down

0 comments on commit 4525e04

Please sign in to comment.