Simple equation help

I am putting this post in the beginners section, because this is basic algebra and I fell stupid for not being able to solve this.

Situation:
An algorithm backs up files which are iterated from a specified number of folders the user lists for the program to use.

sub-algorithms:

Stage 1: User-defined directories: checks and balances...
Stage 2: Set up the file-system's structure, copy all folders (not files) into the target directory as they are in the system.
Stage 3: Copy all files iterated from user-specified folders into the newly-created, identical filesystem in the target directory.

At stage 3 we can assume 2 percentage values: 1, percent of user-defined directories we have been through and 2, the number of files copied from 1 of the user specified directories. The total number of directories and files that are iterated for every user-defined directory (except the current one) is unknown.

Solution:
Since we have 2 percentages: 1 being the total percentage, the other being the percentage of a fraction of the total percentage; we can make an equation to further exact a total percentage.

"Why do we need to do this??" because, the user can specify folders, and since we iterate everything in that folder, a percentage of the number of directories the user has defined would be inaccurate.

I created a special function for this:

1
2
3
4
5
6
7
int percent_of_percent_complete(int x1, int xmax1, int x2, int xmax2)
{
    float percent2 = 0;
    int percent1 = 0;
    percent2 = (float(percent_complete(x1, xmax1)) / (xmax2 * x2));
    return floor(percent2);
}


This function operates on 2 assumptions:

1- the percentage completion of 1 user-defined directory (as derived from x1, and xmax1) is but a fraction of the total percent complete (as derived from x2, and xmax2).

2- none of the variables can be the equivilant of (-).
*****************************************************************************

If someone could give me a solid equation, I would really appreciate it. This isn't for school, I am learning this by myself. I really would like to have a total percent display so I know how far along it is in general.

I actually created this for my personal use, and have successfully performed many 61.8 Gb backups to my external hard drive. :) That takes long to do, as you can imagine and has prompted me to make total percent complete display.

Thank you all for your time.
Last edited on
Alright, new equation:

1
2
3
4
5
6
7
8
9
10
int percent_of_percent_complete(int x1, int xmax1, int x2, int xmax2)
{
    if(x2 == 0)
    {
        x2++;
    }
    float percent2 = 0;
    percent2 = (((float(percent_complete(x1, xmax1)) * (percent_complete(1, xmax2))) / 100) + (percent_complete(1, xmax2) * x2));
    return floor(percent2);
}


I got some help from someone, but it still isnt right. This is, however the closest I have gotten to accurate.

I would also like to make an additiuonal note:
the percent value of x1, and xmax1 go from 0-100 for each directory the user specifies. So, that explains the complexity of my equation.
Last edited on
please?
I don't really understand what you want.
A guess, you want to implement cp -r but showing the progress, with a percentage. ¿a percentage of what? ¿the number of file-systems?, ¿the size?
However you say that `the total number of directories and files that are iterated is unknown', ¿so how do you define that percentage?

IWishIKnew wrote:
This isn't for school, I am learning this by myself.
You don't seem to understand the meaning of homework.
@ne555

You don't seem to understand the meaning of homework.


Too bad this isn't homework then, eh? I'm not even in school yet.

On another note:

To better clear things up-

The algorithm will go down a list of directories that the user sets. For each directory, it will perform the following algorithm:

1 - Iterate the files/folders
2 - Create the folders (directories/subdirectories) under the target folder in an identical 'structure' to the origional.
3 - now we have an identical directories/subdirectories (only folders) under our target directory, so copy all of our files into their corresponing directories/subdirectories under the target directory.
4 - return to the colling function, which will then call this function again with the argument of the next directory (folder/file the user wants backed up).

in steps two and three, we are copying only 1 of many user- defined directories. Because of this, we only know how many files and folders are in that 1 directory. The parent function, being the one that lists the directories and emplements the algorithm on each, can be used to pass a 2nd value: total percent complete, that is how many user-defined directories we have copied, out of the total user-defined directories.

so:

percent value 1 = number of files/folders we have copied from 1 user-defined directory, out of the total number of file and folders in that directory

percent value 2 = number of user defined directories we have completely copied, out of the total number of user-defined directories.

Since the files/folders in 1 given user-defined directory can be iterated at a single time, we can not assume the total number of files/folders contained in the entire backup. This also means that the percentage completion for copying files/folders of 1 of the user-defined directories pertains only to that one user-defined directory: in other words, every time a user-defined directory is finished copying, we assume a new total value of files/folders, and therefore and new percentage. This has the effect of the percentage will start from 0% for each user-defined directory.

If I still haven't made my self clear, please ask.

Examples:

C:\dir1 -> E:\targetfolder\dir1\dir2\dir3 (assume iterated)
C:\dir12\dir22\dir32 -> E:\targetfolder\dir12\dir22\dir32 (assume iterated)

steps:

1 get files and folders for dir1
2 create folder structure adentical to origional
3 copy files iterated to targetfolder (display percent complete)
4 get files and folders for dir12
5 create folder structure adentical to origional
6 copy files iterated to targetfolder (display percent complete)
Last edited on
> If I still haven't made my self clear, please ask.
¿what's your question?
Let me see if I understand.
The user does
$ backup --progress code/ image/ music/ video/ /mnt/backup
You say: 4 directories so 0.25 each. (1)

Now let's say that you are halfway in the second directory.
As you already done the first one you've got 0.25 + 0.5*0.25 = 0.375 from the total progress.

However (1) is a lie
No, not quite......


The algorithm takes the entire directory, from C:\... to the folder the user wants to back up.

It then knocks of "C:\" leaving us with the 'relative directory'. We append the relative directory to the end of out target directory. ex:

User directory1 = C:\users\username\desktop
target directory = E:\target

Resulting target directory: E:\target\users\username\desktop

All files and folders in C:\users\username\desktop are iterated. The total number of files and folders in C:\users\username\desktop is 100% of that 1 directory, while the number of the files and folders that we have copied so far from that directory is used to calculate how far we are in copying that directory.

now, say we have...

C:\users\username\desktop
C:\Program Files\game
C:\Program Files\Budgeting app

We will be applying an iteration/copy algorithm to each directory. The new file system in the target folder will look like this:

E:\target\users\username\desktop\...
E:\target\Program Files\...

Because we have 2 user-defined directories that stem from "Program Files", only 1 folder is created. In that folder we would find:

E:\target\Program Files\game\...
E:\target\Program Files\Budgeting app\...

Assume "..." means files and folders which are iterated and copied to those directories.

So, since we have 3 user-defined directories, 100% of 1 directory is not truely 100%, but 100% of 33% of our total backup.

Now, so far we can:

Find the total percent completion using the number of user-defined directories we have copied, and the total of user-defined directories in-all. We can also find the percent complete of 1 user-defined directory that is currently being copied. Numbers from a previous copy can not be carried over into the next.
Last edited on
So, do you understand now?
No. I don't care about your scenario, just say what's the issue.
It is kind of hard to explain....

If you read you would understand.
I will try to shorthand it for you, if you are so lazy that you cant spend 5 minutes reading:

for each user-defined directory, My program displays percent complete from 0-100. I want it to display the percent complete for the entire backup. To do that, I have taken the percent complete of a user-defined directory that is being copied, and the 'total' percent of user-defined directories that have been copied.

I'm trying to find an equation useing these values.

If you do not understand, and can not, for some reason, read my previous posts explaining my situation, please do not post a reply.

Thank you.
closed account (3qX21hU5)
Just because of your attitude I had to reply you dont ask a question you just state your scenario of what you are suppose to do like ne555 said, but you don't actually ask a question like why doesnt this code snippet work?

1
2
3
4
5
6
int main()
{
      int b;
      cout << b + a << endl;
      return 0;
}


Give us something to work with we cant help you if you dont give us a question to solve. And after your previous post you would be lucky even if you did.
Last edited on
hmm... alright:

Here is the problem I need/want to solve: I want it to show total percent complete, but I only have percent complete for a small percent (varies) of a total percent.

I can not seem to get the equation right.
s
Last edited on
IWishIKnew wrote:
hmm... alright:

Here is the problem I need/want to solve: I want it to show total percent complete, but I only have percent complete for a small percent (varies) of a total percent.

I can not seem to get the equation right.
Questions generally end with a question mark and start with a word such as How, When, Where, Why, Is, Does, Will, Has, Can, etc.

For example:
IKnowIWished wrote:
What is the formula for combining sub-percent with total percent?
Last edited on
So, yall don't want to help me because there is no question mark? really? There doiesnt have to be a question for you to be able to help me. You can infer the problem by reading my posts quite easily.

But that's ok. If you don't want to help, this feature is not necessary. I will just have it show the 2 percentages and that will give the user a general idea of where the program is at in the backup.
Turns out, that's the correct solution. See? You subconsciously knew that that was the correct solution and you were unable to ask the question that would suggest otherwise ;)
@LB
sure, that must have been it. No, actually I thought of a solution that might work:

1
2
3
4
5
float total_ratio, fractal_ratio, completion_ratio, final_percent;
total_ratio = (float(xmax2) * 100);
fractal_ratio = (float(x2) * 100);
completion_ratio = (float(percent_complete(x1, xmax1)) + fractal_ratio);
final_percent = float(percent_complete(completion_ratio, total_ratio));


explanation:

x2 starts at 0, so the 1st value is zero plus the percent complete of our current directory.

for every user-defined directory we have copied, that is 100%, so x2 * 100 = percent so far. So, since we multiply x2 by 100, we do the same for xmax2. Since x2 does not include the directory we are currently copying, we add it's percentage to x2. After that, we simply apply the percent algorithm.

That yields total percent complete useing a percent of a percent, and a non-accurate (at least to the 1% anyway) total percent complete.
Last edited on
Topic archived. No new replies allowed.