Skip to content

Commit

Permalink
Merge pull request #300 from metaDAOproject/staging
Browse files Browse the repository at this point in the history
fix: time estimate
  • Loading branch information
R-K-H authored Oct 14, 2024
2 parents e749202 + 51792a0 commit fa44b2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
-X POST \
-H "Authorization: Bearer ${{ secrets.RAILWAY_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"query\":\"mutation { deploymentRedeploy(id: \\\"${{ secrets.RAILWAY_DEPLOYMENT_ID }}\\\") { status } }\"}" \
--data '{"query": "mutation serviceInstanceDeploy($serviceId: String!, $environmentId: String!) {\n serviceInstanceDeploy(serviceId: $serviceId, environmentId: $environmentId)\n}\n", "variables": { "environmentId": "0942e3fe-8ec3-49b4-b8fb-26eb10b6e08f", "serviceId": "783719dc-3c30-437d-a3a9-b1aeb1d5c487" } }'
31 changes: 17 additions & 14 deletions packages/indexer/src/indexers/autocrat/autocrat-proposal-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,25 +222,28 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {

if (!dbDao) continue;

const endSlot: BN = onChainProposal.account.slotEnqueued.add(
new BN(dbDao.slotsPerProposal?.valueOf())
);
// Setup for calculating time left
const initialSlot = new BN(onChainProposal.account.slotEnqueued.toString());

const slotDifference = onChainProposal.account.slotEnqueued
.add(new BN(dbDao.slotsPerProposal?.valueOf()))
.sub(new BN(currentSlot));
const slotsPerProposal = new BN(dbDao.slotsPerProposal?.toString());

const lowHoursEstimate = Math.floor(
(slotDifference.toNumber() * 400) / 1000 / 60 / 60
);
//const endSlot: BN = initialSlot.add(slotsPerProposal);

const currentSlotBN = new BN(currentSlot.toString());

const slotDifference = initialSlot
.add(slotsPerProposal)
.sub(currentSlotBN);

// Our check to ensure we're actually updating the time correctly.
if (currentSlot <= endSlot.toNumber() && lowHoursEstimate <= 0) {
console.error("Issue with slot update contact administrator");
}
// Setup time to add to the date..
const timeLeftSecondsEstimate = (slotDifference.toNumber() * 400) / 1000 // MS to seconds
// const timeLeftMinutesEstimate = timeLeftSecondsEstimate / 60 // MS to seconds to minutes
// const timeLeftHoursEstimate = timeLeftMinutesEstimate / 60

const endedAt = new Date(currentTime.toUTCString());
endedAt.setHours(endedAt.getHours() + lowHoursEstimate);
// endedAt.setHours(endedAt.getHours() + timeLeftHoursEstimate);
// endedAt.setMinutes(endedAt.getMinutes() + timeLeftMinutesEstimate);
endedAt.setSeconds(endedAt.getSeconds() + timeLeftSecondsEstimate); // setSeconds accepts float and will increase to hours etc.

await usingDb((db) =>
db
Expand Down

0 comments on commit fa44b2b

Please sign in to comment.