Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update scripts #570

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions api/src/scripts/sync-drink-badges.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dayjs = require("dayjs");
const prisma = require("../prisma");
const { countMaxConsecutiveDays, getStarsCorrespondingToConsecutiveDays } = require("../utils/drinks");

async function syncBadges(fixBadges = false) {
async function syncBadges(fixBadges = false, skip, take) {
const users = await prisma.user.findMany({
where: {},
include: {
Expand All @@ -15,7 +15,8 @@ async function syncBadges(fixBadges = false) {
orderBy: { date: "desc" },
},
},
// take: 1000,
take,
skip,
});
console.log("USERS", users.length);
let usersWithBadgeBiggerThan6ThatDontHaveTheBadge = 0;
Expand Down Expand Up @@ -54,4 +55,51 @@ async function syncBadges(fixBadges = false) {
});
}

syncBadges(false);
const skipTakes = [
[0, 1000],
[1000, 1000],
[2000, 1000],
[3000, 1000],
[4000, 1000],
[5000, 1000],
[6000, 1000],
[7000, 1000],
[8000, 1000],
[9000, 1000],
[10000, 1000],
[11000, 1000],
[12000, 1000],
[13000, 1000],
[14000, 1000],
[15000, 1000],
[16000, 1000],
[17000, 1000],
[18000, 1000],
[19000, 1000],
[20000, 1000],
[21000, 1000],
[22000, 1000],
[23000, 1000],
[24000, 1000],
[25000, 1000],
[26000, 1000],
[27000, 1000],
[28000, 1000],
[29000, 1000],
[30000, 1000],
[31000, 1000],
[32000, 1000],
[33000, 1000],
[34000, 1000],
[35000, 1000],
[36000, 1000],
[37000, 1000],
[38000, 1000],
[39000, 1000],
[40000, 1000],
];
(async () => {
for (const [skip, take] of skipTakes) {
await syncBadges(true, skip, take);
}
})();
55 changes: 51 additions & 4 deletions api/src/scripts/sync-goal-badges.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dayjs = require("dayjs");
const prisma = require("../prisma");
const { getStarsCorrespondingToGoalsSuccess } = require("../utils/goals");

async function syncBadges(fixBadges = false) {
async function syncBadges(fixBadges = false, skip, take) {
const users = await prisma.user.findMany({
where: {
goal_isSetup: true,
Expand All @@ -22,8 +22,8 @@ async function syncBadges(fixBadges = false) {
orderBy: {
matomo_id: "asc",
},
take: 50,
skip: 0,
skip,
take,
});
console.log("USERS", users.length);
let usersThatDontHaveTheBadge = 0;
Expand Down Expand Up @@ -60,4 +60,51 @@ async function syncBadges(fixBadges = false) {
});
}

syncBadges(false);
const skipTakes = [
[0, 1000],
[1000, 1000],
[2000, 1000],
[3000, 1000],
[4000, 1000],
[5000, 1000],
[6000, 1000],
[7000, 1000],
[8000, 1000],
[9000, 1000],
[10000, 1000],
[11000, 1000],
[12000, 1000],
[13000, 1000],
[14000, 1000],
[15000, 1000],
[16000, 1000],
[17000, 1000],
[18000, 1000],
[19000, 1000],
[20000, 1000],
[21000, 1000],
[22000, 1000],
[23000, 1000],
[24000, 1000],
[25000, 1000],
[26000, 1000],
[27000, 1000],
[28000, 1000],
[29000, 1000],
[30000, 1000],
[31000, 1000],
[32000, 1000],
[33000, 1000],
[34000, 1000],
[35000, 1000],
[36000, 1000],
[37000, 1000],
[38000, 1000],
[39000, 1000],
[40000, 1000],
];
(async () => {
for (const [skip, take] of skipTakes) {
await syncBadges(true, skip, take);
}
})();
43 changes: 37 additions & 6 deletions api/src/scripts/sync-goals.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const { grabBadgeFromCatalog } = require("../utils/badges");
const { countMaxConsecutiveDays, getStarsCorrespondingToConsecutiveDays } = require("../utils/drinks");
const { checkCurrentWeekGoal } = require("../utils/goals");

async function syncBadges(fixGoals = false, debug = false) {
async function syncBadges(fixGoals = false, debug = false, skip, take) {
console.log("--------------------------------------------------------------------------------------------------------------------");
console.log("SKIP", skip, "TAKE", take);
const users = await prisma.user.findMany({
where: {
goal_isSetup: true,
Expand All @@ -20,8 +22,8 @@ async function syncBadges(fixGoals = false, debug = false) {
orderBy: { date: "desc" },
},
},
take: 1000,
skip: 1100,
take,
skip,
});
console.log("USERS", users.length);
let usersWithFuckedUpGoals = {};
Expand All @@ -30,8 +32,8 @@ async function syncBadges(fixGoals = false, debug = false) {
let usersWithNoObjectives = {};
for (const [index, user] of Object.entries(users)) {
// log every 100 users
console.log("---------------------------------------------------------------------------------------------------------------");
console.log("user", index);
// console.log("---------------------------------------------------------------------------------------------------------------");
// console.log("user", index);
// if (debug) console.log(JSON.stringify(user, null, 2));
if (!user.goal_isSetup) {
usersWithNoObjectives[user.matomo_id] = true;
Expand Down Expand Up @@ -241,4 +243,33 @@ async function syncBadges(fixGoals = false, debug = false) {
});
}

syncBadges(true, true);
const skipTakes = [
[0, 1000],
[1000, 1000],
[2000, 1000],
[3000, 1000],
[4000, 1000],
[5000, 1000],
[6000, 1000],
[7000, 1000],
[8000, 1000],
[9000, 1000],
[10000, 1000],
[11000, 1000],
[12000, 1000],
[13000, 1000],
[14000, 1000],
[15000, 1000],
[16000, 1000],
[17000, 1000],
[18000, 1000],
[19000, 1000],
[20000, 1000],
[21000, 1000],
[22000, 1000],
];
(async () => {
for (const [skip, take] of skipTakes) {
await syncBadges(true, false, skip, take);
}
})();
Loading