Skip to content

Commit

Permalink
Resolve #1, consolidate personalBest table fields, update cubing icon…
Browse files Browse the repository at this point in the history
…s, fix API personalBest bug
  • Loading branch information
big213 committed Mar 26, 2021
1 parent 48ccd5f commit e92963b
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Knex from "knex";

export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable("personalBest", function (t) {
t.decimal("moves_count").nullable().alter();
});
}

export async function down(knex: Knex): Promise<void> {
return knex.schema.alterTable("personalBest", function (t) {
t.integer("moves_count").nullable().alter();
});
}
2 changes: 1 addition & 1 deletion backend/functions/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function up(knex: Knex): Promise<void[]> {
table.integer("product").nullable();
table.dateTime("happened_on").notNullable();
table.integer("time_elapsed").nullable();
table.integer("moves_count").nullable();
table.decimal("moves_count").nullable();
table.boolean("is_current").notNullable();
table.dateTime("created_at").notNullable().defaultTo(knex.fn.now());
table.dateTime("updated_at").nullable();
Expand Down
71 changes: 39 additions & 32 deletions backend/functions/src/schema/models/personalBest/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class PersonalBestService extends PaginatedService {
validatedArgs.attemptsTotal = null;
validatedArgs.attemptsSucceeded = null;
validatedArgs.timeElapsed = null;
score = validatedArgs.movesCount;
score = validatedArgs.movesCount * 1000;
break;
case scoreMethodEnum.MBLD:
// only use movesCount, all other fields null
Expand Down Expand Up @@ -203,11 +203,14 @@ export class PersonalBestService extends PaginatedService {
}

validatedArgs.movesCount = null;
// rightmost 7 rights are for time (), lower is better
// remaining digits are for the score (x -1*1E8), higher is better
score =
validatedArgs.timeElapsed *
((validatedArgs.attemptsTotal - validatedArgs.attemptsSucceeded) *
-1 +
validatedArgs.attemptsSucceeded * 1);
validatedArgs.timeElapsed +
-100000000 *
((validatedArgs.attemptsTotal - validatedArgs.attemptsSucceeded) *
-1 +
validatedArgs.attemptsSucceeded * 1);
break;
}

Expand Down Expand Up @@ -445,34 +448,22 @@ export class PersonalBestService extends PaginatedService {
// args should be validated already
const validatedArgs = <any>args;
// confirm existence of item and get ID
const results = await sqlHelper.fetchTableRows({
select: [
const item = await this.lookupRecord(
[
{ field: "id" },
{
field: "isCurrent",
},
{
field: "happenedOn",
},
{ field: "event" },
{ field: "pbClass" },
{ field: "setSize" },
{ field: "createdBy" },
{ field: "isCurrent" },
{ field: "happenedOn" },
],
from: this.typename,
where: {
connective: "AND",
fields: Object.entries(validatedArgs).map(([field, value]) => ({
field,
value,
})),
},
});

if (results.length < 1) {
throw new Error(`${this.typename} not found`);
}
validatedArgs,
fieldPath
);

const itemId = results[0].id;

// if this pb isCurrent === true, must set the previous pb to isCurrent
if (results[0].isCurrent) {
// if this pb isCurrent === true, must set the previous pb of the same event-pbClass-setSize-createdBy combination to isCurrent
if (item.isCurrent) {
const previousPbResults = await sqlHelper.fetchTableRows({
select: [
{
Expand All @@ -485,7 +476,23 @@ export class PersonalBestService extends PaginatedService {
{
field: "happenedOn",
operator: "lt",
value: results[0].happenedOn,
value: item.happenedOn,
},
{
field: "event",
value: item.event,
},
{
field: "pbClass",
value: item.pbClass,
},
{
field: "setSize",
value: item.setSize,
},
{
field: "createdBy",
value: item.createdBy,
},
],
},
Expand Down Expand Up @@ -531,7 +538,7 @@ export class PersonalBestService extends PaginatedService {

await Resolver.deleteObjectType({
typename: this.typename,
id: itemId,
id: item.id,
req,
fieldPath,
});
Expand Down
3 changes: 2 additions & 1 deletion backend/functions/src/schema/models/personalBest/typeDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
generateUnixTimestampField,
generateBooleanField,
generateCreatedByField,
generateDecimalField,
} from "../../helpers/typeDef";

export default new JomqlObjectType(<ObjectTypeDefinition>{
Expand Down Expand Up @@ -68,7 +69,7 @@ export default new JomqlObjectType(<ObjectTypeDefinition>{
description: "The amount of ms time elapsed for the pb attempt",
sqlOptions: { field: "time_elapsed" },
}),
movesCount: generateIntegerField({
movesCount: generateDecimalField({
allowNull: true,
description: "The amount of moves used in the pb attempt",
sqlOptions: { field: "moves_count" },
Expand Down
62 changes: 31 additions & 31 deletions frontend/.firebase/hosting.ZGlzdA.cache
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
200.html,1616381724544,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
cubepb-trimmed.png,1615156446178,c1b92fbfd084f5f25cae3fe86dd6c4f1689f2041334cb8af81f36a102685428d
favicon.ico,1614368798533,f7b63ed2e9f400459ba0fbf4ca26bd436aaa2e56e5b7693b44a6ff7747c4aa07
index.html,1616381724535,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
wcalogo2020.svg,1615817560528,6ce11e9fec5f4b7f56a517e3a7289d776047750e644a29574b2676fc71f15d4a
WCAlogo_notext.svg,1606074492548,a256ca86013460c171f0c25060018de80f89ac4fb1815878f3a4450f19f5e360
admin/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
my-pbs/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
my-profile/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
pb/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
public-pbs/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
public-users/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
settings/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
user/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
wca-redirect/index.html,1616381724532,44214eb7c544c2a9e858bd612853951f41421a48d161f31d53c09e663464cc31
_nuxt/03e4c21.js,1616381724128,1820e8861da7b2e4aa0af653e9028c7c127a857f58407d188c443c6303e406bd
_nuxt/0574212.js,1616381724127,d4d607a067aab8f3c9e5ade34775e839657d468a1271c62fa4c8ab5f75e0382a
_nuxt/06085ee.js,1616381724136,3159400681b5bb54b2a89cf1a7017014cef67ef6559945a17a74a4fa4858a74c
_nuxt/0cf1f39.js,1616381724127,b679acad4feaa3a716ab50cdec208e787c7ed6b9a820d64d9a025ca945ee7886
_nuxt/2c93f44.js,1616381724128,a14bee84d9c35f68cf5445230125fdafd58af5b63e72b834f8a9d24273079477
_nuxt/2ee21e6.js,1616381724128,5157996e3510beb402adb862359f3d2e5a5ba6ac3e3a34c2fea9b06d5b3cc35d
_nuxt/455f7ce.js,1616381724128,ec094821273f651e446589b7829164bc7c3fcf2be8eace92eeb362c17d6616aa
_nuxt/48f6152.js,1616381724128,727cc6046de9058e86106c7dc10aaadeab2990d4b05e3a3de738fbe9d7319fdb
_nuxt/4ba508e.js,1616381724128,544396be4a12554416d22af777f1a4966ec0d297ab7e9f9083c45fd340b2fe60
_nuxt/8d3dc13.js,1616381724128,e93c6322e0c3a0c0bdb0a35272ded81af56d4f8426e08cf990469c5697e78ecf
_nuxt/a44a6a2.js,1616381724128,4cdd9643cc0bfbf6f6c4369c111763862aa06e94d1fd56b7f257a787b08dd417
_nuxt/b50b883.js,1616381724136,64ad332e62b870468a0e0b5f11d6e4602726fcb2de55c52486e559f6a365a331
_nuxt/b981b21.js,1616381724128,8a9ef60f1657d8ae7e0244e90363c1a1cee1a26eb6939618c908313279a7c3b9
_nuxt/ba319b2.js,1616381724128,d03cc2cf04e416ee02ed2786fcca6f6a2f366442b91a234f07bed4ec4ae36f19
_nuxt/e2fc74e.js,1616381724135,c3d59d985243f1f3376d860f126a8eee90f163023944656fa665b749cea7ed1d
_nuxt/fed3ca9.js,1616381724128,a66f5d1d82b9827ab2e2789eb433c34f3669857500efcc1681cc7710d54df77e
_nuxt/LICENSES,1616381724136,f47302101958e9af5124a2881ba704639c6a6266cedc18ab785440ba357ece1e
_nuxt/img/cubepb-trimmed.e9a5160.png,1616381724128,c1b92fbfd084f5f25cae3fe86dd6c4f1689f2041334cb8af81f36a102685428d
_nuxt/img/wcalogo2020.917de10.svg,1616381724128,6ce11e9fec5f4b7f56a517e3a7289d776047750e644a29574b2676fc71f15d4a
service-worker.js,1616382474747,3d389dc63dfe6760a3036d6f4501d04a4a489014095aa3a0360ed3a7bffa3340
200.html,1616642139872,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
index.html,1616642139864,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
service-worker.js,1616642156652,3d389dc63dfe6760a3036d6f4501d04a4a489014095aa3a0360ed3a7bffa3340
admin/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
my-pbs/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
my-profile/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
pb/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
public-pbs/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
public-users/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
user/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
settings/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
wca-redirect/index.html,1616642139861,1a0fd14e5231a070b8ec60729136ecf8da491c0d885633b49fd256b396f4d7db
_nuxt/13e9356.js,1616642139445,6026e5b6f2d23febef48635ae2197660315b499c9d4655593ec396ca408c27b9
_nuxt/1b52bbe.js,1616642139445,f5f40466147b3d1bc9c61e420db3ae1af8ffb7dcf71a39771a5f84868be6c85f
_nuxt/56b74f2.js,1616642139454,80136be0e2ee9d61d49b6cd916a5875b73be0f22917e307a63985aabbec86d9c
_nuxt/670da48.js,1616642139454,57f653cfe4aac7fe7c620e8195b940bd86e8ea9056f85aac87e95e4dd7f0bdf2
_nuxt/6c528fb.js,1616642139445,67a9c062c6089203fd0f7cfa16c06b6540792f2cc1934ec0f841c34f4a94d755
_nuxt/7ecc0dc.js,1616642139445,ca37de229885b1c6e596a14154f66dd1ce7d5f18d4f8c67db061209b90ad1aca
_nuxt/89515b2.js,1616642139445,4799170c81d8c85ebc40778474f0dd39c50da7db6b73d31fa776f601ce2705b8
_nuxt/8ed7f1d.js,1616642139445,0a329b520e658e5b12caa9fdbf89cd278d37fe1e4dcc61bb13af6b913a50e60c
_nuxt/8bc5f54.js,1616642139445,1ac4a0d4d5a1ad6774835090fe66248f3b1a64ba493e50d61c21e5f17d647fac
_nuxt/ba319b2.js,1616642139445,d03cc2cf04e416ee02ed2786fcca6f6a2f366442b91a234f07bed4ec4ae36f19
_nuxt/dcbf142.js,1616642139445,491695847a72c3023718d66209afc465f5b6ab0c5e863a79c678ed0bc6a8808c
_nuxt/920153a.js,1616642139445,be3d362b577becda1647d917763f55f1b8243b2f9ad640947627c730aab6e4e0
_nuxt/LICENSES,1616642139454,f47302101958e9af5124a2881ba704639c6a6266cedc18ab785440ba357ece1e
_nuxt/img/wcalogo2020.917de10.svg,1616642139447,6ce11e9fec5f4b7f56a517e3a7289d776047750e644a29574b2676fc71f15d4a
_nuxt/img/cubepb-trimmed.e9a5160.png,1616642139445,c1b92fbfd084f5f25cae3fe86dd6c4f1689f2041334cb8af81f36a102685428d
_nuxt/2b5d159.js,1616642139445,9879ba6c9a9adb7db87b44d9694bb422add32772f4a452ce5c603ab0fde8a79b
_nuxt/eb1fdef.js,1616642139445,fcd49eebe6e7f00b87b4b65971bee36a5abb5d9cd6d2f5a22495b1de69dcc6a4
_nuxt/4ba508e.js,1616642139445,544396be4a12554416d22af777f1a4966ec0d297ab7e9f9083c45fd340b2fe60
_nuxt/b32667e.js,1616642139454,ffeb91643ac610a8c8665d6642b2064d4bda33ce389eaa99f5df5ffa5dce95f7
Loading

0 comments on commit e92963b

Please sign in to comment.