Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat(storage): moves average price of offers to monthly basis (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
itofarina authored Nov 16, 2020
1 parent 1e0a42a commit ee15b43
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ It has following schema:
"utilizedCapacity": "number",
"acceptedCurrencies": "string[]", // ['rbtc', 'rif']
"availableCapacity": "number",
"avgBillingPrice": "number",
"avgBillingPrice": "number", // on a monthly basis
"totalStakedUSD": "number",
"createdAt": "Date",
"updatedAt": "Date",
Expand Down Expand Up @@ -182,7 +182,7 @@ It has following schema:
GET: /storage/v0/avgBillingPrice
```

Return min/max average billing price converted to USD.
Returns min/max average billing price per month converted to USD.


```json5
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage/models/offer.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function getBillingPriceAvgQuery (
SELECT
CAST(
SUM(
(cast(price as REAL) / ${WEI}) * coalesce("rates".${sequelize.escape(currency)}, 0) * 1024 / period * (3600 * 24)
(cast(price as REAL) / ${WEI}) * coalesce("rates".${sequelize.escape(currency)}, 0) * 1024 / period * (3600 * 24 * 30)
) / COUNT("storage_billing-plan"."id")
as INTEGER
)
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getAvgMinMaxBillingPriceQuery (minMax: MinMax): string {
SELECT
CAST(
SUM(
CAST(price as REAL) / ${WEI} * COALESCE("rates"."usd", 0) * 1024 / period * (3600 * 24)
CAST(price as REAL) / ${WEI} * COALESCE("rates"."usd", 0) * 1024 / period * (3600 * 24 * 30)
) / COUNT(*)
as INTEGER
) as avgPrice
Expand Down
4 changes: 2 additions & 2 deletions test/integration/services/storage/storage-manger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ describe('Storage service', function () {
const avgBillingPlanService = client.service(ServiceAddresses.AVG_BILLING_PRICE)
const { min, max } = await avgBillingPlanService.get(1)
const rate = await Rate.findOne({ where: { token: 'rbtc' }, raw: true })
expect(min).to.be.eql(Math.floor(rate?.usd as number))
expect(max).to.be.eql(Math.floor(rate?.usd as number))
expect(min).to.be.eql(Math.floor(rate?.usd as number * 30))
expect(max).to.be.eql(Math.floor(rate?.usd as number * 30))
})
})
describe('Notification', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/services/storage/models.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ describe('Models', () => {
order: [literal('avgBillingPrice')]
})
const expectedRes = [
{ provider: 'abc', avgBillingPrice: 1 },
{ provider: 'abc2', avgBillingPrice: 2 },
{ provider: 'abc3', avgBillingPrice: 3 }
{ provider: 'abc', avgBillingPrice: 30 },
{ provider: 'abc2', avgBillingPrice: 60 },
{ provider: 'abc3', avgBillingPrice: 90 }
]
expect(offers).to.be.deep.equal(expectedRes)
})
Expand Down

0 comments on commit ee15b43

Please sign in to comment.