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

MODE_BATCH incorrect city detection #16

Closed
Igreh opened this issue Jan 25, 2024 · 5 comments
Closed

MODE_BATCH incorrect city detection #16

Igreh opened this issue Jan 25, 2024 · 5 comments
Assignees
Labels

Comments

@Igreh
Copy link

Igreh commented Jan 25, 2024

Incorrect detection for some IPs. 109.252.119.71 as an example
PHP API:

docker run --rm -v $(pwd):/app/ php:7-cli php /app/sxgeo_sample.php

IP: 109.252.119.71
array (
  'city' => 
  array (
    'id' => 524901,
    'lat' => 55.75222,
    'lon' => 37.61556,
    'name_ru' => 'Москва',
    'name_en' => 'Moscow',
  ),
  'region' => 
  array (
    'id' => 524894,
    'name_ru' => 'Москва',
    'name_en' => 'Moskva',
    'iso' => 'RU-MOW',
  ),
  'country' => 
  array (
    'id' => 185,
    'iso' => 'RU',
    'lat' => 60,
    'lon' => 100,
    'name_ru' => 'Россия',
    'name_en' => 'Russia',
  ),
)array (
  'city' => 
  array (
    'id' => 524901,
    'lat' => 55.75222,
    'lon' => 37.61556,
    'name_ru' => 'Москва',
    'name_en' => 'Moscow',
  ),
  'country' => 
  array (
    'id' => 185,
    'iso' => 'RU',
  ),
)array (
  'Created' => '2023.11.16',
  'Timestamp' => 1700171947,
  'Charset' => 'utf-8',
  'Type' => 'SxGeo City EN',
  'Byte Index' => 224,
  'Main Index' => 1775,
  'Blocks In Index Item' => 3376,
  'IP Blocks' => 5994260,
  'Block Size' => 6,
  'City' => 
  array (
    'Max Length' => 127,
    'Total Size' => 2682917,
  ),
  'Region' => 
  array (
    'Max Length' => 175,
    'Total Size' => 109379,
  ),
  'Country' => 
  array (
    'Max Length' => 147,
    'Total Size' => 9387,
  ),
)`

PYSYGE

from pysyge.pysyge import GeoLocator, MODE_BATCH, MODE_MEMORY
geodata = GeoLocator('/tmp/SxGeoCity.dat', MODE_BATCH | MODE_MEMORY)
print('DB version %s (%s)' % (geodata.get_db_version(), geodata.get_db_date()))
geodata.get_location('109.252.119.71', detailed=True)

DB version 22 (2023-11-17 04:59:07)
Out[3]: 
{'country_id': 174,
 'country_iso': 'PL',
 'region_id': 3337499,
 'city': 'Щецин',
 'lon': 14.55302,
 'lat': 53.42894,
 'fips': '0',
 'info': {'city': {'id': 3083829,
   'lat': 53.42894,
   'lon': 14.55302,
   'name_ru': 'Щецин',
   'name_en': 'Szczecin'},
  'region': {'id': 3337499,
   'name_ru': 'Западно-Поморское воеводство',
   'name_en': 'Zachodniopomorskie',
   'iso': 'PL-ZP'},
  'country': {'id': 174,
   'iso': 'PL',
   'lat': 52.0,
   'lon': 20.0,
   'name_ru': 'Польша',
   'name_en': 'Poland'}},
 'region': 'Западно-Поморское воеводство',
 'tz': ''}
@idlesign
Copy link
Owner

Do you use the same DB version in both cases?

@Igreh
Copy link
Author

Igreh commented Jan 26, 2024

Yeap, check this output to be sure:

from pysyge.pysyge import GeoLocator, MODE_BATCH, MODE_MEMORY
from pprint import pprint
geodata = GeoLocator('/tmp/SxGeoCity.dat', MODE_BATCH | MODE_MEMORY)
# print('DB version %s (%s)' % (geodata._db_ver, geodata._db_ts))
pprint(geodata._prolog)  # added to class manually
geodata.get_location('109.252.119.71', detailed=True)

{'b_idx_len': 224,
 'charset': 0,
 'city_size': 2682917,
 'country_size': 9387,
 'db_items': 5994260,
 'id_len': 3,
 'm_idx_len': 1775,
 'max_city': 127,
 'max_country': 147,
 'max_region': 175,
 'pack_size': 157,
 'range': 3376,
 'region_size': 109379,
 'ts': 1700171947,
 'type': 3,
 'ver': 22}
Out[4]: 
{'country_id': 174,
 'country_iso': 'PL',
 'region_id': 3337499,
 'city': 'Щецин',
 'lon': 14.55302,
 'lat': 53.42894,
 'fips': '0',
 'info': {'city': {'id': 3083829,
   'lat': 53.42894,
   'lon': 14.55302,
   'name_ru': 'Щецин',
   'name_en': 'Szczecin'},
  'region': {'id': 3337499,
   'name_ru': 'Западно-Поморское воеводство',
   'name_en': 'Zachodniopomorskie',
   'iso': 'PL-ZP'},
  'country': {'id': 174,
   'iso': 'PL',
   'lat': 52.0,
   'lon': 20.0,
   'name_ru': 'Польша',
   'name_en': 'Poland'}},
 'region': 'Западно-Поморское воеводство',
 'tz': ''}

and for php:

cat sxgeo_sample.php 

<?php
chdir("/app/");

include("SxGeo.php");
$SxGeo = new SxGeo('SxGeoCity.dat', SXGEO_BATCH | SXGEO_MEMORY); // Самый производительный режим, если нужно обработать много IP за раз

$ip = '109.252.119.71';

print("IP: $ip\n");
var_export($SxGeo->info);
print("\n");
var_export($SxGeo->get($ip)); // Вся информация о городе
docker run --rm -v $(pwd):/app/ php:7-cli php /app/sxgeo_sample.php

IP: 109.252.119.71
array (
  'ver' => 22,
  'time' => 1700171947,
  'type' => 3,
  'charset' => 0,
  'b_idx_len' => 224,
  'm_idx_len' => 1775,
  'range' => 3376,
  'db_items' => 5994260,
  'id_len' => 3,
  'max_region' => 175,
  'max_city' => 127,
  'region_size' => 109379,
  'city_size' => 2682917,
  'max_country' => 147,
  'country_size' => 9387,
  'pack_size' => 157,
  'regions_begin' => 35973753,
  'cities_begin' => 36083132,
)
array (
  'city' => 
  array (
    'id' => 524901,
    'lat' => 55.75222,
    'lon' => 37.61556,
    'name_ru' => 'Москва',
    'name_en' => 'Moscow',
  ),
  'country' => 
  array (
    'id' => 185,
    'iso' => 'RU',
  ),
)

@idlesign idlesign added the bug label Jan 26, 2024
@idlesign
Copy link
Owner

Thank you for the report.
It seems that something has changed in db struct, even prologue differs (new cities_begin, regions_begin items in php version).
Need to sync eventually.

@Igreh
Copy link
Author

Igreh commented Jan 29, 2024

MEMORY mode is broken. MODE_FILE gives us correct results (at least for '109.252.119.71')
Hope it helps =)

from pysyge.pysyge import GeoLocator, MODE_BATCH, MODE_MEMORY
from pprint import pprint
geodata = GeoLocator('/tmp/SxGeoCity.dat', MODE_BATCH | MODE_MEMORY)
pprint(geodata.get_location('109.252.119.71', detailed=True))
{'city': 'Щецин',
 'country_id': 174,
 'country_iso': 'PL',
 'fips': '0',
 'info': {'city': {'id': 3083829,
                   'lat': 53.42894,
                   'lon': 14.55302,
                   'name_en': 'Szczecin',
                   'name_ru': 'Щецин'},
          'country': {'id': 174,
                      'iso': 'PL',
                      'lat': 52.0,
                      'lon': 20.0,
                      'name_en': 'Poland',
                      'name_ru': 'Польша'},
          'region': {'id': 3337499,
                     'iso': 'PL-ZP',
                     'name_en': 'Zachodniopomorskie',
                     'name_ru': 'Западно-Поморское воеводство'}},
 'lat': 53.42894,
 'lon': 14.55302,
 'region': 'Западно-Поморское воеводство',
 'region_id': 3337499,
 'tz': ''}

from pysyge.pysyge import GeoLocator, MODE_BATCH, MODE_MEMORY
from pprint import pprint
geodata = GeoLocator('/tmp/SxGeoCity.dat')
pprint(geodata.get_location('109.252.119.71', detailed=True))
{'city': 'Москва',
 'country_id': 185,
 'country_iso': 'RU',
 'fips': '0',
 'info': {'city': {'id': 524901,
                   'lat': 55.75222,
                   'lon': 37.61556,
                   'name_en': 'Moscow',
                   'name_ru': 'Москва'},
          'country': {'id': 185,
                      'iso': 'RU',
                      'lat': 60.0,
                      'lon': 100.0,
                      'name_en': 'Russia',
                      'name_ru': 'Россия'},
          'region': {'id': 524894,
                     'iso': 'RU-MOW',
                     'name_en': 'Moskva',
                     'name_ru': 'Москва'}},
 'lat': 55.75222,
 'lon': 37.61556,
 'region': 'Москва',
 'region_id': 524894,
 'tz': ''}

idlesign added a commit that referenced this issue Feb 9, 2024
idlesign added a commit that referenced this issue Feb 9, 2024
@idlesign
Copy link
Owner

idlesign commented Feb 9, 2024

MODE_BATCH seems to be fixed in master now.
You may want to try it out.

@idlesign idlesign changed the title incorrect city detection MODE_BATCH incorrect city detection Feb 9, 2024
@idlesign idlesign removed the question label Feb 9, 2024
@idlesign idlesign self-assigned this Feb 9, 2024
@idlesign idlesign closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants