The scoop on Windows running Perl

Scoop is a command-line installer for Windows that allows you to install a local user copy of Perl and other open source programming languages.

To get started, just install scoop on your windows machine by typing this in a powershell terminal:


irm get.scoop.sh | iex

If this doesn't work you might have to set a Powershell execution policy by typing this in your Powershell terminal :

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Check the ="https://github.com/ScoopInstaller/Insta…

Hacktoberfest 2022 is near!

Hello Fellow Perl mongers!

Every year in the month of October a company named DigitalOcean hosts an event named Hacktoberfest.

If you ever wanted to contribute to a Perl project now is a good time to give it a go!. Here are a few beginner friendly projects that are up-for-grabs and here is a list of Github projects with the "hacktoberfest' topic.

If …

EV charge calculator from script to Dancer web

Since my last post I wanted to take my EV charge calculator script and convert it into a web form. In this post I breakdown how I migrated the script to a Dancer2 web app.

Just a minor note for those readers who may not be aware, Dancer2 is a "lightweight web-framework for Perl" as described in Dancer2 documentation and can be similar in comparison to Ruby Sinatra and ="https://flask.palletspr…

EV charge pricing per State in US

Continuing from my previous post ( https://blogs.perl.org/users/itcharlie/2021/04/calculating-ev-battery-charge-with-perl.html ) I learned that residential electricity charges are calculated using an electricity supply rate per kWh and a electric delivery rate per kWh which actually increases the total EV charge prices that I have calculated in my previous post. My current bill states that my electric supply rate is at 6.9057 cents per kWh and my delivery rate is 11.1785 cents per kWh making it a total of 18.0842 cents per kWh which is 5 cents more than my original post at $ 0.13 cents per kWh.

I was curious to calculate the average cost per state in US so I did some research online and found a site that would give me average electric charges per State in US from January 2021 ( https://paylesspower.com/blog/electric-rates-by-state/ ) and I was able to copy the table of data into a tab delimited file : https://github.com/itcharlie/ev-calc-pricing/blob/main/electric_rates.txt

I created a new copy of my perl script ( https://github.com/itcharlie/ev-calc-pricing/blob/main/generateevchargepricereport.pl ) where I read the tab delimited file like so:


my $state_rates_fh;
my %electric_rate;

open( $state_rates_fh, "<", "electric_rates.txt" )
        or die "Unable to open file:   $!\n";     

while (<$state_rates_fh> ) {
    my @line_data =  split('\t', $_);
    $electric_rate{ $line_data[0] } = $line_data[1] ;
}
and generate total pricing per state.

foreach my $state (sort keys %electric_rate )  {
    my $total_price = $cars{'EV'}->{$ev_brand}->{$model}->{‘battery_size’}  * ( $electric_rate{$state} / 100 ) ;
    say “$state: \$ ” .  sprintf(“%.2f” , $total_price);
}
which resulted as the following output :
0-100% battery charge price by State:
--------------------------------------------------
Alabama : $ 10.15
Alaska : $ 17.48
Arizona : $ 9.59
Arkansas : $ 7.72
California : $ 17.57
Colorado : $ 9.95
Connecticut : $ 17.46
Delaware : $ 9.65
District Of Columbia : $ 10.05
Florida : $ 9.55
Georgia : $ 8.97
Hawaii : $ 25.05
Idaho : $ 8.24
...

From this data I learned that Oklahoma has the cheapest electric rates and it would take a total of $7.31 dollars in electricity to charge a 2021 Tesla Model 3 with an all electric range of 353 miles. Using the same car as an example, Hawaii is the most expensive state with a total of $25.05 dollars in electricity charge.

Thank you for your time and I hope you enjoyed this post.

Calculating EV battery charge pricing with Perl

Presently I have great interest in “EVs” Electric Vehicles but I haven’t seen any data on how much it would cost to charge an electric vehicle from 0 % to 100 % battery charge at home in NYC ( So I wrote a Perl script to do just that ) but before we dig in into it I explain a few things about Electric Vehicles.

Electric Vehicles will have a battery capacity that is represented by kilowatt-hour units or kWh for short.

An EV’s driving range is represented in miles units ( In the US ) and the average mileage is determined by the EPA battery range rating ( the bigger the battery capacity usually means the more driving range you will have in a car ) after conducting a few tests ( so in reality your mileage will vary ).

Electric vehicles have an onboard charger which determines its charging rate in Kilowatt per Hour and it varies by car makers. Most EV car owners will install a Level 2 charger that is usually capable of charging cars up to 7.2 kWH rate using 220 volt electric circuit with 32 amps of power ( but there are chargers that can go at a higher rate ).

Ok now that I explained a few things lets dig into the data used to make my script.

I checked my electric bill and found that my electricity rate in NYC is $0.13 cents per kWh.

For comparison I phoned a friend in Florida to get electricity rates where he lives which is $ 0.07 cents per kWh. ( Almost half of NY rate )

I took as an example this car a 2021 Tesla Model 3 Long Range with a battery capacity of 82kWh. It has an EPA mileage of 353 miles.


#### Tesla Model 3 
#
say "Tesla Model 3 2021 Long Range: 82kwh battery pack";
say "All Electric range: 353 miles";
my $tesla_total_price = 82 * .13 ;
my $tesla_total_price_fl = 82 * .07 ;
my $tesla_charge_time = 82 / 7.2;  # 7.2 is the onboard charger rate ( it can also be 3.3 kwh  rate )  
my $tesla_miles_per_kWh = 353 / 82;

say "NYC Full charge price: \$ " .  sprintf("%.2f" , $tesla_total_price);
say "FL Full charge price: \$ " .  sprintf("%.2f" , $tesla_total_price_fl);
say "Time to charge: " . sprintf("%.2f" , $tesla_charge_time) . " hours";
say "Miles per kWh : " . sprintf("%.2f" , $tesla_miles_per_kWh) . " miles";

print "\n";
which will output the following:
Tesla Model 3 2021 Long Range: 82kwh battery pack
All Electric range: 353 miles
NYC Full charge price: $ 10.66
FL Full charge price: $ 5.74
Time to charge: 11.39 hours
Miles per kWh : 4.30 miles

$10.66 dollars for a 353 miles in New York City driving is pretty sweet deal!

I looked into a few other cars and started to copy and paste code which resulted in this script: https://github.com/itcharlie/ev-calc-pricing/blob/main/evchargeprice_calculator.pl

and of course there is more than one way to do it so I rewrote the script with a Hash of EV cars: https://github.com/itcharlie/ev-calc-pricing/blob/main/rewriteevchargepricecalculator.pl



#!/usr/bin/perl
use strict;
use warnings;

use Data::Dumper;
use feature 'say';


my %cars;

$cars{'EV'}->{'KIA'}->{'NIRO'} = { 'year' => 2020 , 'battery_size' => 64, 'onboard_charger_rate' => 7.2 , 'aer' => 239 };
$cars{'EV'}->{'TESLA'}->{'MODEL 3'} = { 'year' => 2021 , 'battery_size' => 82, 'onboard_charger_rate' => 7.2 , 'aer' => 353 };
$cars{'EV'}->{'CHEVY'}->{'BOLT'} = { 'year' => 2021 , 'battery_size' => 60, 'onboard_charger_rate' => 7.2 , 'aer' => 259 };

my %electric_rate;

$electric_rate{'NY'} = '0.13';
$electric_rate{'FL'} = '0.07';

foreach my $ev_brand ( keys %{$cars{'EV'}} ) {

    print "-" x 50;

    foreach my $model ( keys %{$cars{'EV'}->{$ev_brand}} )  {
        print "\n";
        say "$ev_brand  $model $cars{'EV'}->{$ev_brand}->{$model}->{'year'}";
        say "All electric range: $cars{'EV'}->{$ev_brand}->{$model}->{'aer'} miles";
        my $charge_time = $cars{'EV'}->{$ev_brand}->{$model}->{'battery_size'}  / $cars{'EV'}->{$ev_brand}->{$model}->{'onboard_charger_rate'} ; 
        my $miles_per_kWh =  $cars{'EV'}->{$ev_brand}->{$model}->{'aer'}   /  $cars{'EV'}->{$ev_brand}->{$model}->{'battery_size'}  ;
        say "Time to charge: " . sprintf("%.2f" , $charge_time ) . " hours";
        say "Miles per kWh : " . sprintf("%.2f" , $miles_per_kWh) . " miles";
        print "\n";

        foreach my $state ( keys %electric_rate )  {
           my $total_price = $cars{'EV'}->{$ev_brand}->{$model}->{'battery_size'}  * $electric_rate{$state} ;
           say "$state state 0-100% battery charge price: \$ " .  sprintf("%.2f" , $total_price);
        }
    }
}
 

Thank you for your time and hope you enjoyed this post!