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

Poe zone tracker service #63

Merged
merged 16 commits into from
Dec 7, 2023

Conversation

kongsgaard
Copy link

@kongsgaard kongsgaard commented Nov 29, 2023

Added a poe-zone-tracker-service, which aggregates from the poe-client-log-service into zones.

Information is aggregated in a PoeZoneDelta type, which represents the things that happened within entrance to exit of a zone. PoeZoneInstances represents an actual instance of a zone in PoE, so one PoeZoneInstance can have multiple PoeZoneDeltas, if the zone was entered/exited multiple times.
Currently hideouts and towns have individual PoeZoneInstance objects per enter/exit.

Two subjects are exposed, zoneEntered$ and zoneExited$. The PoeZoneDelta will be the same object, just with more information when emitted from the zoneExited$ event stream.

The character features are removed from this PR, and will be developed later
The character snapshot/delta is currently not working fully. Partially due to a long default stale_ms on the smart_cache, and because the delta for stuff like curreny stack-sizes are not calculated currectly. So if a chaos orb stack was incremented from 2 to 5, it will not show up in the inventoryDelta, as these items still has the same id.
In general, alot more utilities for calculating inventory/stash diff of literal items over time should be implemented.

I will write an .md file for both the poe-client-log-service and the poe-zone-tracker-service, to document usage. After that i will try to make the zone-tracker more robust to errors.

.character(charName) //TODO Find a solution to call this function to get non-stale data, probably more intelligent rate-limiter
.pipe(
filter((e) => e.type == 'result'), //MAKE SURE ERRORS ARE HANDLED ASWELL. PROBABLY USE OF + ZIP TO CHECK CURRENT ZONE IS STILL THE SAME IN CASE OF RATELIMIT
map((e) => e as SmartCacheResultEvent<PoeCharacter>),
Copy link
Author

Choose a reason for hiding this comment

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

Is this really the way to get typescript to recognize the type, or am i missing something?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

validResults has a more strict type definition so typescript will recognize the types.

@kongsgaard
Copy link
Author

Is the build failing something that is currently being resolved in another branch?
Or did i screw something while merging?

@@ -32,6 +37,7 @@ export function buildContext(contextSource: string): EchoContext {
plugins: ECHO_PLUGIN_SERVICE,
poeAccounts: POE_ACCOUNT_SERVICE,
poeClientLog: POE_CLIENT_LOG_SERVICE,
PoeZoneTracker: POE_ZONE_TRACKER_SERVICE,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the casing is wrong here

@@ -12,5 +12,5 @@
"jsx": "react-jsx",
"sourceMap": true
},
"include": ["./src"]
"include": ["./src", "./test"]
Copy link
Contributor

Choose a reason for hiding this comment

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

@kongsgaard this change is what is breaking the build.

When you add this folder, it changes the paths that the build generates (adds a /src and /test

If you update the package exports here and here with the new generated paths, everything works

let tail: Tail

beforeEach(() => {
const filename = Math.floor(Math.random() * 999999999999) + '.txt'
Copy link
Member

Choose a reason for hiding this comment

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

if there isn't a reason these need to be numbers it would probably be better to use https://www.npmjs.com/package/uuid I think we already have this as a dep everywhere.

Copy link
Author

Choose a reason for hiding this comment

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

I added and now use the uuid package, it was not originally used in echo-common

.subscribe((event) => {
if (this.currentZoneDelta === undefined) {
//Emit as event
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

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

Throwing errors inside a subscribe like this will make it impossible to catch them anywhere. That might be okay if these are errors that should never happen, but even then since they are uncatchable converting them to just logging warnings/errors probably makes more sense.

Copy link
Author

Choose a reason for hiding this comment

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

Created another subject which emits errors. Maybe the service should temporarily timeout on such an event, to avoid spamming errors, but i am not entirely sure on the best way of handing these "errors"

this.currentZoneDelta.deltaLoadTime = event.systemUptime - loadStart

if (this.characterService != undefined) {
const charName = 'BlaesendeBruno' //TODO from settings
Copy link
Member

Choose a reason for hiding this comment

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

We probably want to use the character with current set to true from the character list as a general solution, or make this class more of a util than a context() object. If it was constructed by the plugins themselves they could pass in and manage what character to track themselves.

Copy link
Author

Choose a reason for hiding this comment

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

I removed the character based stuff for now, as it was not properly ready to be merged into main and be used elsewhere

Comment on lines 279 to 280
filter((e) => e.type == 'NPCEncounterEvent'),
map((e) => e as PoeNPCEncounterEvent)
Copy link
Member

@zach-herridge zach-herridge Nov 30, 2023

Choose a reason for hiding this comment

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

Checks like these could be converted to if(e.type !== "XXXXX") return; in the subscribe, since the filter/map aren't doing anything special in the pipe.

Copy link
Author

Choose a reason for hiding this comment

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

Seems like a better way to handle it in general yes

@kongsgaard
Copy link
Author

I updated the pull-request based on the review.

I removed the half-baked character based stuff, as it was not entirely ready to be used. I have stashed it and will work on making it more solid, and get it into service once some other elements (such as a more centralized 'current character') is in place

@kongsgaard
Copy link
Author

Btw this is ready to be re-reviewed, or merged

@zach-herridge zach-herridge merged commit 77976f3 into PoeStack:main Dec 7, 2023
1 check passed
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.

None yet

3 participants