Options

API Google DotNet

RikarddoRikarddo Member Posts: 80
Hello,

I am trying to create a Report Only processing, that calculates the distance between two Local Post Codes ( My Company WhareHouse and Client).
I'm using a variable dotnet getdistance from google to calculate the distance. But i have some problems.
I have more than 30k lines to calculate, and not all gives back distance different from 0.

My table structure is like this:

Customer No|PostCodeOrigin|PostCodeDestination|Distance
where
Customer No|PostCodeOrigin|PostCodeDestination is a key.


the code does something like this

MyTable.RESET;
IF MyTable.FINDSET THEN REPEAT
...
Code to get the Post Codes and other data
.....
Distance:=GetDistance(PostCodeOrigin, CountryOrigin,PostCodeDestination,CountryDestination);
IF Distance= 0 THEN
Distance:=1;// so i can know what calculation failed
Mytable.Modify;
COMMIT;
SLEEP(1000);

Until Mytable.Next=0;

How can i complement the variable distance so that if it gets 0 there can be other way to get distance by other fields of Customer and Location tables.
Then how can i pass the limit of requests . I don't know what is the limit but i guess is very little.
Or is other way of getting distance between to points in NAV?

Really need help on this one :-/



Comments

  • Options
    lubostlubost Member Posts: 615
    1. How is distance calculated/obtained?
    2. COMMIT is bad, especially inside loop.
    3. Your code is probably a part of some batch process and you should divide it to filling other data and distance setting processes.
  • Options
    RikarddoRikarddo Member Posts: 80
    My variable:

    Name: getDistance
    DataType : DotNet
    Subtype : GetDistance.GetDistance.'GetDistance, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
    Length

    Why commit is bad?
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    COMMIT is bad because if you run the report as a part of some bigger code you will get unexpected commits half way through your process. If this report is standalone and will never be used as a part of some bigger process then it is fine.. However you know what they say - never say never, which imho is true especialy in software/coding domain

    Better than COMMIT imho would be to put your call to GetDistance in a TryFunction, so any .NET errors would not rollback transaction
    REPEAT
      IF NOT TryGetDistance(..) THEN
        CalcDistanceUsingAlternativeMethod(...)
    UNTIL...
    

    There is no generic way of getting a distance in NAV.

    You mat come up with some alghoritm (store geo coordinates along post-codes?), or build your own .NET assembly, or use som alternative WEB API (Bing?), or build/get table of distances between postcodes in some external software, preload it into NAV table and keep it as a dictionary. You can also ask a user and how far is between A and B and remember the answer for future use.

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Also I'd be questioning using Customer No in Primary key. Your own code sample
    Distance:=GetDistance(PostCodeOrigin, CountryOrigin,PostCodeDestination,CountryDestination);
    
    shows clearly that the distance between point A and B does not depend on Customer No. - so why to store and calculate the same thing over and over for different customers?
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.