Acme-FishFarm

 view release on metacpan or  search on metacpan

docs/Acme-FishFarm-1.01.html  view on Meta::CPAN


<pre><code>    use 5.010;

    use Acme::FishFarm &quot;:all&quot;;

    my $water_monitor = Acme::FishFarm::WaterConditionMonitor-&gt;install;
    my $oxygen = Acme::FishFarm::OxygenMaintainer-&gt;install( DO_generation_volume =&gt; 1.92 );

    $water_monitor-&gt;add_oxygen_maintainer( $oxygen );

    say &quot;Water condition monitor installed...&quot;;
    say &quot;Oxygen maintainer installed and connected to water condition monitor...&quot;;
    say &quot;Water condition monitor switched on!&quot;;
    say &quot;&quot;;

    while ( &quot;fish are swimming happily&quot; ) {
        ### DO
        check_DO( $oxygen, reduce_precision( rand(8) ) );
        say &quot;&quot;;
        
        ### pH
        check_pH( $water_monitor, 6.912 );
        #check_pH( $water_monitor, 5.9 );
        say &quot;&quot; ;
        
        ## temperature
        #check_temperature( $water_monitor, 23 );
        check_temperature( $water_monitor, 26 );
        say &quot;&quot;;
        
        ## turbidity
        check_turbidity( $water_monitor, 120 );
        #check_turbidity( $water_monitor, 190 );
        say &quot;&quot;;
        
        # all LEDs
        render_leds( $water_monitor );
        say &quot;&quot;;
        
        # buzzers
        render_buzzer( $water_monitor );
        
        sleep(3);
        say &quot;-----------------------------&quot;;
    }
    </code></pre>

<h1 id="EXPORT">EXPORT</h1>

<p>The <code>:all</code> tag can be used to import all the subroutines available in this module.</p>

<h1 id="NOTES">NOTES</h1>

<p>Almost all the subroutines in this module will give output. The unit measurements used will be according to the ones mentioned in <code>Acme::FishFarm::WaterConditionMonitor</code>.</p>

docs/Acme-FishFarm-Feeder-1.01.html  view on Meta::CPAN


<p>Version 1.01</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>    use 5.010;
    use Acme::FishFarm::Feeder;

    my $feeder = Acme::FishFarm::Feeder-&gt;install( timer =&gt; 3, feeding_volume =&gt; 150 );

    say &quot;Feeder installed and switched on!&quot;;
    say &quot;&quot;;

    while ( &quot;fish are living happilly&quot; ) {

        if ( $feeder-&gt;timer_is_up ) {
            say &quot;\nTimer is up, time to feed the fish!&quot;;
            say &quot;Feeding &quot;, $feeder-&gt;feeding_volume, &quot; cm^3 of fish food to the fish...&quot;;
            
            $feeder-&gt;feed_fish;
            
            say $feeder-&gt;food_remaining, &quot; cm^3 of fish food remaining in the tank.\n&quot;;
        }
        
        if ( $feeder-&gt;food_remaining &lt;= 0  ) {
            $feeder-&gt;refill; # default back to 500 cm^3
            say &quot;Refilled food tank back to &quot;, $feeder-&gt;food_tank_capacity, &quot; cm^3.\n&quot;;
        }
        
        say $feeder-&gt;time_remaining, &quot; hours left until it&#39;s time to feed the fish.&quot;;

        sleep(1);
        $feeder-&gt;tick_clock;
    }

    say &quot;&quot;;
    say &quot;Feeder was switched off, please remeber to feed your fish on time :)&quot;;</code></pre>

<h1 id="EXPORT">EXPORT</h1>

<p>None</p>

<h1 id="CREATION-RELATED-METHODS">CREATION RELATED METHODS</h1>

<h2 id="install-options">install ( %options )</h2>

<p>Installs an automated fish feeder.</p>

docs/Acme-FishFarm-OxygenMaintainer-1.01.html  view on Meta::CPAN

<p>Version 1.01</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>    use 5.010;

    use Acme::FishFarm qw(consume_oxygen reduce_precision);
    use Acme::FishFarm::OxygenMaintainer;

    my $oxygen = Acme::FishFarm::OxygenMaintainer-&gt;install( DO_generation_volume =&gt; 3 );
    say &quot;Oxygen maintainer installed!\n&quot;;


    while ( &quot;fish are using up oxygen&quot; ) {
        say &quot;Current Oxygen Level: &quot;, $oxygen-&gt;current_DO, &quot; mg/L&quot;,
            &quot; (low: &lt; &quot;, $oxygen-&gt;DO_threshold, &quot;)&quot;;
        #say &quot;Low Oxygen Level: &quot;, $oxygen-&gt;DO_threshold, &quot; mg/L&quot;;

        if ( $oxygen-&gt;is_low_DO ) {
            say &quot;Fish status: Suffocating&quot;;
            say &quot;  !! Low oxygen level!&quot;;
            say &quot;Pumping &quot;, $oxygen-&gt;oxygen_generation_volume, &quot; mg/L of oxygen into the water...&quot; ;
            $oxygen-&gt;generate_oxygen;
        } else {
            say &quot;Fish status: Happy&quot;;
        }
        
        consume_oxygen( $oxygen, rand(2.5) );
        
        sleep(3);
        say &quot;&quot;;
    }</code></pre>

<h1 id="EXPORT">EXPORT</h1>

<p>None</p>

<h1 id="CREATION-RELATED-SUBROUTINES-METHODS">CREATION RELATED SUBROUTINES/METHODS</h1>

<h2 id="install-options">install ( %options )</h2>

docs/Acme-FishFarm-WaterFiltration-1.01.html  view on Meta::CPAN


<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>    use 5.010;

    use Acme::FishFarm qw( reduce_precision );
    use Acme::FishFarm::WaterFiltration;

    my $water_filter = Acme::FishFarm::WaterFiltration-&gt;install;

    say &quot;Water filter installed and switched on!\n&quot;;


    my $current_reading;
    my $waste_count_threshold;
    
    while ( &quot;Fish are living under the water...&quot; ) {
        $water_filter-&gt;current_waste_count( reduce_precision ( rand(100) ) );
        
        $current_reading = $water_filter-&gt;current_waste_count;
        $waste_threshold = $water_filter-&gt;waste_count_threshold;

docs/Acme-FishFarm-WaterFiltration-1.01.html  view on Meta::CPAN

        print &quot;Current Waste Count: &quot;, $current_reading, &quot; (high: &gt;= &quot;, $waste_threshold, &quot;)\n&quot;;

        if ( $water_filter-&gt;is_cylinder_dirty ) {
            print &quot;  !! Filtering cylinder is dirty!\n&quot;;
            print &quot;  Cleaned the filter!\n&quot;;
            $water_filter-&gt;clean_cylinder;
        } else {
            print &quot;  Filtering cylinder is still clean.\n&quot;;
        }
        sleep(1);
        say &quot;&quot;;
    }</code></pre>

<h1 id="EXPORT">EXPORT</h1>

<p>None</p>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This module assumes a cool water filter with a filtering cylinder constantly filtering water in the tank. It has inlet, outlet and a drainage valves. The drainage valve is only opened when the cleaners are switched on automatically to remove waste...

docs/Acme-FishFarm-WaterLevelMaintainer-1.01.html  view on Meta::CPAN


<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>    use 5.010;

    use Acme::FishFarm qw( reduce_precision );
    use Acme::FishFarm::WaterFiltration;

    my $water_level = Acme::FishFarm::WaterLevelMaintainer-&gt;install;

    say &quot;Water level maintainer installed and switched on!\n&quot;;

    my $height_increase;
    my $water_level_threshold;
    my $current_reading;

    while ( &quot;Fish are living under the water...&quot; ) {

        $current_reading = reduce_precision( rand(10) );
        $height_increase = $water_level-&gt;water_level_increase_height;
        $water_level_threshold = $water_level-&gt;low_water_level_threshold;

docs/Acme-FishFarm-WaterLevelMaintainer-1.01.html  view on Meta::CPAN

        if ( $water_level-&gt;is_low_water_level ) {
            print &quot;  !! Water level is low!\n&quot;;
            $water_level-&gt;pump_water_in;
            print &quot;  Pumping in &quot;, $height_increase, &quot; m of water...\n&quot;;
            print &quot;Current Water Level: &quot;, $water_level-&gt;current_water_level, &quot;\n&quot;;
        } else {
            print &quot;  Water level is still normal.\n&quot;;
        }
        
        sleep(1);
        say &quot;&quot;;
    }</code></pre>

<h1 id="EXPORT">EXPORT</h1>

<p>None</p>

<h1 id="CREATION-RELATED-MEHODS">CREATION RELATED MEHODS</h1>

<h2 id="install-options">install ( %options )</h2>

lib/Acme/FishFarm.pm  view on Meta::CPAN


    use 5.010;

    use Acme::FishFarm ":all";

    my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install;
    my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 1.92 );

    $water_monitor->add_oxygen_maintainer( $oxygen );

    say "Water condition monitor installed...";
    say "Oxygen maintainer installed and connected to water condition monitor...";
    say "Water condition monitor switched on!";
    say "";

    while ( "fish are swimming happily" ) {
        ### DO
        check_DO( $oxygen, reduce_precision( rand(8) ) );
        say "";
        
        ### pH
        check_pH( $water_monitor, 6.912 );
        #check_pH( $water_monitor, 5.9 );
        say "" ;
        
        ## temperature
        #check_temperature( $water_monitor, 23 );
        check_temperature( $water_monitor, 26 );
        say "";
        
        ## turbidity
        check_turbidity( $water_monitor, 120 );
        #check_turbidity( $water_monitor, 190 );
        say "";
        
        # all LEDs
        render_leds( $water_monitor );
        say "";
        
        # buzzers
        render_buzzer( $water_monitor );
        
        sleep(3);
        say "-----------------------------";
    }
    
=head1 EXPORT

The C<:all> tag can be used to import all the subroutines available in this module.

=cut

use Exporter qw( import );
our @EXPORT_OK = qw( 

lib/Acme/FishFarm/Feeder.pm  view on Meta::CPAN

our $VERSION = '1.01';


=head1 SYNOPSIS

    use 5.010;
    use Acme::FishFarm::Feeder;

    my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );

    say "Feeder installed and switched on!";
    say "";

    while ( "fish are living happilly" ) {

        if ( $feeder->timer_is_up ) {
            say "\nTimer is up, time to feed the fish!";
            say "Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...";
            
            $feeder->feed_fish;
            
            say $feeder->food_remaining, " cm^3 of fish food remaining in the tank.\n";
        }
        
        if ( $feeder->food_remaining <= 0  ) {
            $feeder->refill; # default back to 500 cm^3
            say "Refilled food tank back to ", $feeder->food_tank_capacity, " cm^3.\n";
        }
        
        say $feeder->time_remaining, " hours left until it's time to feed the fish.";

        sleep(1);
        $feeder->tick_clock;
    }

    say "";
    say "Feeder was switched off, please remeber to feed your fish on time :)";

=head1 EXPORT

None

=head1 CREATION RELATED METHODS

=head2 install ( %options )

Installs an automated fish feeder.

lib/Acme/FishFarm/Feeder.pm  view on Meta::CPAN

    }
    
    if ( not $options{food_tank_capacity} ) {
        $options{food_tank_capacity} = 500;
    }
    
    if ( not $options{current_food_amount} ) {
        $options{current_food_amount} = $options{food_tank_capacity};
    }
    
    $options{first_usage} = 1; # make sure the feeder doesn't say timer is up as soon as it is switched on
    
    bless \%options, $class;
}



=head1 TIMER RELATED SUBROUTINES/METHODS

=head2 get_timer

lib/Acme/FishFarm/OxygenMaintainer.pm  view on Meta::CPAN



=head1 SYNOPSIS

    use 5.010;

    use Acme::FishFarm qw(consume_oxygen reduce_precision);
    use Acme::FishFarm::OxygenMaintainer;

    my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 3 );
    say "Oxygen maintainer installed!\n";


    while ( "fish are using up oxygen" ) {
        say "Current Oxygen Level: ", $oxygen->current_DO, " mg/L",
            " (low: < ", $oxygen->DO_threshold, ")";
        #say "Low Oxygen Level: ", $oxygen->DO_threshold, " mg/L";

        if ( $oxygen->is_low_DO ) {
            say "Fish status: Suffocating";
            say "  !! Low oxygen level!";
            say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ;
            $oxygen->generate_oxygen;
        } else {
            say "Fish status: Happy";
        }
        
        consume_oxygen( $oxygen, rand(2.5) );
        
        sleep(3);
        say "";
    }

=head1 EXPORT

None

=head1 CREATION RELATED SUBROUTINES/METHODS

=head2 install ( %options )

lib/Acme/FishFarm/WaterFiltration.pm  view on Meta::CPAN


=head1 SYNOPSIS

    use 5.010;

    use Acme::FishFarm qw( reduce_precision );
    use Acme::FishFarm::WaterFiltration;

    my $water_filter = Acme::FishFarm::WaterFiltration->install;

    say "Water filter installed and switched on!\n";


    my $current_reading;
    my $waste_count_threshold;
    
    while ( "Fish are living under the water..." ) {
        $water_filter->current_waste_count( reduce_precision ( rand(100) ) );
        
        $current_reading = $water_filter->current_waste_count;
        $waste_threshold = $water_filter->waste_count_threshold;

lib/Acme/FishFarm/WaterFiltration.pm  view on Meta::CPAN

        print "Current Waste Count: ", $current_reading, " (high: >= ", $waste_threshold, ")\n";

        if ( $water_filter->is_cylinder_dirty ) {
            print "  !! Filtering cylinder is dirty!\n";
            print "  Cleaned the filter!\n";
            $water_filter->clean_cylinder;
        } else {
            print "  Filtering cylinder is still clean.\n";
        }
        sleep(1);
        say "";
    }

=head1 EXPORT

None

=head1 DESCRIPTION

This module assumes a cool water filter with a filtering cylinder constantly filtering water in 
the tank. It has inlet, outlet and a drainage valves. The drainage valve is only opened when the

lib/Acme/FishFarm/WaterLevelMaintainer.pm  view on Meta::CPAN


=head1 SYNOPSIS

    use 5.010;

    use Acme::FishFarm qw( reduce_precision );
    use Acme::FishFarm::WaterFiltration;

    my $water_level = Acme::FishFarm::WaterLevelMaintainer->install;

    say "Water level maintainer installed and switched on!\n";

    my $height_increase;
    my $water_level_threshold;
    my $current_reading;

    while ( "Fish are living under the water..." ) {

        $current_reading = reduce_precision( rand(10) );
        $height_increase = $water_level->water_level_increase_height;
        $water_level_threshold = $water_level->low_water_level_threshold;

lib/Acme/FishFarm/WaterLevelMaintainer.pm  view on Meta::CPAN

        if ( $water_level->is_low_water_level ) {
            print "  !! Water level is low!\n";
            $water_level->pump_water_in;
            print "  Pumping in ", $height_increase, " m of water...\n";
            print "Current Water Level: ", $water_level->current_water_level, "\n";
        } else {
            print "  Water level is still normal.\n";
        }
        
        sleep(1);
        say "";
    }

=head1 EXPORT

None

=head1 CREATION RELATED MEHODS

=head2 install ( %options )

scripts/feeder.pl  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Acme::FishFarm::Feeder;

my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );

say "Feeder installed and switched on!";
say "";

#while (1) {
for (0..20){

    if ( $feeder->timer_is_up ) {
        say "\nTimer is up, time to feed the fish!";
        say "Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...";
        
        $feeder->feed_fish ( verbose => 1 );
        
        say $feeder->food_remaining, " cm^3 of fish food remaining in the tank.\n";
    }
    
    if ( $feeder->food_remaining <=0  ) {
        $feeder->refill; # default back to 500 cm^3
        say "Refilled food tank back to ", $feeder->food_tank_capacity, " cm^3.\n";
    }
    
    say $feeder->time_remaining, " hours left until it's time to feed the fish.";

    sleep(1);
    $feeder->tick_clock;
}

say "";
say "Feeder was switched off, please remeber to feed your fish on time :)";

# besiyata d'shmaya

scripts/feeder_2.pl  view on Meta::CPAN

use 5.010;

use Acme::FishFarm ":all";
use Acme::FishFarm::Feeder;

my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );

while ( "fish are living in the water..." ) {
    check_feeder( $feeder, verbose => 1 );
    sleep 2;
    say "";
}

# besiyata d'shmaya

scripts/fish_farm.pl  view on Meta::CPAN

use warnings;
use 5.010;

use Acme::FishFarm ":all";

my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 1.92 );

$water_monitor->add_oxygen_maintainer( $oxygen );

say "Water condition monitor installed...";
say "Oxygen maintainer installed and connected to water condition monitor...";
say "Water condition monitor switched on!";
say "";

# my $first_round = 1; # not applicable for manual input
while ( "fish are swimming happily" ) {
    ### DO
    check_DO( $oxygen, reduce_precision( rand(8) ) );
    say "";
    
    ### pH
    check_pH( $water_monitor, 6.912 );
    #check_pH( $water_monitor, 5.9 );
    say "" ;
    
    ## temperature
    #check_temperature( $water_monitor, 23 );
    check_temperature( $water_monitor, 26 );
    say "";
    
    ## turbidity
    check_turbidity( $water_monitor, 120 );
    #check_turbidity( $water_monitor, 190 );
    say "";
    
    # all LEDs
    render_leds( $water_monitor );
    #if ( $water_monitor->is_on_LED_DO ) {
    #    say "  Low oxygen LED: up";
    #}
    say "";
    
    # buzzers
    render_buzzer( $water_monitor );
    
    sleep(3);
    say "-----------------------------";
}

# besiyata d'shmaya


scripts/fish_farm_2.pl  view on Meta::CPAN

my ( $feeder, $oxygen, $water_monitor, $water_level, $water_filter ) = install_all_systems;
show_installation_status();
sleep 1;
show_all_threshold();

$water_level->set_water_level_increase_height(5);

my $feeder_verbose = 1;

print colored(['bold bright_blue'], "Prese <ENTER> to start monitoring your fish farm"); <>;
say "";

while ( "fish are swimming happily" ) {

    # get input for DO, pH, temperature, turbidity, in one go
    print colored(['bold bright_blue'], "Enter current DO level (mg/L): ");
    chomp ( my $current_DO = <>);
    
    print colored(['bold bright_blue'], "Enter current pH value: ");
    chomp ( my $current_pH = <>);
    
    print colored(['bold bright_blue'], "Enter current temperature (C): ");
    chomp ( my $current_temperature = <>);
    
    print colored(['bold bright_blue'], "Enter current turbidity (ntu): ");
    chomp ( my $current_turbidity = <>);

    say colored(['bright_yellow'], "--------------------------------");
    say colored(['bold bright_yellow'], "Water Condition Monitor Report");
    say colored(['bright_yellow'], "--------------------------------");
    
    check_DO( $oxygen, $current_DO ); say "";
    check_pH( $water_monitor, $current_pH ); say "" ;
    check_temperature( $water_monitor, $current_temperature ); say "";
    check_turbidity( $water_monitor, $current_turbidity );
    say colored(['bright_yellow'], "--------------------------------"); say "";
    
    print colored(['bold bright_blue'], "Press <ENTER> to check the LED status"); <>; say "";
    say colored(['bright_yellow'], "------------------------------------");
    say colored(['bold bright_yellow'], "Water Condition Monitor LEDs Status");
    say colored(['bright_yellow'], "------------------------------------");
    render_leds( $water_monitor );
    say colored(['bright_yellow'], "--------------------------------"); say "";
    
    print colored(['bold bright_blue'], "Press <ENTER> to check the buzzer status"); <>; say "";
    say colored(['bright_yellow'], "--------------------------------------");
    say colored(['bold bright_yellow'], "Water Condition Monitor Buzzer Status");
    say colored(['bright_yellow'], "--------------------------------------");
    render_buzzer( $water_monitor );
    say colored(['bright_yellow'], "--------------------------------------"); say "";
    
    print colored(['bold bright_blue'], "Press <ENTER> to check the feeder"); <>; say "";
    say colored(['bright_yellow'], "--------------------------------");
    say colored(['bold bright_yellow'], "Automated Feeder Report");
    say colored(['bright_yellow'], "--------------------------------");
    check_feeder( $feeder, $feeder_verbose );
    say colored(['bright_yellow'], "--------------------------------"); say "";
    
    print colored(['bold bright_blue'], "Enter current waste count (integer): ");
    chomp ( my $current_waste_count = <>);
    say colored(['bright_yellow'], "--------------------------------");
    say colored(['bold bright_yellow'], "Water Filtration Report");
    say colored(['bright_yellow'], "--------------------------------");
    check_water_filter( $water_filter, $current_waste_count );
    say colored(['bright_yellow'], "--------------------------------"); say "";

    print colored(['bold bright_blue'], "Enter current water level (m): ");
    chomp ( my $current_water_level = <>);    
    say colored(['bright_yellow'], "----------------------------------");
    say colored(['bold bright_yellow'], "Water Level Maintainer Report");
    say colored(['bright_yellow'], "-----------------------------------");
    check_water_level( $water_level, $current_water_level );
    say colored(['bright_yellow'], "-----------------------------------"); say "";
    
    say colored(['bold bright_yellow'], "-------------END OF REPORT-----------\n");
    print colored(['bold bright_blue'], "Press <ENTER> to monitor your fish farm again"); <>;
    say "";
}

sub show_installation_status {
    say colored(['bright_yellow'], "Setting up your fish farm..."); sleep(1);
    say colored(['bright_green'], "  Feeder installed and switched on!"); sleep(1);
    say colored(['bright_green'], "  Water level maintiner installed and switched on!"); sleep(1);
    say colored(['bright_green'], "  Water filter installed and switched on!"); sleep(1);
    say colored(['bright_yellow'], "  Setting up water condition monitor..."); sleep(1);
    say colored(['bright_green'], "    Water condition monitor installed!"); sleep(1);
    say colored(['bright_yellow'], "      Oxygen maintainer installed & connected to water condition monitor..."); sleep(1);
    say colored(['bright_green'], "    Water condition monitor switched on!"); sleep(1);
    say colored(['bold bright_blue'], "Your fish farm is ready!");
    say "";
}

sub show_all_threshold {
    my $ph_range = $water_monitor->ph_threshold;
    my $temperature_range = $water_monitor->temperature_threshold;
    
    say colored(['bold bright_magenta'], "Acceptable threshold/range of parameters:");
    say "  Min. DO level: ", $oxygen->DO_threshold, " mg/L";
    say "  pH: ", $ph_range->[0], "~", $ph_range->[1];
    say "  Temperature: ", $temperature_range->[0], "~", $temperature_range->[1], " C";
    say "  Max. Turbidity: ", $water_monitor->turbidity_threshold, " ntu";
    say "  Max. Waste Count: ", $water_filter->waste_count_threshold;
    say "  Min. Water level: ", $water_level->low_water_level_threshold, " m";
    say "";
}

# besiyata d'shmaya


scripts/oxygen_maintainer.pl  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Acme::FishFarm::OxygenMaintainer;

my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 3 );
say "Oxygen maintainer installed!\n";


while ( "fish are using up oxygen" ) {
    say "Current Oxygen Level: ", $oxygen->current_DO, " mg/L",
        " (low: < ", $oxygen->DO_threshold, ")";
    #say "Low Oxygen Level: ", $oxygen->DO_threshold, " mg/L";

    if ( $oxygen->is_low_DO ) {
        say "Fish status: Suffocating";
        say "  !! Low oxygen level!";
        say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ;
        $oxygen->generate_oxygen;
    } else {
        say "Fish status: Happy";
    }
    
    #consume_oxygen( $oxygen, 3 ); # die
    consume_oxygen( $oxygen, rand(2.5) );
    
    sleep(3);
    say "";
}


# must pass in a decimal
sub consume_oxygen {
    my $o2_maintainer = shift;
    my $consumed_oxygen = reduce_precision ( shift );
    #$consumed_oxygen =~ /(\d+\.\d{3})/;
    say "$consumed_oxygen mg/L of oxygen consumed...";
    my $o2_remaining = $o2_maintainer->current_DO - $consumed_oxygen;
    $o2_maintainer->current_DO( $o2_remaining );
}

sub reduce_precision {
    my $sensor_reading = shift;
    die "Please pass in a decimal value" if not $sensor_reading =~ /\./;
    $sensor_reading =~ /(\d+\.\d{3})/;
    $1;
}

scripts/water_filter.pl  view on Meta::CPAN


use strict;
use warnings;
use 5.010;

use Acme::FishFarm qw( check_water_filter reduce_precision );
use Acme::FishFarm::WaterFiltration;

my $water_filter = Acme::FishFarm::WaterFiltration->install;

say "Water filter installed and switched on!\n";

while ( "Fish are living under the water..." ) {
    check_water_filter( $water_filter, int (rand(150)), reduce_precision( rand(10) ) );
    sleep(1);
    say "";
}

=head1 use Acme::FishFarm's check_water_filter
sub check_water_filter {
    my ( $water_filter, $current_reading ) = @_;
    my $waste_threshold = $water_filter->waste_count_threshold;
    
    $water_filter->current_waste_count( $current_reading );
    
    print "Current Waste Count: ", $current_reading, " (high: >= ", $waste_threshold, ")\n";

scripts/water_level.pl  view on Meta::CPAN


use strict;
use warnings;
use 5.010;

use Acme::FishFarm ":all";
use Acme::FishFarm::WaterLevelMaintainer;

my $water_level = Acme::FishFarm::WaterLevelMaintainer->install;

say "Water level maintainer installed and switched on!\n";

while ( "Fish are living under the water..." ) {
    check_water_level( $water_level, reduce_precision(rand(8)) );
    sleep(1);
    say "";
}

=head1 use Acme::FishFarm's check_water_level
sub check_water_level {
    my $water_level = shift;
    my $current_reading = shift;
    my $height_increase = $water_level->water_level_increase_height; # for output
    my $water_level_threshold = $water_level->low_water_level_threshold;
    
    $water_level->current_water_level( $current_reading ); # input by user

scripts/water_monitor.pl  view on Meta::CPAN

use 5.010;

use Acme::FishFarm::WaterConditionMonitor;
use Acme::FishFarm::OxygenMaintainer;

my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 1.92 );

$water_monitor->add_oxygen_maintainer( $oxygen );

say "Water condition monitor installed...";
say "Oxygen maintainer installed and connected to water condition monitor...";
say "Water condition monitor switched on!";
say "";

# my $first_round = 1; # not applicable for manual input
while ( "fish are swimming happily" ) {
    ### DO
    check_DO( $oxygen, reduce_precision( rand(8) ) );
    # not applicable for manual input
    #if ( $first_round ) {
    #    $first_round = 0;
    #} else {
    #    consume_oxygen( $oxygen, 1.25 );
    #}

    say "";
    
    ### pH
    check_pH( $water_monitor, 6.912 );
    #check_pH( $water_monitor, 5.9 );
    say "" ;
    
    ## temperature
    #check_temperature( $water_monitor, 23 );
    check_temperature( $water_monitor, 26 );
    say "";
    
    ## turbidity
    check_turbidity( $water_monitor, 120 );
    #check_turbidity( $water_monitor, 190 );
    say "";
    
    # all LEDs
    render_leds( $water_monitor );
    #if ( $water_monitor->is_on_LED_DO ) {
    #    say "  Low oxygen LED: up";
    #}
    say "";
    
    # buzzers
    render_buzzer( $water_monitor );
    
    sleep(3);
    say "-----------------------------";
}

# taken directly from oxygen_maintainer.pl

# these 2 subroutines are to be called manually, the check_* only checks the current condition
# must pass in a decimal
sub consume_oxygen {
    my $o2_maintainer = shift;
    my $consumed_oxygen = shift;
    say "$consumed_oxygen mg/L of oxygen consumed...";
    my $o2_remaining = $o2_maintainer->current_DO - $consumed_oxygen;
    $o2_maintainer->current_DO( $o2_remaining );
}

sub reduce_precision {
    my $sensor_reading = shift;
    die "Please pass in a decimal value" if not $sensor_reading =~ /\./;
    $sensor_reading =~ /(\d+\.\d{3})/;
    $1;
}

sub check_DO {
    my ( $oxygen, $current_reading ) = @_;
    my $DO_threshold = $oxygen->DO_threshold;

    $oxygen->current_DO( $current_reading );
    $oxygen->is_low_DO;
    
    say "Current Oxygen Level: ", $current_reading, " mg/L",
        " (low: < ", $DO_threshold, ")";

    if ( $oxygen->is_low_DO ) {
        say "  !! Low oxygen level!";
        # commented ones are not applicable for manual input
            #say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ;
            #$oxygen->generate_oxygen;
    } else {
        say "  Oxygen level is normal.";
    }
}

sub check_pH {
    my ( $water_monitor, $current_reading ) = @_;
    my $ph_range = $water_monitor->ph_threshold;
    
    $water_monitor->current_ph( $current_reading );
    $water_monitor->ph_is_normal;
    
    say "Current pH: ", $water_monitor->current_ph, 
        " (normal range: ", $ph_range->[0], "~", $ph_range->[1], ")";

    if ( !$water_monitor->ph_is_normal ) {
        say "  !! Abnormal pH!";
    } else {
        say "  pH is normal."
    }
    
}

sub check_temperature {
    my ( $water_monitor, $current_reading ) = @_;
    my $temperature_range = $water_monitor->temperature_threshold;

    $water_monitor->current_temperature( $current_reading );
    $water_monitor->temperature_is_normal;
    
    say "Current temperature: ", $water_monitor->current_temperature, " C", 
        " (normal range: ", $temperature_range->[0], " C ~ ", $temperature_range->[1], " C)";

    if ( !$water_monitor->temperature_is_normal ) {
        say "  !! Abnormal temperature!";
    } else {
        say "  Temperature is normal."
    }
}

sub check_turbidity {
    my ( $water_monitor, $current_reading ) = @_;
    my $turbidity_threshold = $water_monitor->turbidity_threshold;

    $water_monitor->current_turbidity( $current_reading );
    
    say "Current Turbidity: ", $water_monitor->current_turbidity, " ntu",
        " (dirty: > ", $turbidity_threshold, ")";

    if ( $water_monitor->water_dirty ) {
        say "  !! Water is dirty!";
    } else {
        say "  Water is still clean.";
    } 
}

sub render_leds {
    my $water_monitor = shift;

    # must check condition first! If not it won't work
    $water_monitor->ph_is_normal;
    $water_monitor->temperature_is_normal;
    $water_monitor->lacking_oxygen;    
    $water_monitor->water_dirty;
        
    say "Total LEDs up: ", $water_monitor->lighted_LED_count;

    if ( $water_monitor->is_on_LED_pH ) {
        say "  pH LED: on";
    } else {
        say "  pH LED: off";
    }
    
    if ( $water_monitor->is_on_LED_temperature ) {
        say "  Temperature LED: on";
    } else {
        say "  Temperature LED: off";
    }
    
    if ( $water_monitor->is_on_LED_DO ) {
        say "  Low DO LED: on";
    } else {
        say "  Low DO LED: off";
    }
    
    if ( $water_monitor->is_on_LED_turbidity ) {
        say "  Turbidity LED: on";
    } else {
        say "  Turbidity LED: off";
    }
}

sub render_buzzer {
    my $water_monitor = shift;
    
    #$water_monitor->_tweak_buzzers;
    if ( $water_monitor->is_on_buzzer_long ) {
        say "Long buzzer is on, water condition very critical!";
    } elsif ( $water_monitor->is_on_buzzer_short ) {
        say "Short buzzer is on, water condition is a bit worrying :|";
    } else {
        say "No buzzers on, what a peaceful moment."
    }
}

# besiyata d'shmaya




( run in 1.406 second using v1.01-cache-2.11-cpan-b85c58fdc1d )