want the script to help calculate when to buy songs?
I wrote this really quickly and probably has some incorrect math somewhere, but it was still fun nonetheless..... use at on risk, yada yada yada... If you don't know what to do with this, don't mess with it. You'll have to use terminal. You're going to make two files in a directory... count.pl and counting.results. Don't forget to make count.pl executable (ie. chmod 755 count.pl)
-------- count.pl ---------
#!/usr/bin/perl
$| = 1;
use strict;
my($date, $time, $songs, %entries);
$time = time();
open(RESULTS,"< counting.results");
while(<RESULTS>) {
chomp;
($time,$songs) = split(/,/, $_);
$entries{$time} = $songs;
}
close(RESULTS);
sub print_est {
my($time, $start_time, $start_songs);
my ($million, $next_hundred_thousand);
my ($current_average);
my ($prev_time, $current_songs_since, $current_time_since);
my ($current_next_hundred_thousand, $current_million);
foreach $time (sort {$a <=> $b} (keys(%entries))) {
my($date, $num_songs, $time_since, $songs_per_minute);
unless ($start_time) {
$start_time = $time;
$start_songs = $entries{$time};
next;
}
$date = localtime($time);
$num_songs = $entries{$time} - $start_songs;
$current_songs_since = $entries{$time} - $entries{$prev_time};
$time_since = int(($time - $start_time)/60);
$current_time_since = (($time - $prev_time)/60);
$songs_per_minute = int($num_songs / $time_since);
$current_average = int($current_songs_since / $current_time_since);
print "$date - $num_songs songs [$entries{$time}] $time_since minutes $current_average songs/minute ($songs_per_minute)\n";
$next_hundred_thousand = int((((100000-($entries{$time} % 100000))/$songs_per_minute)*60)+$time);
$current_next_hundred_thousand = int((((100000-($entries{$time} % 100000))/$current_average)*60)+$time);
$million = int((((100000000 - ($entries{$time} % 100000000))/ $songs_per_minute) * 60) + $time);
$current_million = int((((100000000 - ($entries{$time} % 100000000))/ $current_average) * 60) + $time);
$prev_time = $time;
}
print "\nCurrent Date: ".localtime(time())."\n";
print "Next Hundred Thousand: ".localtime($next_hundred_thousand)."\n";
print "Next Million: ".localtime($million)."\n\n";
print "Next Current Hundred Thousand: ".localtime($current_next_hundred_thousand)."\n";
print "Next Current Million: ".localtime($current_million)."\n\n";
}
my ($temp_songs);
open(RESULTS,">> counting.results");
while($temp_songs ne "q") {
print_est();
print "Last Entry: $songs songs\n";
print "Enter Number of Songs sold, press [ENTER] to View Results, or q to quit\n";
print "[#,<ENTER>,q]: ";
$temp_songs = <>;
chomp $temp_songs;
if (($temp_songs) and ($temp_songs ne "q")) {
$songs = $temp_songs;
$time = time();
$entries{$time} = $songs;
print RESULTS "$time,$songs\n";
}
}
close(RESULTS);
-------- end of count.pl --------
-------- counting.results ------
1088883841,95691713
1088884261,95693993
1088884561,95699366
1088884981,95702835
1088885461,95707903
1088886001,95712563
1088886481,95715140
1088886961,95720280
1088887561,95724963
1088888101,95727438
1088892602,95763717
1088921043,95955133
1088921665,95958459
1088922171,95959512
1088922408,95960794
1088923222,95963310
1088923432,95964589
1088923923,95966338
1088924307,95967502
1088925623,95971861
1088926920,95974084
1088927012,95974719
1088927098,95975479
1088927382,95976460
1088928800,95979208
1088929147,95980214
1089097799,96911788
1089116083,96941904
1089261761,97838655
1089296336,97951608
1089395739,98541026
1089438570,98855876
1089504560,99247764
1089521006,99373617
--------- end of counting.results ---------