Python script, runs well, but not perfectly, debugging help.
Posted
by S1syphus
on Stack Overflow
See other posts from Stack Overflow
or by S1syphus
Published on 2010-04-09T20:04:00Z
Indexed on
2010/04/10
12:13 UTC
Read the original article
Hit count: 380
python
What it does (sort of)... or is meant to, the script reads from a csv file that contains information on sound files and create a play list exactly 60 minutes long.
An example csv, contains:
their title, duration (in seconds), minium total time to be played (in minutes)
An example is:
Soundfoo,120,10
Soundbar,30,6
Sounddev,60,20
Soundrandom,15,8
The script works out the minimum instances of plays, take 'Soundfoo' for example, the length of each sample is 120 seconds and the minimum time to be played is 10 minutes, so basic maths 10*60/120 gives the number of instances the song is to be played, in this case 5.
It is meant to take minimum number of instances and spread out equally from each other; so there will never be a period where for example Soundbar is played twice in a row.
Then if the minium instances of each song has been used, and there is still time with in the 60 min, how is it possible to tell it to go back and fill the time by selecting each sound and including it till the 60 min is filled while remaining sparsely populated.
Heres the issue(s)!
The script fails to calculate the actual time require to play all the sounds in a file and the total time of the playlist, the thing is tho it doesn't get it wrong all the time maybe 3/5 times, even if I run it on the same csv file it will give me different answers.
Here is the file I shall run the script on e for sake of ease to see the issue:
Sound1,60,10
Sound2,60,10
Sound3,60,10
Sound4,60,10
Sound5,60,10
Sound6,60,10
I'll do it three times and post the results:
1 Required playtime in minutes: 60 Actual time in minutes to play all required ads: 62 Total playtime in minutes: 62.0
2 Required playtime in minutes: 60 Actual time in minutes to play all required ads: 71 Total playtime in minutes: 71.0
3 Required playtime in minutes: 60 Actual time in minutes to play all required ads: 60 Total playtime in minutes: 60.0
Relevant Code:
pastebin.com/demkBXk6
And finally... in context:
If you made it down to here, thanks for staying and reading, kudos.
© Stack Overflow or respective owner