Skip to content

Commit 240bfbe

Browse files
committed
Fix types/linting in cohort analysis
1 parent 251e0dc commit 240bfbe

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

app/helpers/cohortAnalysis.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { sql } from "kysely";
22
import { partition } from "lodash-es";
33

4-
import type { CodeStats } from "#~/discord/activityTracker.js";
4+
import type { CodeStats } from "#~/helpers/discord";
55
import { descriptiveStats, percentile } from "#~/helpers/statistics";
66
import { createMessageStatsQuery } from "#~/models/activity.server";
77

@@ -15,11 +15,11 @@ const performanceThresholds = [
1515
{ min: -Infinity, value: "bottom" },
1616
] as const;
1717

18-
type MetricConfig = {
18+
interface MetricConfig {
1919
key: "messageCount" | "reactionCount" | "codeChars" | "longestStreak";
2020
strength: string;
2121
improvement: string;
22-
};
22+
}
2323

2424
const metricsConfig: MetricConfig[] = [
2525
{
@@ -53,11 +53,11 @@ export interface UserCohortMetrics {
5353
totalChars: number;
5454
totalLines: number;
5555
languageBreakdown: Record<string, number>;
56-
topLanguages: Array<{
56+
topLanguages: {
5757
language: string;
5858
chars: number;
5959
percentage: number;
60-
}>;
60+
}[];
6161
};
6262
streakData: {
6363
longestStreak: number;
@@ -168,7 +168,7 @@ function calculateUserPercentile(value: number, data: number[]): number {
168168
}
169169

170170
function calculateStreakData(
171-
dailyActivity: Array<{ date: string; messageCount: number }>,
171+
dailyActivity: { date: string; messageCount: number }[],
172172
): UserCohortMetrics["streakData"] {
173173
const sortedActivity = dailyActivity.sort((a, b) =>
174174
a.date.localeCompare(b.date),
@@ -179,8 +179,8 @@ function calculateStreakData(
179179
let tempStreak = 0;
180180
let activeDays = 0;
181181

182-
for (let i = 0; i < sortedActivity.length; i++) {
183-
const hasActivity = sortedActivity[i].messageCount > 0;
182+
for (const { messageCount } of sortedActivity) {
183+
const hasActivity = messageCount > 0;
184184

185185
if (hasActivity) {
186186
activeDays++;
@@ -217,7 +217,7 @@ function aggregateCodeStats(
217217
): UserCohortMetrics["codeStats"] {
218218
const validCodeStats = codeStatsJson.flatMap((jsonStr) => {
219219
try {
220-
return JSON.parse(jsonStr) as Array<CodeStats>;
220+
return JSON.parse(jsonStr) as CodeStats[];
221221
} catch {
222222
return [];
223223
}
@@ -262,7 +262,7 @@ export async function getCohortMetrics(
262262
guildId: string,
263263
start: string,
264264
end: string,
265-
minMessageThreshold: number = 10,
265+
minMessageThreshold = 10,
266266
): Promise<UserCohortMetrics[]> {
267267
// Get aggregated user data
268268
const userStatsQuery = createMessageStatsQuery(guildId, start, end)
@@ -312,12 +312,12 @@ export async function getCohortMetrics(
312312
});
313313
return acc;
314314
},
315-
{} as Record<string, Array<{ date: string; messageCount: number }>>,
315+
{} as Record<string, { date: string; messageCount: number }[]>,
316316
);
317317

318318
return userStats.map((user) => {
319319
const codeStatsArray = user.code_stats_json
320-
? String(user.code_stats_json).split(",").filter(Boolean)
320+
? JSON.stringify(user.code_stats_json).split(",").filter(Boolean)
321321
: [];
322322

323323
const userDailyActivity = fillDateGaps(
@@ -536,7 +536,7 @@ export async function getUserCohortAnalysis(
536536
userId: string,
537537
start: string,
538538
end: string,
539-
minMessageThreshold: number = 10,
539+
minMessageThreshold = 10,
540540
) {
541541
const cohortMetrics = await getCohortMetrics(
542542
guildId,

app/helpers/discord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export const isModalCommand = (config: AnyCommand): config is ModalCommand =>
204204
"type" in config.command &&
205205
config.command.type === InteractionType.ModalSubmit;
206206

207-
interface CodeStats {
207+
export interface CodeStats {
208208
chars: number;
209209
words: number;
210210
lines: number;

0 commit comments

Comments
 (0)