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

Wrong state in API for dipped GK #1063

Open
okainov opened this issue Sep 3, 2024 · 5 comments
Open

Wrong state in API for dipped GK #1063

okainov opened this issue Sep 3, 2024 · 5 comments

Comments

@okainov
Copy link
Member

okainov commented Sep 3, 2024

Reported by gc.su users

GK: https://geokrety.org/ru/geokrety/GK14227
Website shows correctly that it was dipped in the cache https://geocaching.su/?pn=101&cid=31933.

However in the differential API it shows wrong state 0 ("dropped")

https://geokrety.org/api/v1/export_oc?modifiedsince=20240903070000&timezone=Europe%2FParis&compress=0

image

Please fix the API results so it shows the correct state (5?)

It's even mentioned in the API docs (https://geokrety.org/help/api#syncmethod1) that dipped ones should have value of "grabbed"

kumy added a commit that referenced this issue Feb 16, 2025
@kumy
Copy link
Member

kumy commented Feb 16, 2025

You're using /api/v1/export_oc, so the correct doc is https://geokrety.org/help/api#syncmethod2.

Image
However the doc say if someone dips a GeoKret, its state will be 1 (grabbed) which is in any case also not what you see (0).

After checking the code, on this endpoint the state show if the GK is in a cache or not. So on a dipped, 0 looks the right result ("absent from cache"). I believe however that the doc is wrong "if someone dips a GeoKret, its state will be 1 (grabbed)", should be if someone drop/meet, its state will be 1, and grab/dip will be 0

$xml->writeElement('state', $geokret->move_type->isTheoricallyInCache() ? '1' : '0');

Regarding https://geokrety.org/help/api#syncmethod1, given the code, this field is the actual logtype ID.

$xml->writeAttribute('state', $geokret->move_type->getLogTypeId());

--
doc adjusted via #1093

Image

github-merge-queue bot pushed a commit that referenced this issue Feb 18, 2025
@kumy kumy closed this as completed Mar 23, 2025
@okainov
Copy link
Member Author

okainov commented Mar 23, 2025

So on a dipped, 0 looks the right result ("absent from cache").

Wait-wait-wait! 0 is "dropped" which is IN THE CACHE, isn't it? It's not "absent".

That's what we rely on in our scripts:

   # 0 = Dropped to; 1 = Grabbed from; 2 = A comment; 3 = Seen in; 4 = Archived; 5 = Visiting;
   was_dropped = self.state in [0, 3]

As we want to show only GK that next visitor can actually find in the cache.

@okainov okainov reopened this Mar 23, 2025
@okainov
Copy link
Member Author

okainov commented Mar 23, 2025

Maybe I mixed up some URLs btw, that's from our production code as well:

INCREMENTAL_URL = "https://geokrety.org/export_oc.php?modifiedsince=%s"
FULL_DB_URL = "https://cdn.geokrety.org/exports/geokrety.xml"

@okainov
Copy link
Member Author

okainov commented Mar 23, 2025

if someone drop/meet, its state will be 1, and grab/dip will be 0

So basically at some point the interface of these endpoints was changes to completely opposite values? We had one script to rule them all which was able to handle data regardless of full export and incremental correctly. And now it sounds like we need to add some hack to treat "0" in one case completely differently from another... That sounds sad...

@kumy
Copy link
Member

kumy commented Mar 23, 2025

I think you are mixing 2 APIs...

FULL_DB_URL = "https://cdn.geokrety.org/exports/geokrety.xml" is an export from export2 format, while INCREMENTAL_URL = "https://geokrety.org/export_oc.php?modifiedsince=%s" is using export_oc format.

Did you try the export2 api?
INCREMENTAL_URL = "https://geokrety.org/export2.php?modifiedsince=%s"


I took one with state=1 from export_oc https://geokrety.org/en/geokrety/GK565F

  <geokret id="22111">
    <name><![CDATA[Quieschente ohne quietsch!]]></name>
    <distancetravelled>1682</distancetravelled>
    <state>1</state>
    <position latitude="50.89835" longitude="8.06732"/>
    <waypoints>
      <waypoint><![CDATA[GCR6TH]]></waypoint>
    </waypoints>
  </geokret>

It's last log is dropped, so it is present in cache, "state=1" is valid for export_oc format
Image

and one with state=0 https://geokrety.org/en/geokrety/GK58C8

  <geokret id="22728">
    <name><![CDATA[Drewniany Pan]]></name>
    <distancetravelled>10395</distancetravelled>
    <state>0</state>
    <position latitude="51.59365" longitude="16.04848"/>
    <waypoints>
      <waypoint><![CDATA[OP9W24]]></waypoint>
    </waypoints>
  </geokret>

last log is dipped, so not rpesent in cache, "state=0" is valid for export_oc format

now with export2:

$ curl -Ss "https://geokrety.org/api/v1/export2?gkid=22111"|xmlstarlet fo
<?xml version="1.0" encoding="UTF-8"?>
<gkxml version="1.0" date="2025-03-23 11:02:01" date_Iso8601="2025-03-23T11:02:01+00:00">
  <geokrety>
    <geokret id="22111" type="0" collectible="true" owner_id="9675" ownername="15wombat" dist="1682" date="2025-03-21" lat="50.89835" lon="8.06732" waypoint="GCR6TH" state="0" last_pos_id="6176452" last_log_id="6176452" places="15"><![CDATA[Quieschente ohne quietsch!]]></geokret>
  </geokrety>
</gkxml>


$ curl -Ss "https://geokrety.org/api/v1/export2?gkid=22728"|xmlstarlet fo
<?xml version="1.0" encoding="UTF-8"?>
<gkxml version="1.0" date="2025-03-23 11:01:35" date_Iso8601="2025-03-23T11:01:35+00:00">
  <geokrety>
    <geokret id="22728" type="0" collectible="true" owner_id="13799" ownername="zastęp aGG" holder_id="42296" holdername="" dist="10395" date="2025-03-19" state="5" last_pos_id="6170296" last_log_id="6170296" places="494" image="GK58C8_6503cbe502ce1"><![CDATA[Drewniany Pan]]></geokret>
  </geokrety>
</gkxml>

States a 0 and 5 which represent the move type. which map with the comment in your code

  # 0 = Dropped to; 1 = Grabbed from; 2 = A comment; 3 = Seen in; 4 = Archived; 5 = Visiting;
   was_dropped = self.state in [0, 3]

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

No branches or pull requests

2 participants