Need PHP real quick

Discussion in 'OT Technology' started by sparq, Jul 24, 2006.

  1. sparq

    sparq New Member

    Joined:
    Dec 3, 2004
    Messages:
    13,183
    Likes Received:
    0
    Location:
    Syracuse
    n/m I fixed it...
     
    Last edited: Jul 24, 2006
  2. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,922
    Likes Received:
    11
    Location:
    Los Angeles
    Fantastic.
     
  3. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    PHP:
    #!/usr/bin/perl

    print "PHP Blows";
     
  4. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    heh, cgi perl sucks bfdd.
     
  5. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Everything on the web sucks. The whole fucking WWW is nothing more than a bunch of glorified Word documents. I want a unified, precompiled executable language I can develop in a comfortable IDE environment and distribute over the web. So far, the closest thing I've seen is ActiveX, but I haven't played with it enough to be sure.
     
  6. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,922
    Likes Received:
    11
    Location:
    Los Angeles
    I hope you're not serious.

    Actually, I'm certain this is a parody. 9/10. :bigthumb:
     
  7. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    I have an erie feeling he's being serious, and that is just :ugh:
     
  8. piratepenguin

    piratepenguin New Member

    Joined:
    Jun 18, 2006
    Messages:
    1,067
    Likes Received:
    0
    Location:
    Ireland
    ...what about an executable program users can download and run?

    Of course it won't be multi-platform or anything like that - neither would ActiveX.

    Also see http://discuss.fogcreek.com/joelonsoftware5/default.asp?cmd=show&ixPost=153881&ixReplies=5
     
  9. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Downloading code onto a client's computer isn't particularly safe.
    Documents posing as applications suck as far as usability is concerned.
    Basically neither current paradigm is good enough.

    Having used Citrix MetaFrame rather heavily in the past few weeks, I have to say the idea of hosting a storefront (or some other facility that would normally be a website) as a precompiled application running remotely, accessible via a hyperlink and transmitted interactively in realtime to the client, is extremely appealing.
     
  10. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    negative ghostrider.
     
  11. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Okay, so nothing extra has to be installed for ASP.NET to run; that's good from a compatibility standpoint. Two questions then; does the code run on the client's computer or the server, and can ASP.NET be viewed from a non-Windows machine?

    What I'd love to see is something like the Citrix Metaframe that could run within a browser window, so that the application could be navigated like a website, but the interior of the browser window would be a live feed straight from an application server off in la-la-land. Given that most applications are not nearly as heavy as the ArcGIS suite that I've been using via Citrix for the past few weeks, hosting even thousands of simultaneous instances of a storefront application shouldn't be out-of-reach for a reasonably-modern rack of servers.

    Yes, it would be heavy on bandwidth, but I'm not concerned with 56k users; this is 2006, not 1996. As for bandwidth bottlenecks on the server end, that can be mitigated by using a compressed transmission protocol.

    Those of you who would like to ride my ass for thinking this way, don't bother. Either what I'm talking about already exists in some form, or it will within five years.
     
  12. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Sounds like Java Applets... which blow. In case you missed that memo.
     
  13. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Java, at least via the web, is interpreted and runs on the client computer, if I recall. I'm looking for something that is precompiled, as unified as possible, and runs remotely.

    I know Java can be compiled to run in various OSes, but that doesn't fulfill the compatibility requirement; nobody would wait around for the website to compile itself before they could view it. As it is, it bugs me to have to wait for my browser to instantiate all the objects on a webpage.

    And yes, I know Java Applets suck.
     
  14. piratepenguin

    piratepenguin New Member

    Joined:
    Jun 18, 2006
    Messages:
    1,067
    Likes Received:
    0
    Location:
    Ireland
    See: http://ntw.sourceforge.net/

    There was talk on the mailing list not long ago about creating an ActiveX component and/or a Firefox extension that would be an NTW client, that would achieve what you are describing if I'm understanding correctly. AFAIK no work has begun on the component/extension, yet, but it would make things even more convenient (right now it's kinda convenient because you can have a link to a file that stores the address/IP and port number that an application is listening on, and if you open the file up in an NTW client the app is run, except not inside the browser).

    And plus NTW doesn't use that much bandwidth, since it uses a high-level toolkit protocol.


    Outside of NTW, with current web technologies, using some AJAX magic it's probably possible to catch events (javascript) and send them back to the server and have the server do some work and then send info back to the browser-side (using AJAX again) which can act on the new info. That's bloody cumbersome though, and probably uses ass-loads of bandwidth if the data must be transferred in XML format (I don't have much experience with this kinda stuff so I dunno).
     
  15. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    deusexaethera has a fairly poor understanding of this. Java compiles to byte-code... And that is then run through the JRE on the client machine. There is no other way to do something like this multi-platform... it has to be put into an intermediate language and "run" on the client.
     
  16. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    He just wants to remote desktop. Remote desktopping sucks. I like web apps. They're MUCH easier to make than rich client apps, and can provide as much functionality. Whats more they're open standards. I was a rich client guy. I've been converted.
     
  17. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Funny, because I stopped caring about web apps once I saw the Citrix Metaframe.
     
  18. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    What would that let me do, interact with shitty windows applications? No thanks.
     
  19. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Perl is better, because of the CPAN. I just wrote a program that generates hourly statistics for slot machines, and it was easy... because of the CPAN.

    PHP:
    #!/usr/bin/perl


    # This program reads in CSV files for hourly play rates and game data and enters the data in a SQLite database.  
    # See accompanying examples for hour and game csv, and the sample SQLite database for file formats
    #
    # Use: ./generate.pl (Start Date: YYYY-MM-DD) <hourly weights CSV file> <game data CSV file>
    #
    #
    use strict;

    # For XML Config file
    use XML::Simple;

    # For DB connectivity
    use DBI;
    use 
    DBD::SQLite;

    # Setup date stuff
    use Date::Simple ();

    # Bet Average Default Range
    my $bet_avg_low 2;
    my $bet_avg_high 5;

    # Hold Percent Variance Default Range
    my $hold_variation_low = -5;
    my $hold_variation_high 5;


    # Make sure all args are there and die/print use statement if not
    if($#ARGV < 2) { die "\nInsufficient Arguements\n\nUse: ./generate.pl (Start Date: YYYY-MM-DD) <hourly weights CSV file> <game data CSV file>\n\n"; }


    # Assign ARGs

    my $date_arg $ARGV[0];
    my $hours_filename $ARGV[1];
    my $game_filename $ARGV[2];

    # Initialize date
    my $date Date::Simple->new($date_arg);    

    main();

    sub main {
        

        
    # 2 Arrays of arrays for our hourly weights and game info
        
    my @hourlyWeights;
        
    my @gameInfo;
        
        
    # If config.xml is present, load it
        
    if(-"config.xml" && -"config.xml")
        {
            
    loadConfig("config.xml");
        }
        
        
    # If the filename specifidd exists, then parse the hours CSV
        
    if(-e $hours_filename && -r $hours_filename) {
            @
    hourlyWeights getHourlyWeights($hours_filename);
        }
        else { die 
    "Invalid filename $hours_filename\n"; }
        
        
    # If the filename specified exists, then parse the game CSV
        
    if(-e $game_filename && -r $game_filename) {
            @
    gameInfo loadGameData($game_filename);
        }
            else { die 
    "Invalid filename $game_filename\n"; }

        
    # Initialize the database
        
    my $dbh DBI->connect("dbi:SQLite:dbname=demo.sqlite""""", { RaiseError => 1AutoCommit => }) || die "Unable to connect to database.";

        foreach 
    my $one_game (@gameInfo)
        {
            
    $date Date::Simple->new($date_arg);
            
            
    # Assign our fields to the variables previously used
            
    my $denomination = @$one_game[3];
            
    my $vendor_coeff = @$one_game[6];
            
    my $theo_hold_percent = @$one_game[4];
            
    my $bank = @$one_game[5];
            
    my $vendor = @$one_game[2];
            
    my $gameTitle = @$one_game[1];
            
    my $game_id = @$one_game[0];
            
            
    # Loop through each day and each hour and do the computations
            
    my $day_counter 0;
            foreach 
    my $hourly_weights (@hourlyWeights)
            {    
                
    my $hour_counter 0;
                foreach 
    my $weight (@$hourly_weights)
                {
                    
    #Debug
                    #print "Hourly weight: $weight\n";
                    
                    
    my $date_string $date->as_d8;
                
                    
    # Compute Average Bet
                    
    my $averageBet roundPercentage(getAverageBet($denomination));
        
                    
    # Compute Games Played
                    
    my $gamesPlayed getGamesPlayed($vendor_coeff$weight);
                
                    
    # Compute Gross Sales
                    
    my $grossSales getGrossSales($averageBet$gamesPlayed);
        
                    
    # Compute Hold %
                    
    my $holdPercentage roundPercentage(getHoldPercentage($theo_hold_percent));
        
                    
    # Compute Hold Variance
                    
    my $holdVariance roundPercentage(getHoldVariance($holdPercentage$theo_hold_percent));
        
                    
    # Compute Prizes
                    
    my $prizes roundPercentage(getPrizes($grossSales$holdPercentage));
        
                    
    # Compute Net Win
                    
    my $netWin roundPercentage(getNetWin($grossSales$prizes));
                
                    
    #Debug
                    # Print our CSV
                    #my $outputString = "$day_counter,$hour_counter,$denomination,$grossSales,$prizes,$netWin,$averageBet,$gamesPlayed,$holdPercentage,$theo_hold_percent,$holdVariance\n";
                    #print $outputString;
                
                    # Write to DB
                    
    insertToDB($dbh,$date_string,$game_id,$gameTitle,$vendor,$bank,$day_counter,$hour_counter,$denomination,$grossSales,$prizes,$netWin,$averageBet,$gamesPlayed,$holdPercentage,$theo_hold_percent,$holdVariance);
                
                    
    # Increment hour counter
                    
    $hour_counter++;
                
                }
                
    $day_counter++;
            
                
    # Increment the date
                
    $date++;
            }

        }
        
        
    # Commit the changes once they're all inserted
        
    $dbh->commit();
        
        
    # Must clean disconnect or it will rollback.
        
    $dbh->disconnect();

    }

    # Opens file with game info and returns an array of arrays holding that info
    # ARGS: filename
    # RETURNS: ARRAY of ARRAYS containing the game data from teh CSV
    sub loadGameData {

        
    my $filename shift;
        
    my @games;

        
    open GAMES$filename;
        
        while(<
    GAMES>)
        {
            
    chomp#remove return carriage if it is there
            
    my @tmp split /,/;
            
    push @games, [ @tmp ];    
        }
        
        
    # Return our array of arrays
        
    return @games;

    }

    # Inserts data into DB
    # ARGS: $dbh,$date,$gameID,$gameTitle,$vendor,$bank,$day,$hour,$denomination,$grossSales,$prizes,$netWin,$averageBet,$gamesPlayed,$holdPercentage,$theo_hold_percent,$holdVariance
    sub insertToDB {
        
        
    # Grab our parameters
        
    my $database shift;
        
    my $date shift;
        
    my $gameID shift;
        
    my $gameTitle shift;
        
    my $vendor shift;
        
    my $bank shift;
        
    my $day shift;
        
    my $hour shift;
        
    my $denom shift;
        
    my $grossSales shift;
        
    my $prizes shift;
        
    my $netWin shift;
        
    my $avgBet shift;
        
    my $gamesPlayed shift;
        
    my $holdPercent shift;
        
    my $theoryHold shift;
        
    my $holdVariance shift;
        
        
    # Prepare query
        
    my $sth $database->prepare(qqINSERT INTO hourly (slotIdvendorgameTitledatebusinessDayhourbankdenominationtheoHoldPercentactualHoldPercentvarianceHoldPercentgrossSalesprizenetWinaverageBetgamesPlayedVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }) || die "SQL Error.";

        
    # And fire off our insert.
        
    $sth->execute($gameID,$vendor,$gameTitle,$date,$day,$hour,$bank,$denom,$theoryHold,$holdPercent,$holdVariance,$grossSales,$prizes,$netWin,$avgBet,$gamesPlayed) || die "Unable to insert to DB.";
          
          
    #$database->do("INSERT INTO hourly VALUES (NULL,$gameID,$vendor,$gameTitle,$day,$hour,NULL,$bank,NULL,$denom,$theoryHold,$holdPercent,$holdVariance,$grossSales,$prizes,$netWin,$avgBet,$gamesPlayed,NULL,NULL,NULL)");
        
        # Moved to main() 
        #$database->commit;
    }

    # Load XML Configuration
    # ARGS: filename
    # RETURNS: NADA
    sub loadConfig {

        
    my $filename shift;
        
        
    # Initialize and load file
        
    my $xml = new XML::Simple;
        
    my $data $xml->XMLin("$filename");

        
    # Assign bet range high and low if present
        
    if($data->{config}->{bet_range}->{low} && $data->{config}->{bet_range}->{high})
        {
            
    $bet_avg_low $data->{config}->{bet_range}->{low};
            
    $bet_avg_high $data->{config}->{bet_range}->{high};
        }
        
        
    # Assign payout percentage variance if present
        
    if($data->{config}->{hold_variance}->{low} && $data->{config}->{hold_variance}->{high})
        {
            
    $hold_variation_low $data->{config}->{hold_variance}->{low};
            
    $hold_variation_high $data->{config}->{hold_variance}->{high};
        }
    }


    # Compute Hourly Play Coefficients
    # Sum values of array, and then compute ratio of each value to that total, assign results to array and return it
    # ARGS: Array(24) of INTS
    # RETURN: Array(24) of FLOATS
    sub computeHourlyCoeffs {

        
    my @in_array shift;
        
    my $total;
        
        (
    $total += $_) for @in_array;     

        
    my @result map { ($_/$total) } @in_array;

        return @
    result;
    }

    # Get Hourly Rates
    # ARGS: filename
    # RETURN: ARRAY of ARRAY of INTs
    sub getHourlyWeights {

        
    my $filename shift;
        
    my @hours;
        
        
    open HOURLY$filename;
        
        
        while(<
    HOURLY>)
        {
            
    chomp#remove return carriage if it is there
            
    my @tmp split /,/;
            
    push @hours, [ @tmp ];    
        }
        
        
    # Return our array of arrays
        
    return @hours;
    }

    # Get Prizes
    # ARGS: Gross Sales, Hold %
    # RETURN: FLOAT Prizes
    sub getPrizes {

        
    my $sales shift;
        
    my $hold shift;

        
    # Convert to ratio
        
    $hold/=100;
        
        return (
    $sales $hold);

    }


    # Get Net Win
    # ARGS: Gross Sales, Prizes
    # RETURN: FLOAT Net Win
    sub getNetWin {

        
    my $sales shift;
        
    my $prizes shift;
        
        return(
    $sales $prizes);

    }


    # Get Hold %
    # ARGS: Theo Hold %
    # RETURN: FLOAT Hold %
    sub getHoldPercentage {

        
    my $theo_hold shift;
        
        
    # Subtract the bottom range from our rand max
        
    my $rand_max $hold_variation_high $hold_variation_low;
        
        
    # get our rand
        
    my $rand rand($rand_max);

        
    # Put the bottom limit back in
        
    $rand += $hold_variation_low;
        
        
    # Now return the theoretical + the variance
        
    return (($theo_hold $rand));
    }

    # Round a percentage to two decimal places
    # ARGS: FLOAT %%.%^X
    # RETURN: FLOAT %%.%%
    sub roundPercentage {
        
        
    my $percent shift;

        if(
    $percent gt 0) { $percent+=0.005; }
        
    elsif($percent lt 0) { $percent -= 0.005; }
        
        
    # Regex Magic!
        
    $percent =~ s/(^[+-]?\d+\.?\d{0,2}).*/$1/;
        
        return 
    $percent;
    }

    #Debug
    #print "Get hold percent: " . roundPercentage(getHoldPercentage($theo_hold_percent)) . "\n";

    # Get the variance of the hold as a percentage
    # ARGS: Hold %
    # RETURN: FLOAT Variance %
    sub getHoldVariance {
        
        
    my $hold_percent shift;
        
    my $theo_hold_percent shift;

        
    #Debug
        #print "Hold Percentage: $hold_percent\n";
        
        
    return (($hold_percent $theo_hold_percent));
    }

    # Get Gross Sales
    # ARGS: Bet Avg, Games Played
    # RETURN: FLOAT Gross Sales
    sub getGrossSales {

        
    my $bet_avg shift;
        
    my $games_played shift;
        
        
    # Return the Bet Avg times Games Played
        
    return (($bet_avg $games_played));

    }

    #Debug
    #print "Denom: $denomination, Vendor Coeff: $vendor_coeff, Theoretical Hold %: $theo_hold_percent\n\n";

    # Get Games Played
    # ARG: FLOAT Vendor Coefficient, INT Play Level
    # RETURN: INT Games Played
    sub getGamesPlayed {

        
    my $vendor shift;
        
    my $play_level shift;
        
        
    my $total_play 0;
        
        
    # Base play is 120 * play level
        
    my $base_play $play_level 120;
        
        
    # A play level of 0 means 0 play, 1-10 means we should apply play level and add variance
        
    if($play_level 0)
        {
            
    # Generate a random between 0-200
            
    my $variance int(rand(200));
            
            
    # Decrement base play by 100
            
    $base_play -= 100;
            
            
    # Add variance to base play
            
    $total_play $base_play $variance;
        }
        
        return 
    $total_play;
    }

    #Debug
    #print "Games Played: " . getGamesPlayed($vendor_coeff) . "\n";

    # Get Average Bet
    # ARG: FLOAT Denomination
    # RETURN: FLOAT Average Bet
    sub getAverageBet {
        
        
    my $denom shift;
        
        
    # remove the bottom range
        
    my $rand_max $bet_avg_high $bet_avg_low;

        
    # Add one to make it hit the top value as well
        
    my $rand rand($rand_max);

        
    # add the bottom range we removed
        
    $rand += $bet_avg_low;
        
        
    # Return the denomination times our random range
        
    return ($denom $rand);

        
    #Debug
        #print "rand $rand\n";
        
    }

    #Debug
    #print "Average Bet: " . getAverageBet($denomination) . "\n";
     
    Last edited: Jul 26, 2006
  20. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    PHP:
    use XML::Simple;

        
    # If config.xml is present, load it
        
    if(-"config.xml" && -"config.xml")
        {
            
    loadConfig("config.xml");
        } 


    # Load XML Configuration
    # ARGS: filename
    # RETURNS: NADA
    sub loadConfig {

        
    my $filename shift;
        
        
    # Initialize and load file
        
    my $xml = new XML::Simple;
        
    my $data $xml->XMLin("$filename");

        
    # Assign bet range high and low if present
        
    if($data->{config}->{bet_range}->{low} && $data->{config}->{bet_range}->{high})
        {
            
    $bet_avg_low $data->{config}->{bet_range}->{low};
            
    $bet_avg_high $data->{config}->{bet_range}->{high};
        }
        
        
    # Assign payout percentage variance if present
        
    if($data->{config}->{hold_variance}->{low} && $data->{config}->{hold_variance}->{high})
        {
            
    $hold_variation_low $data->{config}->{hold_variance}->{low};
            
    $hold_variation_high $data->{config}->{hold_variance}->{high};
        }
    Why does perl kick ass? Cause thats ALL the code required to load an XML configuration file. Just damned simple.
     
  21. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Right, because the vast majority of web apps are SO much better. And faster. :rolleyes:

    I'm just stating my preference. I grew up writing code that was designed to compile and run fast, and now "the future" is supposedly this slow-loading, buggy patchwork of interpreted code languages that are mixed and matched like so many sentence fragments. What advantage does this have? One advantage: it takes less bandwidth to transmit, that's all.

    Applications are still easily editable, if you have access to the source code, and the programmers are forced to plan their shit out instead of just grabbing whichever language is more convenient to use on that particular day. I am so sick of having to decipher web code that's written in four or five different languages, and I can only imagine how much it slows down a computer to have to run that many language interpreters at once.

    When I write an application, I don't have to upload it to test it, I don't have to worry about broken hyperlinks, and I can't publish it until it works right. I see no reason why this paradigm shouldn't continue.
     
  22. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,922
    Likes Received:
    11
    Location:
    Los Angeles
    Completely defeats the purpose of robust web applications and rapid development. There are reasons why things are done the way they are on the www. If you can't see that, then you shouldn't be developing web applications. This thread should be locked now.
     

Share This Page