How to correct Linear file sync progress percentage

Hello everyone! I have some problem with correct calculating synchronization progress. I use GET /rest/db/status for getting infomation of sync folder and try to calculate by this formela:

    result = Math.Floor(100 * (1 - (neededBytes / totalBytes)))); 

So I getting valid percentage, but I would like to other way of calculate. F.e there are files in the sync folder and they are synchronized. Next I add the files to the folder and I would like to get percentage from 0 - 100% like a copy progress not from current state% - 100%.

Is this a math question or is there a Syncthing bug? :thinking:
Everybody here is good at hunting bugs, idk about math :crazy_face:

Do you mean haveBytes = totalBytes - neededBytes ?

Hey, I can do maths as long as were talking applied math (I have not much clue about topology and similar nicenesses). That doesn’t sound like a math question though :slight_smile:

There’s nothing built in. What you could do is subscribe to the event apib for folder status, then when it enters sync preparing our syncing status query db/status to get the initial haveBytes and then take that into account for “sync percentage”.

1 Like

I think i need something like this?

        long totalBytes = 0;
        totalBytes = needBytes + globalBytes;
        result = (int)Math.Floor(Convert.ToDouble(100 * (1 - ((double)globalBytes / (double)totalBytes))));

I don’t understand that. What I meant i pseudo-code:

for state in folderStateEventQueue:
  if state == syncPreparing || state == syncing {
    haveInitial = queryStatusEndpoint().haveBytes
status = queryStatusEndpoint
result = 100 * ((status.haveBytes - haveInitial) / (status.globalBytes - haveInitial))
1 Like