Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

PERL postgresql yaml poker and thank you

by ShermW0829 (Sexton)
on Feb 27, 2018 at 23:53 UTC ( #1210054=perlmeditation: print w/replies, xml ) Need Help??

Thank you to all who helped me get this started. Even though my name is on it that just means that I borrowed most of it from others. You will see your suggested way of doing things throughout this post.

I will describe how I created the postgresql database. Any and all comments are welcome.

I did not use these tables but I am strongly considering them.

CREATE TABLE seven_stud_spread_stakes(bring_in int, fourth_street int +check(fourth_street >= bring_in), fifth_street int check(fifth_street + >= bring_in), sixth_street int check(sixth_street >= bring_in), seve +nth_street int check(seventh_street >= bring_in)); CREATE TABLE colorado_limit_stakes(small_blind int, big_blind int chec +k(big_blind >= small_blind), preflop int check(preflop <= 100), flop +int check(flop <= 100), turn int check(turn <= 100), river int check( +river >= big_blind)); CREATE TABLE spread_limit_stakes(small_blind int, big_blind int check( +big_blind >= small_blind), preflop int check(preflop >= small_blind), + flop int check(flop >= small_blind), turn int check(turn >= small_bl +ind), river int check(river >= small_blind)); CREATE TABLE seven_stud_stakes(bring_in int, fourth_street int check(f +ourth_street >= bring_in), fifth_street int check(fifth_street >= fou +rth_street), sixth_street int check(sixth_street >= fifth_street), se +venth_street int check(seventh_street >= sixth_street)); CREATE TABLE stakes(small_blind int, big_blind int check(big_blind >= +small_blind), preflop int check(preflop >= big_blind), flop int check +(flop >= preflop), turn int check(turn >= flop), river int check(rive +r >= turn)); INSERT INTO stakes VALUES(1, 3, 3, 3, 6, 9);

I am using the following tables. Note that I am using v_limits since limit is a reserved word in postgresql.

CREATE TABLE v_limits(v_limit TEXT PRIMARY KEY); CREATE TABLE states(abbreviation TEXT PRIMARY KEY, state TEXT); CREATE TABLE cities(city TEXT PRIMARY KEY); CREATE TABLE games(game TEXT PRIMARY KEY); CREATE TABLE hi_lows(hi_lo TEXT PRIMARY KEY); CREATE TABLE kills(kill TEXT PRIMAY KEY); CREATE TABLE stakes(stake TEXT PRIMARY KEY); CREATE TABLE venues(venue TEXT PRIMAY KEY); CREATE TABLE visits(id INT PRIMARY KEY, arrival_date DATE, departure_d +ate DATE, arrival_time TIME, departure_time TIME, venue TEXT REFERENC +ES venues(venue), city TEXT REFERENCES cities(city), state TEXT REFER +ENCES states(abbreviation), game TEXT REFERENCES games(game), stake T +EXT REFERENCES stakes(stake), kill TEXT REFERENCES kills(kill), hi_lo + TEXT REFERENCES hi_lows(hi_lo), v_limit REFERENCES v_limits(v_limit) +, buy_in MONEY, cash_out MONEY);

This is the visit_configuration.yaml file I am using.

arrival_date: 20180214 departure_date: 20180215 arrival_time: 1000 departure_time: 1800 venue: "Binion's" city: "Las Vegas" state: "NV" game: "hold'em" stake: "4-8" kill: "no-kill" hi_lo: "hi" limit: "fixed" buy_in: 200 cash_out: 400

Next I will post the perl file I am using.

Replies are listed 'Best First'.
Re: PERL postgresql yaml poker and thank you
by ShermW0829 (Sexton) on Feb 27, 2018 at 23:58 UTC
    #!/usr/bin/perl use strict; use warnings; use v5.26; use DBI; ## postgresql access via dbi use YAML::Tiny; ## Used to call default answers use IO::Prompt; ## Used to prompt for the current information use POSIX; ###################################################################### ## postgresql database login configurations # ###################################################################### my $driver = "Pg"; my $database = "venue_visits"; my $dsn = "DBI:$driver:dbname = $database;host = 127.0.0.1;port = 5432 +"; my $username = "postgres"; my $password = "somepassword"; ##################################################################### ## get user's visit inputs # ##################################################################### my @visits_array = get_visit_information(); ##################################################################### ## Connect to postgresql database # ##################################################################### my %attr = (PrintError=>0,RaiseError=>1); my $dbh = DBI->connect($dsn,$username,$password,\%attr); ##################################################################### ## Prepare to insert data into the appropriate postgresql table # ##################################################################### my $sql = "INSERT INTO visits(id, arrival_date, departure_date, arriva +l_time, departure_time, venue, city, state, game, stake, kill, hi_lo, + v_limit, buy_in, cash_out) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; my $stmt = $dbh->prepare($sql); ##################################################################### ## execute the query # ##################################################################### foreach my $visit(@visits_array) { if ( $stmt->execute($visit->{id}, $visit->{arrival_date}, $visit-> +{departure_date}, $visit->{arrival_time}, $visit->{departure_time}, $ +visit->{venue}, $visit->{city}, $visit->{state}, $visit->{game}, $vis +it->{stake}, $visit->{kill}, $visit->{hi_lo}, $visit->{v_limit}, $vis +it->{buy_in}, $visit->{cash_out})) { print( "visit $visit->{id} inserted successfully \n" ); } } $stmt->finish(); ##################################################################### ## disconnect from the postgresql database # ##################################################################### $dbh->disconnect(); ##################################################################### # The below sub obtains the information required for the above # # actions # ##################################################################### sub get_visit_information { ################################################################## +#### ## Read the visit_configuration file to retrieve the default answe +rs # ################################################################## +#### my $visit_configuration = YAML::Tiny->read( 'visit_configuration.y +aml' ); ################################################################## +### # Create the id which will go into the venue_visits database + # # visits table + # ################################################################## +### my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti +me(time) or die "Unable to obtaing from localtime: $!"; my $id = "$year$yday$hour$min"; $id =~ s/^\s+|\s+$//g; my $cmd = ''; my @visit_sub_array; ## get visits from the command line my($arrival_date, $departure_date, $arrival_time, $departure_time, $venue, $city, $state, $game, $stake, $kill, $hi_lo, $v_limit, $buy_in, $cash_out); ## repeatedly ask for visit data from command line $arrival_date = prompt -d => "$visit_configuration->[0]->{arrival_ +date}", "Arrival Date: " or die "Unable to obtain arrival date: $!"; $arrival_date =~ s/^\s+|\s+$//g; $departure_date = prompt -d => "$visit_configuration->[0]->{depart +ure_date}", "Departure Date: " or die "Unable to obtaian departure da +te: $!"; $departure_date =~ s/^\s+|\s+$//g; $arrival_time = prompt -d => "$visit_configuration->[0]->{arrival_ +time}", "Arrival Time: " or die "Unable to obtain arrival time: $!"; $arrival_time =~ s/^\s+|\s+$//g; $departure_time = prompt -d => "$visit_configuration->[0]->{depart +ure_time}", "Departure Time: " or die "Unable to obtain departure tim +e: $!"; $departure_time =~ s/^\s+|\s+$//g; $venue = prompt -d => "$visit_configuration->[0]->{venue}", "Venue +: " or die "Unable to obtain venue: $!"; $venue =~ s/^\s+|\s+$//g; $city = prompt -d => "$visit_configuration->[0]->{city}", "City: " +, or die "Unable to obtain city: $!"; $city =~ s/^\s+|\s+$//g; $state = prompt -d => "$visit_configuration->[0]->{state}", "State +: ", or die "Unable to obtain state: $!"; $state =~ s/^\s+|\s+$//g; $game = prompt -d => "$visit_configuration->[0]->{game}", "Game: " +, or die "Unable to obtain game: $!"; $game =~ s/^\s+|\s+$//g; $stake = prompt -d => "$visit_configuration->[0]->{stake}", "Stake +: ", or die "Unable to obtain stake: $!"; $stake =~ s/^\s+|\s+$//g; $kill = prompt -d => "$visit_configuration->[0]->{kill}", "Kill: " +, or die "Unable to obtain kill: $!"; $kill =~ s/^\s+|\s+$//g; $hi_lo = prompt -d => "$visit_configuration->[0]->{hi_lo}", "Hi Lo +: " or die "Unable to obtain hi_lo: $!"; $hi_lo =~ s/^\s+|\s+$//g; $v_limit = prompt -d => "$visit_configuration->[0]->{limit}", "Lim +it: " or die "Unable to obtain limit: $!"; $v_limit =~ s/^\s+|\s+$//g; $buy_in = prompt -d => "$visit_configuration->[0]->{buy_in}", "Buy + In: " or die "Unable to obtain buy_in: $!"; $buy_in =~ s/^\s+|\s+$//g; $cash_out = prompt -d => "$visit_configuration->[0]->{cash_out}", +"Cash Out: " or die "Unable to obtain cash_out: $!"; $cash_out =~ s/^\s+|\s+$//g; my %visit_sub_hash = (id=>$id, arrival_date=>$arrival_date, depart +ure_date=>$departure_date, arrival_time=>$arrival_time, departure_time=>$de +parture_time, venue=>$venue, city=>$city, state=>$state, game=>$ga +me, stake=>$stake, kill=>$kill, hi_lo=>$hi_lo, v_limit=>$v_l +imit, buy_in=>$buy_in, cash_out=>$cash_out ); push(@visit_sub_array,\%visit_sub_hash); return @visit_sub_array; } 1; __END__ =head1 NAME build_sql_entries =cut =head1 SYNOPSIS The build_sql_entries file allows a user to enter poker statistics in +to a postgresql database. The user is prompeted for the correct infor +mation. The configuration file is visit_configuration.yaml. =cut =head1 DESCRIPTION The information is formatted as necessary. More description tbd. =cut =head1 AUTHOR Sherman L. Willden =cut =head1 BUGS TDB =cut =head1 SEE ALSO Any PERL book and regular expression book =cut =head1 COPYRIGHT build_sql_entries: Copyright (C) 2018, Sherman Willden. The file is l +icensed under the terms of the GNU Lesser General Public License 2.1. + See <http://www.gnu.org/licenses/lgpl-2.1.html>. This program is free software; you can redistribute it and/or modify i +t under the terms of the Artistic License 2.0. You can redistribute i +t and/or modify it under the same terms as Perl 5.26.0 This program is distributed in the hope that it will be useful, but it + is provided “as is” and without any express or implied warranties. =cut
Re: PERL postgresql yaml poker and thank you
by ait (Friar) on Feb 28, 2018 at 14:18 UTC

    You may want to write a tutorial or cool uses for perl sections?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1210054]
Approved by Arunbear
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2018-06-19 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (114 votes). Check out past polls.

    Notices?