Skip to content

Commit

Permalink
highload testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fourhtyoz committed Jan 24, 2025
1 parent 1661239 commit 037277b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import Toast, { BaseToast } from 'react-native-toast-message';
import { I18nextProvider } from 'react-i18next';
import i18n from '@/utils/i18n';
import { observer } from 'mobx-react-lite';
import { createTables } from '@/services/db';
import { createTables, deleteTables } from '@/services/db';
import { settingsStore } from '@/store/store';
import Loader from '@/components/Loader';
import { LightTheme, DarkTheme } from '@/styles/themes';
import { FONT_SIZE } from '@/styles/colors';
import { clearAsyncStorage } from '@/utils/helpFunctions';
import { generateExercises, generateResults } from '@/utils/helpFunctions';


const App = observer(() => {
useEffect(() => {
// for development
// clearAsyncStorage();
// deleteTables();

createTables();
settingsStore.initialize();
}, []);
Expand Down
86 changes: 86 additions & 0 deletions utils/helpFunctions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import AsyncStorage from "@react-native-async-storage/async-storage";
import { Result, GroupedResult } from "./types";
import { settingsStore } from "@/store/store";
import { MUSCLES } from "@/constants/settings";
import { UNITS } from "@/constants/settings";
import { addExercise, addResult } from "@/services/db";
import { db } from "@/services/db";


export function getProgress(currentSet: Result, previousSet: Result) {
Expand Down Expand Up @@ -90,3 +95,84 @@ export function filterByMuscleGroup(data: any, targetGroup: any) {
}
return filteredData;
}

// for development
export async function clearAsyncStorage() {
try {
await AsyncStorage.clear()
console.log('All keys cleared successfully.');
} catch (e) {
console.error('Failed to clear AsyncStorage:', e);
}
}


export function generateExercises(quantity: number = 100) {
console.log('generateExercises start')
for (let i = 0; i < quantity; i++) {
const title = generateRandomString()

const typeIndex = Math.floor(Math.random() * MUSCLES.length);
const type = MUSCLES[typeIndex].title

console.log(`${i}, title: ${title} type: ${type}`)
addExercise(title, type)
}
console.log('generateExercises finish')
}


export async function generateResults(quantity: number = 1000) {
console.log('generateResults start')
for (let i = 0; i < quantity; i++) {
const exerciseObject = await getRandomExercise()
const date = generateRandomDate()
const reps = Math.floor(Math.random() * 20)
const weight = Math.floor(Math.random() * 150)
const unitsIndex = Math.floor(Math.random() * UNITS.length)
const units = UNITS[unitsIndex].title

console.log(`${i}, title: ${exerciseObject.title} type: ${exerciseObject.type}`)
await addResult(exerciseObject.title, date, exerciseObject.type, reps, weight, units)
}
console.log('generateResults finish')
}


export async function getRandomExercise() {
try {
const result = await new Promise((resolve, reject) => {
db.transaction(tx => {
tx.executeSql(
'SELECT title, type FROM exercises ORDER BY RANDOM() LIMIT 1;',
[],
(_, { rows }) => resolve(rows._array[0]),
(_, error) => reject(error)
);
});
});
console.log('result')
return result;
} catch (e) {
console.error('Error fetching random exercise:', e);
throw e;
}
};

export function generateRandomDate(start = new Date(2000, 0, 1), end = new Date()) {
const randomTimestamp = Math.random() * (end.getTime() - start.getTime()) + start.getTime();
const date = new Date(randomTimestamp)
const dateString = date.toISOString()
return dateString;
}


export function generateRandomString(length = 10) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters[randomIndex];
}
return result;
}

0 comments on commit 037277b

Please sign in to comment.