Skip to content

Commit

Permalink
Change case of AscentType enum keys and values to all lowercase.
Browse files Browse the repository at this point in the history
  • Loading branch information
salamca committed Sep 13, 2024
1 parent c4ef3ec commit 152b842
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 114 deletions.
60 changes: 30 additions & 30 deletions src/activities/entities/activity-route.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,50 @@ import { Pitch } from '../../crags/entities/pitch.entity';
import { User } from '../../users/entities/user.entity';

export enum AscentType {
ONSIGHT = 'onsight',
FLASH = 'flash',
REDPOINT = 'redpoint',
REPEAT = 'repeat',
ALLFREE = 'allfree',
AID = 'aid',
ATTEMPT = 'attempt',
T_ONSIGHT = 't_onsight',
T_FLASH = 't_flash',
T_REDPOINT = 't_redpoint',
T_REPEAT = 't_repeat',
T_ALLFREE = 't_allfree',
T_AID = 't_aid',
T_ATTEMPT = 't_attempt',
TICK = 'tick',
onsight = 'onsight',
flash = 'flash',
redpoint = 'redpoint',
repeat = 'repeat',
allfree = 'allfree',
aid = 'aid',
attempt = 'attempt',
t_onsight = 't_onsight',
t_flash = 't_flash',
t_redpoint = 't_redpoint',
t_repeat = 't_repeat',
t_allfree = 't_allfree',
t_aid = 't_aid',
t_attempt = 't_attempt',
tick = 'tick',
}
registerEnumType(AscentType, {
name: 'AscentType',
});

export const tickAscentTypes = new Set([
AscentType.ONSIGHT,
AscentType.FLASH,
AscentType.REDPOINT,
AscentType.REPEAT,
AscentType.onsight,
AscentType.flash,
AscentType.redpoint,
AscentType.repeat,
]);

export const firstTickAscentTypes = new Set([
AscentType.ONSIGHT,
AscentType.FLASH,
AscentType.REDPOINT,
AscentType.onsight,
AscentType.flash,
AscentType.redpoint,
]);

export const trTickAscentTypes = new Set([
AscentType.T_ONSIGHT,
AscentType.T_FLASH,
AscentType.T_REDPOINT,
AscentType.T_REPEAT,
AscentType.t_onsight,
AscentType.t_flash,
AscentType.t_redpoint,
AscentType.t_repeat,
]);

export const firstTrTickAscentTypes = new Set([
AscentType.T_ONSIGHT,
AscentType.T_FLASH,
AscentType.T_REDPOINT,
AscentType.t_onsight,
AscentType.t_flash,
AscentType.t_redpoint,
]);

export enum PublishType {
Expand Down Expand Up @@ -115,7 +115,7 @@ export class ActivityRoute extends BaseEntity {
@Column({
type: 'enum',
enum: AscentType,
default: AscentType.REDPOINT,
default: AscentType.redpoint,
})
@Field((type) => AscentType)
ascentType: AscentType;
Expand Down
22 changes: 11 additions & 11 deletions src/activities/services/activity-routes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,46 +247,46 @@ export class ActivityRoutesService {
// boulders cannot be onsighted at all
if (routeTypeId === 'boulder') {
if (
ascentType === AscentType.ONSIGHT ||
ascentType === AscentType.T_ONSIGHT
ascentType === AscentType.onsight ||
ascentType === AscentType.t_onsight
)
return false;
}

// already tried routes cannot be onsighted or flashed
if (routeTried) {
if (
ascentType === AscentType.ONSIGHT ||
ascentType === AscentType.T_ONSIGHT ||
ascentType === AscentType.FLASH ||
ascentType === AscentType.T_FLASH
ascentType === AscentType.onsight ||
ascentType === AscentType.t_onsight ||
ascentType === AscentType.flash ||
ascentType === AscentType.t_flash
)
return false;
}

// already ticked routes cannot be redpointed (flash, sight included above)
if (routeTicked) {
if (
ascentType === AscentType.REDPOINT ||
ascentType === AscentType.T_REDPOINT
ascentType === AscentType.redpoint ||
ascentType === AscentType.t_redpoint
)
return false;
}

// routes one already 'ticked' on toprope cannot be tr redpointed
if (routeTrTicked) {
if (ascentType === AscentType.T_REDPOINT) {
if (ascentType === AscentType.t_redpoint) {
return false;
}
}

// routes not ticked before cannot be repeated
if (ascentType === AscentType.REPEAT && !routeTicked) {
if (ascentType === AscentType.repeat && !routeTicked) {
return false;
}

// routes not ticked (real or tr) before cannot be toprope repeated
if (ascentType === AscentType.T_REPEAT && !(routeTicked || routeTrTicked)) {
if (ascentType === AscentType.t_repeat && !(routeTicked || routeTrTicked)) {
return false;
}

Expand Down
30 changes: 15 additions & 15 deletions src/crags/utils/calculate-scores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,35 @@ function calculateScore(
const scoreTypeFactor = scoreType === 'order' ? 1 : 0;

switch (ascentType) {
case AscentType.ONSIGHT:
case AscentType.onsight:
return difficulty + 100;
case AscentType.FLASH:
case AscentType.flash:
return difficulty + 50;
case AscentType.REDPOINT:
case AscentType.redpoint:
return difficulty;
case AscentType.REPEAT:
case AscentType.repeat:
return (difficulty - 10) * scoreTypeFactor;
case AscentType.ALLFREE:
case AscentType.allfree:
return difficulty * 0.01 * scoreTypeFactor;
case AscentType.AID:
case AscentType.aid:
return difficulty * 0.001 * scoreTypeFactor;
case AscentType.ATTEMPT:
case AscentType.attempt:
return difficulty * 0.0001 * scoreTypeFactor;
case AscentType.T_ONSIGHT:
case AscentType.t_onsight:
return (difficulty + 100) * 0.0001 * scoreTypeFactor;
case AscentType.T_FLASH:
case AscentType.t_flash:
return (difficulty + 50) * 0.0001 * scoreTypeFactor;
case AscentType.T_REDPOINT:
case AscentType.t_redpoint:
return difficulty * 0.0001 * scoreTypeFactor;
case AscentType.T_REPEAT:
case AscentType.t_repeat:
return (difficulty - 10) * 0.0001 * scoreTypeFactor;
case AscentType.T_ALLFREE:
case AscentType.t_allfree:
return difficulty * 0.01 * 0.0001 * scoreTypeFactor;
case AscentType.T_AID:
case AscentType.t_aid:
return difficulty * 0.001 * 0.0001 * scoreTypeFactor;
case AscentType.T_ATTEMPT:
case AscentType.t_attempt:
return difficulty * 0.0001 * 0.0001 * scoreTypeFactor;
case AscentType.TICK:
case AscentType.tick:
// TODO: what is TICK ascent type, and is it even used?? prob not, 1 ar in db... suggest removal, discuss
return 0;
}
Expand Down
12 changes: 6 additions & 6 deletions src/crags/utils/convert-ascents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function convertFirstTickAfterToRepeat(
);

// Convert it to repeat
futureTick.ascentType = AscentType.REPEAT;
futureTick.ascentType = AscentType.repeat;
await queryRunner.manager.save(futureTick);
sideEffects.push({ before: futureTickBeforeChange, after: futureTick });
}
Expand Down Expand Up @@ -86,7 +86,7 @@ async function convertFirstTrTickAfterToTrRepeat(
);

// Convert it to toprope repeat
futureTrTick.ascentType = AscentType.T_REPEAT;
futureTrTick.ascentType = AscentType.t_repeat;
await queryRunner.manager.save(futureTrTick);
sideEffects.push({
before: futureTrTickBeforeChange,
Expand All @@ -110,7 +110,7 @@ async function convertFirstSightOrFlashAfterToRedpoint(
.where('ar.route_id = :routeId', { routeId: routeId })
.andWhere('ar.user_id = :userId', { userId: userId })
.andWhere('ar.ascent_type IN (:...aTypes)', {
aTypes: [AscentType.ONSIGHT, AscentType.FLASH],
aTypes: [AscentType.onsight, AscentType.flash],
})
.andWhere('ar.date > :arDate', { arDate: date })
.getOne(); // If data is valid there can only be one such ascent logged (or none)
Expand All @@ -126,7 +126,7 @@ async function convertFirstSightOrFlashAfterToRedpoint(
);

// Convert it to redpoint
futureSightOrFlash.ascentType = AscentType.REDPOINT;
futureSightOrFlash.ascentType = AscentType.redpoint;
await queryRunner.manager.save(futureSightOrFlash);
sideEffects.push({
before: futureSightOrFlashBeforeChange,
Expand All @@ -150,7 +150,7 @@ async function convertFirstTrSightOrFlashAfterToTrRedpoint(
.where('ar.route_id = :routeId', { routeId: routeId })
.andWhere('ar.user_id = :userId', { userId: userId })
.andWhere('ar.ascent_type IN (:...aTypes)', {
aTypes: [AscentType.T_ONSIGHT, AscentType.T_FLASH],
aTypes: [AscentType.t_onsight, AscentType.t_flash],
})
.andWhere('ar.date > :arDate', { arDate: date })
.getOne(); // If data is valid there can only be one such ascent logged (or none)
Expand All @@ -166,7 +166,7 @@ async function convertFirstTrSightOrFlashAfterToTrRedpoint(
);

// Convert it to toprope redpoint
futureTrSightOrFlash.ascentType = AscentType.T_REDPOINT;
futureTrSightOrFlash.ascentType = AscentType.t_redpoint;
await queryRunner.manager.save(futureTrSightOrFlash);
sideEffects.push({
before: futureTrSightOrFlashBeforeChange,
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/activity.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('Activity', () => {

await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityWithPublicRoutes.activityRoutes.publicActivityRoute.id}', '${AscentType.ONSIGHT}', 'public', '${mockData.activities.activityWithPublicRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityWithPublicRoutes.activityRoutes.publicActivityRoute.id}', '${AscentType.onsight}', 'public', '${mockData.activities.activityWithPublicRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);

// add activity with only private activity routes
Expand All @@ -141,7 +141,7 @@ describe('Activity', () => {

await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityWithPrivateRoutes.activityRoutes.privateActivityRoute.id}', '${AscentType.REPEAT}', 'private', '${mockData.activities.activityWithPrivateRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityWithPrivateRoutes.activityRoutes.privateActivityRoute.id}', '${AscentType.repeat}', 'private', '${mockData.activities.activityWithPrivateRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);

// add activity with only log activity routes
Expand All @@ -152,7 +152,7 @@ describe('Activity', () => {

await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityWithLogRoutes.activityRoutes.logActivityRoute.id}', '${AscentType.REPEAT}', 'log', '${mockData.activities.activityWithLogRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityWithLogRoutes.activityRoutes.logActivityRoute.id}', '${AscentType.repeat}', 'log', '${mockData.activities.activityWithLogRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);

// add activty with mixed activity routes (public, private, log)
Expand All @@ -163,15 +163,15 @@ describe('Activity', () => {

await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.publicActivityRoute.id}', '${AscentType.REPEAT}', 'public', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.publicActivityRoute.id}', '${AscentType.repeat}', 'public', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);
await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.logActivityRoute.id}', '${AscentType.REPEAT}', 'log', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.logActivityRoute.id}', '${AscentType.repeat}', 'log', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);
await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.privateActivityRoute.id}', '${AscentType.REPEAT}', 'private', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityWithMixedRoutes.activityRoutes.privateActivityRoute.id}', '${AscentType.repeat}', 'private', '${mockData.activities.activityWithMixedRoutes.id}', '${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);

// add activity in a draft crag
Expand All @@ -181,7 +181,7 @@ describe('Activity', () => {
);
await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityInDraftCrag.activityRoutes.activityRoute1.id}', '${AscentType.REPEAT}', 'public', '${mockData.activities.activityInDraftCrag.id}', '${mockData.crags.draftCrag.sectors.draftSector.routes.draftRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityInDraftCrag.activityRoutes.activityRoute1.id}', '${AscentType.repeat}', 'public', '${mockData.activities.activityInDraftCrag.id}', '${mockData.crags.draftCrag.sectors.draftSector.routes.draftRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);

// add activity in an in_review crag
Expand All @@ -191,7 +191,7 @@ describe('Activity', () => {
);
await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityInInReviewCrag.activityRoutes.activityRoute1.id}', '${AscentType.REPEAT}', 'public', '${mockData.activities.activityInInReviewCrag.id}', '${mockData.crags.inReviewCrag.sectors.inReviewSector.routes.inReviewRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityInInReviewCrag.activityRoutes.activityRoute1.id}', '${AscentType.repeat}', 'public', '${mockData.activities.activityInInReviewCrag.id}', '${mockData.crags.inReviewCrag.sectors.inReviewSector.routes.inReviewRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);

// add activity in a published crag and draft sector
Expand All @@ -201,7 +201,7 @@ describe('Activity', () => {
);
await queryRunner.query(
`INSERT INTO activity_route (id, ascent_type, publish, activity_id, route_id, user_id, order_score, ranking_score)
VALUES ('${mockData.activities.activityInPublishedCragDraftSector.activityRoutes.activityRoute1.id}', '${AscentType.REPEAT}', 'public', '${mockData.activities.activityInPublishedCragDraftSector.id}', '${mockData.crags.publishedCrag.sectors.draftSector.routes.draftRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
VALUES ('${mockData.activities.activityInPublishedCragDraftSector.activityRoutes.activityRoute1.id}', '${AscentType.repeat}', 'public', '${mockData.activities.activityInPublishedCragDraftSector.id}', '${mockData.crags.publishedCrag.sectors.draftSector.routes.draftRoute.id}', '${mockData.users.basicUser1.id}', 1000, 1000)`,
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/activityMutations.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('ActivityMutations', () => {
},
routes: [
{
ascentType: "${AscentType.ONSIGHT}",
ascentType: "${AscentType.onsight}",
publish: "${PublishType.PUBLIC}",
date: "2017-03-07",
routeId: "${mockData.crags.publishedCrag.sectors.publishedSector.routes.publishedRoute.id}"
Expand Down
Loading

0 comments on commit 152b842

Please sign in to comment.