Skip to content

Commit

Permalink
keep track of global ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
metkm committed Jul 24, 2022
1 parent e30f291 commit ea8d540
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,8 @@ export const jsonCountries: WebCountry[] = [
{ flag_url: "1f1f3-1f1fa.svg", code: "NU", name: "Niue" },
{ flag_url: "1f1f5-1f1f3.svg", code: "PN", name: "Pitcairn" },
{ flag_url: "1f1e8-1f1eb.svg", code: "CF", name: "Central African Republic" },

// GLOBAL RANKING TO KEEP TRACK OF WHERE THE PROGRAM IS LEFT
{ flag_url: "global.svg", code: "GLOBAL", name: "Global" },
]

59 changes: 22 additions & 37 deletions src/views/Mutuals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ const randomNumber = (): number => {
}
const threads: Threads = {}
const getUserElements = async (page: number, country?: string): Promise<Element[]> => {
const response = await http.fetch<string>(`https://osu.ppy.sh/rankings/${gamemode.value}/performance?page=${page}${country ? `&country=${country}` : ''}`, {
const getUserElements = async (page: number, country: string): Promise<Element[]> => {
let countryParam = country == "GLOBAL" ? "" : `&country=${country}`;
const response = await http.fetch<string>(`https://osu.ppy.sh/rankings/${gamemode.value}/performance?page=${page}${countryParam}`, {
method: "GET",
responseType: 2
})
Expand Down Expand Up @@ -84,58 +86,41 @@ const add = async (element: Element) => {
}
}
const startCheck = async (id: number, country?: string) => {
let limit = {
countryCode: "?",
start: 1,
end: 200,
index: 0
}
const startCheck = async (id: number, country: string) => {
let limit = settingsStore.getLimit(country) || { countryCode: country, end: 200, start: 1, index: 0 };
if (country) {
let countryLimit = settingsStore.getLimit(country);
if (countryLimit) {
limit = countryLimit;
}
}
for (let page = limit.start; page <= limit.end; page++) {
currentPage.value = page;
let slice_index = country ? settingsStore.getLimit(country)?.index : limit.index;
let elements = (await getUserElements(page, country)).slice(slice_index);
let elements = (await getUserElements(page, country)).slice(limit.index);
for (const [index, element] of elements.entries()) {
if (!threads[id]) return;
await add(element);
if (country) {
settingsStore.updateLimit({
countryCode: country,
start: page,
end: limit.end,
index
});
}
}
if (country) {
settingsStore.updateLimit({
countryCode: country,
countryCode: limit.countryCode,
start: page,
end: limit.end,
index: 0
})
index
});
}
settingsStore.updateLimit({
countryCode: country,
start: page,
end: limit.end,
index: 0
})
// page change sleep. Just in case.
await sleep(2000);
}
}
const start = async (id: number) => {
if (check.value == Check.Global) {
await startCheck(id);
await startCheck(id, "GLOBAL");
} else {
for (let country of countries.value) {
await startCheck(id, country);
Expand All @@ -149,10 +134,10 @@ onDeactivated(() => {
console.log("deactivated");
});
onActivated(() => {
if (import.meta.env.DEV) {
checked.value = [10440852];
return
};
// if (import.meta.env.DEV) {
// checked.value = [10440852];
// return
// };
// Disable all threads
for (const item in threads) {
Expand Down

0 comments on commit ea8d540

Please sign in to comment.