From 9a29652a12a6a8d9aa671f4e2069878e2060ce50 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 12 Apr 2022 21:27:41 +0200 Subject: [PATCH 01/11] remove unused data --- frontend/src/layouts/DashboardLayout_gdd.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/src/layouts/DashboardLayout_gdd.vue b/frontend/src/layouts/DashboardLayout_gdd.vue index 8b84ac10d..f65329470 100755 --- a/frontend/src/layouts/DashboardLayout_gdd.vue +++ b/frontend/src/layouts/DashboardLayout_gdd.vue @@ -53,11 +53,9 @@ export default { }, data() { return { - logo: 'img/brand/green.png', balance: 0, GdtBalance: 0, transactions: [], - bookedBalance: 0, transactionCount: 0, transactionLinkCount: 0, pending: true, From 997ef9d72a607a278f6e4bcdf24fd515af1efc83 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 12 Apr 2022 21:34:04 +0200 Subject: [PATCH 02/11] query only required fields on balance --- frontend/src/graphql/queries.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index dce22fbd9..6a27a8052 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -47,12 +47,9 @@ export const transactionsQuery = gql` transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) { balance { balance - decay - lastBookedBalance balanceGDT count linkCount - lastBookedDate } transactions { id From a6e70363392ef88aef007c721cf5c5649c3970f8 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 12 Apr 2022 21:34:33 +0200 Subject: [PATCH 03/11] remove unused fields from balance model --- backend/src/graphql/model/Balance.ts | 17 ----------------- backend/src/graphql/resolver/BalanceResolver.ts | 5 ----- 2 files changed, 22 deletions(-) diff --git a/backend/src/graphql/model/Balance.ts b/backend/src/graphql/model/Balance.ts index 619d9b242..f04b235ee 100644 --- a/backend/src/graphql/model/Balance.ts +++ b/backend/src/graphql/model/Balance.ts @@ -5,33 +5,20 @@ import Decimal from 'decimal.js-light' export class Balance { constructor(data: { balance: Decimal - decay: Decimal - lastBookedBalance: Decimal balanceGDT: number | null count: number linkCount: number - lastBookedDate?: Date | null }) { this.balance = data.balance - this.decay = data.decay - this.lastBookedBalance = data.lastBookedBalance this.balanceGDT = data.balanceGDT || null this.count = data.count this.linkCount = data.linkCount - this.lastBookedDate = data.lastBookedDate || null } // the actual balance, decay included @Field(() => Decimal) balance: Decimal - // the decay since the last booked balance - @Field(() => Decimal) - decay: Decimal - - @Field(() => Decimal) - lastBookedBalance: Decimal - @Field(() => Number, { nullable: true }) balanceGDT: number | null @@ -42,8 +29,4 @@ export class Balance { // the count of transaction links @Field(() => Number) linkCount: number - - // may be null as there may be no transaction - @Field(() => Date, { nullable: true }) - lastBookedDate: Date | null } diff --git a/backend/src/graphql/resolver/BalanceResolver.ts b/backend/src/graphql/resolver/BalanceResolver.ts index 7cbd455cb..909a22144 100644 --- a/backend/src/graphql/resolver/BalanceResolver.ts +++ b/backend/src/graphql/resolver/BalanceResolver.ts @@ -29,8 +29,6 @@ export class BalanceResolver { if (!lastTransaction) { return new Balance({ balance: new Decimal(0), - decay: new Decimal(0), - lastBookedBalance: new Decimal(0), balanceGDT, count: 0, linkCount: 0, @@ -69,12 +67,9 @@ export class BalanceResolver { balance: calculatedDecay.balance .minus(sumHoldAvailableAmount.toString()) .toDecimalPlaces(2, Decimal.ROUND_DOWN), // round towards zero - decay: calculatedDecay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), // round towards - infinity - lastBookedBalance: lastTransaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), balanceGDT, count, linkCount, - lastBookedDate: lastTransaction.balanceDate, }) } } From 0bcf2cbd8cc556780fbedc8c963453a72263f89e Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 12 Apr 2022 21:43:18 +0200 Subject: [PATCH 04/11] use interface for decay constructor --- backend/src/graphql/model/Decay.ts | 26 ++++++++++---------- backend/src/graphql/model/Transaction.ts | 30 +++++++++++++----------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/backend/src/graphql/model/Decay.ts b/backend/src/graphql/model/Decay.ts index f1204e730..4416a738f 100644 --- a/backend/src/graphql/model/Decay.ts +++ b/backend/src/graphql/model/Decay.ts @@ -1,20 +1,22 @@ import { ObjectType, Field, Int } from 'type-graphql' import Decimal from 'decimal.js-light' +interface DecayInterface { + balance: Decimal + decay: Decimal + start: Date | null + end: Date | null + duration: number | null +} + @ObjectType() export class Decay { - constructor( - balance: Decimal, - decay: Decimal, - start: Date | null, - end: Date | null, - duration: number | null, - ) { - this.balance = balance - this.decay = decay - this.start = start - this.end = end - this.duration = duration + constructor(data: DecayInterface) { + this.balance = data.balance + this.decay = data.decay + this.start = data.start + this.end = data.end + this.duration = data.duration } @Field(() => Decimal) diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index 3c3a684ef..523ca06bc 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -17,21 +17,23 @@ export class Transaction { this.balanceDate = transaction.balanceDate if (!transaction.decayStart) { // TODO: hot fix, we should separate decay calculation from decay graphql model - this.decay = new Decay( - transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), - new Decimal(0), - null, - null, - null, - ) + this.decay = new Decay({ + balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + decay: new Decimal(0), + start: null, + end: null, + duration: null, + }) } else { - this.decay = new Decay( - transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), - transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), - transaction.decayStart, - transaction.balanceDate, - Math.round((transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000), - ) + this.decay = new Decay({ + balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + decay: transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + start: transaction.decayStart, + end: transaction.balanceDate, + duration: Math.round( + (transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000, + ), + }) } this.memo = transaction.memo this.creationDate = transaction.creationDate From 55ff0ee96437bb60fb495520c243c264c9ed47e8 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 12 Apr 2022 22:52:51 +0200 Subject: [PATCH 05/11] add roundedDecay field to Decay Model. This is used to calibrate the decay since the last transaction --- backend/src/graphql/model/Decay.ts | 5 +++++ backend/src/graphql/model/Transaction.ts | 3 +++ backend/src/util/decay.ts | 5 +++++ backend/src/util/virtualTransactions.ts | 4 ++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/model/Decay.ts b/backend/src/graphql/model/Decay.ts index 4416a738f..591294df5 100644 --- a/backend/src/graphql/model/Decay.ts +++ b/backend/src/graphql/model/Decay.ts @@ -4,6 +4,7 @@ import Decimal from 'decimal.js-light' interface DecayInterface { balance: Decimal decay: Decimal + roundedDecay: Decimal start: Date | null end: Date | null duration: number | null @@ -14,6 +15,7 @@ export class Decay { constructor(data: DecayInterface) { this.balance = data.balance this.decay = data.decay + this.roundedDecay = data.roundedDecay this.start = data.start this.end = data.end this.duration = data.duration @@ -25,6 +27,9 @@ export class Decay { @Field(() => Decimal) decay: Decimal + @Field(() => Decimal) + roundedDecay: Decimal + @Field(() => Date, { nullable: true }) start: Date | null diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index 523ca06bc..b6f75f745 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -20,6 +20,7 @@ export class Transaction { this.decay = new Decay({ balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), decay: new Decimal(0), + roundedDecay: new Decimal(0), start: null, end: null, duration: null, @@ -28,6 +29,8 @@ export class Transaction { this.decay = new Decay({ balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), decay: transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + // TODO + roundedDecay: new Decimal(0), start: transaction.decayStart, end: transaction.balanceDate, duration: Math.round( diff --git a/backend/src/util/decay.ts b/backend/src/util/decay.ts index 36f83f23f..48674dc50 100644 --- a/backend/src/util/decay.ts +++ b/backend/src/util/decay.ts @@ -29,6 +29,7 @@ function calculateDecay( const decay: Decay = { balance: amount, decay: new Decimal(0), + roundedDecay: new Decimal(0), start: null, end: null, duration: null, @@ -52,6 +53,10 @@ function calculateDecay( decay.end = to decay.balance = decayFormula(amount, decay.duration) decay.decay = decay.balance.minus(amount) + decay.roundedDecay = amount + .toDecimalPlaces(2, Decimal.ROUND_DOWN) + .minus(decay.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN).toString()) + .mul(-1) return decay } diff --git a/backend/src/util/virtualTransactions.ts b/backend/src/util/virtualTransactions.ts index 920fc4201..2f37ad188 100644 --- a/backend/src/util/virtualTransactions.ts +++ b/backend/src/util/virtualTransactions.ts @@ -68,12 +68,12 @@ const virtualDecayTransaction = ( userId: -1, previous: -1, typeId: TransactionTypeId.DECAY, - amount: decay.decay ? decay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) : new Decimal(0), // new Decimal(0), // this kinda is wrong, but helps with the frontend query + amount: decay.decay ? decay.roundedDecay : new Decimal(0), // this kinda is wrong, but helps with the frontend query balance: decay.balance .minus(holdAvailabeAmount.toString()) .toDecimalPlaces(2, Decimal.ROUND_DOWN), balanceDate: time, - decay: decay.decay ? decay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) : new Decimal(0), + decay: decay.decay ? decay.roundedDecay : new Decimal(0), decayStart: decay.start, memo: '', creationDate: null, From 034fa5e7a9fa25dcc43c7c55c45031ca7a999545 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 12 Apr 2022 23:09:40 +0200 Subject: [PATCH 06/11] add math minus, add minus operator if decay is zero --- .../src/components/DecayInformations/DecayInformation-Decay.vue | 1 + frontend/src/locales/de.json | 1 + frontend/src/locales/en.json | 1 + 3 files changed, 3 insertions(+) diff --git a/frontend/src/components/DecayInformations/DecayInformation-Decay.vue b/frontend/src/components/DecayInformations/DecayInformation-Decay.vue index 67847f6cf..96ffc9153 100644 --- a/frontend/src/components/DecayInformations/DecayInformation-Decay.vue +++ b/frontend/src/components/DecayInformations/DecayInformation-Decay.vue @@ -17,6 +17,7 @@
{{ previousBookedBalance | GDD }} + {{ decay === '0' ? $t('math.minus') : '' }} {{ decay | GDD }} {{ $t('math.equal') }} {{ balance | GDD }}
diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 557570019..731196936 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -145,6 +145,7 @@ "aprox": "~", "equal": "=", "exclaim": "!", + "minus": "−", "pipe": "|" }, "navigation": { diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 06342cab9..0a0d15a72 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -145,6 +145,7 @@ "aprox": "~", "equal": "=", "exclaim": "!", + "minus": "−", "pipe": "|" }, "navigation": { From 6d2033abd27164a6cefbe73b88f5d0b22a35201c Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 19 Apr 2022 08:36:38 +0200 Subject: [PATCH 07/11] no interface --- backend/src/graphql/model/Decay.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/backend/src/graphql/model/Decay.ts b/backend/src/graphql/model/Decay.ts index 591294df5..46aef4263 100644 --- a/backend/src/graphql/model/Decay.ts +++ b/backend/src/graphql/model/Decay.ts @@ -1,18 +1,16 @@ import { ObjectType, Field, Int } from 'type-graphql' import Decimal from 'decimal.js-light' -interface DecayInterface { - balance: Decimal - decay: Decimal - roundedDecay: Decimal - start: Date | null - end: Date | null - duration: number | null -} - @ObjectType() export class Decay { - constructor(data: DecayInterface) { + constructor(data: { + balance: Decimal + decay: Decimal + roundedDecay: Decimal + start: Date | null + end: Date | null + duration: number | null + }) { this.balance = data.balance this.decay = data.decay this.roundedDecay = data.roundedDecay From 1268b375b7fd3b281612e29e2673104dd98f28f3 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 20 Apr 2022 09:31:17 +0200 Subject: [PATCH 08/11] change config DECAY_START_TIME in UTC Timezone of 0000 --- frontend/src/config/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/config/index.js b/frontend/src/config/index.js index d29c4dc09..a11b5d924 100644 --- a/frontend/src/config/index.js +++ b/frontend/src/config/index.js @@ -5,7 +5,7 @@ const pkg = require('../../package') const constants = { - DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0 + DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 CONFIG_VERSION: { DEFAULT: 'DEFAULT', EXPECTED: 'v1.2022-03-18', From 6691be813f640f3e119432901e4ee20b7a5354fb Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 20 Apr 2022 12:44:21 +0200 Subject: [PATCH 09/11] decontruct input --- backend/src/graphql/model/Decay.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/backend/src/graphql/model/Decay.ts b/backend/src/graphql/model/Decay.ts index 46aef4263..f59a21249 100644 --- a/backend/src/graphql/model/Decay.ts +++ b/backend/src/graphql/model/Decay.ts @@ -1,22 +1,24 @@ import { ObjectType, Field, Int } from 'type-graphql' import Decimal from 'decimal.js-light' +interface DecayInterface { + balance: Decimal + decay: Decimal + roundedDecay: Decimal + start: Date | null + end: Date | null + duration: number | null +} + @ObjectType() export class Decay { - constructor(data: { - balance: Decimal - decay: Decimal - roundedDecay: Decimal - start: Date | null - end: Date | null - duration: number | null - }) { - this.balance = data.balance - this.decay = data.decay - this.roundedDecay = data.roundedDecay - this.start = data.start - this.end = data.end - this.duration = data.duration + constructor({ balance, decay, roundedDecay, start, end, duration }: DecayInterface) { + this.balance = balance + this.decay = decay + this.roundedDecay = roundedDecay + this.start = start + this.end = end + this.duration = duration } @Field(() => Decimal) From 324de9381412f270a6038af2b8c9192df23eae94 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 20 Apr 2022 12:51:34 +0200 Subject: [PATCH 10/11] update/remove comments --- backend/src/graphql/model/Transaction.ts | 2 +- backend/src/util/virtualTransactions.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index b6f75f745..24c66ac67 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -29,7 +29,7 @@ export class Transaction { this.decay = new Decay({ balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), decay: transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), - // TODO + // TODO: add correct value when decay must be rounded in transaction context roundedDecay: new Decimal(0), start: transaction.decayStart, end: transaction.balanceDate, diff --git a/backend/src/util/virtualTransactions.ts b/backend/src/util/virtualTransactions.ts index 2f37ad188..8c1aec65b 100644 --- a/backend/src/util/virtualTransactions.ts +++ b/backend/src/util/virtualTransactions.ts @@ -68,7 +68,7 @@ const virtualDecayTransaction = ( userId: -1, previous: -1, typeId: TransactionTypeId.DECAY, - amount: decay.decay ? decay.roundedDecay : new Decimal(0), // this kinda is wrong, but helps with the frontend query + amount: decay.decay ? decay.roundedDecay : new Decimal(0), balance: decay.balance .minus(holdAvailabeAmount.toString()) .toDecimalPlaces(2, Decimal.ROUND_DOWN), From 28065efd43ad48908e35af2039cf6381114349eb Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 20 Apr 2022 12:54:33 +0200 Subject: [PATCH 11/11] update README --- database/README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/database/README.md b/database/README.md index af9f3242c..84db3d194 100644 --- a/database/README.md +++ b/database/README.md @@ -31,9 +31,3 @@ yarn dev_reset ``` Runs all down migrations and after this all up migrations. - -## Reset DB -``` -yarn dev_reset -``` -