Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill level change api #8

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Fill level change api #8

wants to merge 10 commits into from

Conversation

ammar450
Copy link

No description provided.

src/app.ts Outdated
@@ -53,7 +57,7 @@ initializeMQTT(globalEventEmitter);

// Middleware
app.use(bodyParser.json());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the new middleware, that you added, we dont need this line anymore, right? How about moving line 25 and 26 to here and removing the bodyparser.json?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks better now, nice :)
But line 25 and 59 are now duplicate, right? So perhaps remove line 25?

src/controllers/project.ts Outdated Show resolved Hide resolved
src/controllers/trashbin.ts Outdated Show resolved Hide resolved
src/controllers/trashbin.ts Outdated Show resolved Hide resolved
src/controllers/trashbin.ts Outdated Show resolved Hide resolved
src/controllers/trashbin.ts Outdated Show resolved Hide resolved
@PaulaScharf
Copy link
Member

ok, all in all this looks really good now :)
Just one thing:
Can you change it, so that instead of the fill level changes since saving the settings it actually calculates the changes from the most recent fill level to the fill level at X hours before (where X is given in the project settings). Also whenever a new fill level measurement comes in, the fill level change gets recalculated.
So the fillLevelChange will basically be a live value, that changes with the incoming measurements.

…pdate new value in trashbin fill level change value.
@@ -98,6 +99,9 @@ export function initializeMQTT(eventEmitter: EventEmitter) {
trashbin[0].fillLevel = fillLevel ? Math.round(fillLevel * 100) : 0;
await trashbin[0].save();
}
await axios.put('http://localhost:5001/api/v1/trashbin/updateFillLevelChanges', {
Copy link
Member

@PaulaScharf PaulaScharf Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is definitely an interesting idea to use axios to call the url of the backend.
Latency wise this is not an optimal solution and it also creates unnecessary overhead.
Please have a look at the src/service folder. For example there is already a function called "generateUniqueTrashbinIdentifier" implemented there. This function can then be imported and used in other places of the backend.
Please refactor your code to also use this service structure to update fillLevelChanges and then import the defined function in the mqtt and trashbin controller file (and dont forget to remove axios from the dependencies in the package.json).
Perhaps you could even make it so, that when a new measurement comes in, not all fillLevelChanges are updated but just the one of the corresponding trashbin (atleast I think, that currently all levelChanges are updated, but perhaps Im misunderstanding).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants