Skip to content

Commit

Permalink
fix: 来源统计改为当日数据
Browse files Browse the repository at this point in the history
  • Loading branch information
xjq7 committed Dec 4, 2022
1 parent 811ce9b commit 919e747
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/src/pages/stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function Component() {
<div id="region-stats"></div>
</div>
<div className="w-1/2">
<div className="mb-6">来源统计</div>
<div className="mb-6">今日访问用户来源统计</div>
<div id="source-stats"></div>
</div>
</div>
Expand Down
26 changes: 12 additions & 14 deletions server/src/controller/stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export class StatController {
const uv = uniqList.length;
const pv = list.length;

const source: Record<string, number> = {};

const parseList = uniqList.map((o) => {
const ua = uaparser(o.userAgent ?? '');
const browser = ua?.browser?.name ?? '未知';
Expand All @@ -69,7 +71,7 @@ export class StatController {
]
>(
(acc, cur) => {
const { os, country, province, city } = cur;
const { os, country, province, city, channel } = cur;
if (os) {
if (!acc[0][os]) {
acc[0][os] = 1;
Expand All @@ -88,6 +90,13 @@ export class StatController {
}
});

const curCount = source[ChannelText[channel as Channel]];
if (curCount) {
source[ChannelText[channel as Channel]]++;
} else {
source[ChannelText[channel as Channel]] = 1;
}

return acc;
},
[{}, {}, {}, {}]
Expand Down Expand Up @@ -124,22 +133,11 @@ export class StatController {
},
];

const source: Record<string, number> = {};
const ipSet = new Set();

list7.reverse().forEach((stat) => {
const { createdAt, channel, ip } = stat;
const { createdAt } = stat;

const diff = wrapDayjs(endAt).diff(createdAt, 'd');
uvStats[diff].value++;

const curCount = source[ChannelText[channel as Channel]];
if (curCount) {
source[ChannelText[channel as Channel]]++;
} else {
source[ChannelText[channel as Channel]] = 1;
}

ipSet.add(ip);
});

return {
Expand Down

0 comments on commit 919e747

Please sign in to comment.