Caliber Conversion Finder

An app by Sean Newton, for GunWiki.net

If this application has helped you, please consider making a small donation to GunWiki. Particularly if this app has shown you how to avoid buying an $80 caliber conversion by picking up one or two inexpensive parts!

Please note that the instructions contain some non-obvious information you should probably read before you just start clicking away. Of course, if you really want to just start clicking, feel free.

<% use strict; my %OwnedConversions; my %OwnedParts; my %DesiredConversions; my %DesiredParts; my $dbh=CS::MakeConnect('gunwiki') or die "Can't connect to host!"; my %Machines=CS::LoadHash($dbh, 'calconv_machine', 'id,descr'); my $Action=$Request->QueryString('go'); my %Conversion=CS::LoadHash($dbh, 'calconv_conversion', 'id,descr'); my %MachConv=CS::LoadHash($dbh, 'calconv_conversion', 'id,machine'); my $MachineList=$Request->QueryString('ml'); $MachineList='' unless($MachineList=~m/^[\d,]+$/); my $Gray ='#A0A0A0'; my $Green ='#80FF80'; my $Red ='#FF4040'; my $Yellow='#FFFF80'; %>

<% if($Action eq '') { my %MachinePop=CS::LoadHash($dbh, 'calconv_conversion', 'machine,count(*)', '1=1 GROUP BY machine'); %>Please choose which machine you wish to look at conversions for. Be warned that although you may select multiple machines, the next caliber conversion lists will get very long if you do so.
So realistically, unless you intend to mix and match parts across machines (which is possible in some cases), you should only run one machine at a time.

Which Dillon presses do you want to consider conversions for?

<% foreach (sort keys %Machines) { next unless($MachinePop{$_} ne ''); printf "\n", $_, $Machines{$_}, $MachinePop{$_}; } %>
 PressConversions On File
%s%s

In case you can't find the caliber you're looking for, you may request a new conversion here.
I don't have a lot of major connections, but I do periodically beg Dillon and Brian Enos for more info. <% $dbh->disconnect; return; } elsif($Action eq 'Choose Machines') { foreach(keys %Machines) { $MachineList.="$_,"if($Request->QueryString('machine_'.$_) eq 'on'); } $MachineList=~s/,$//; } %>

Back to Machine Selection

<% if($MachineList ne '') { %><% } { my @MachineArr=split(',', $MachineList); foreach my $Machine (@MachineArr) { my %MachConversions=CS::LoadHash($dbh, 'calconv_conversion', 'id,machine', 'machine='.$Machine); my @List; my $Count; foreach(sort { $Conversion{$a} cmp $Conversion{$b} } keys %MachConversions) { my $Line; ++$Count; my ($CheckHave, $CheckWant, $CheckDontCare); if($Request->QueryString('cal_'.$_) eq 'H') { $CheckHave=' CHECKED'; $OwnedConversions{$_}=1; } elsif($Request->QueryString('cal_'.$_) eq 'W') { $CheckWant=' CHECKED'; $DesiredConversions{$_}=1; } else { $CheckDontCare=' CHECKED'; } $Line.=''.$Conversion{$_}.''; $Line.=""; $Line.=""; $Line.=""; push @List, $Line; } my $Count=0; my $Cols=3; my $Buf=sprintf "\n", $Machines{$Machine};; while($Count<$Cols) { $Buf.="\n"; $Count++; $Buf.='' if($Count<$Cols); } $Buf.=''; $Count=1; my $Lines=0; my $PerColumn=int(@List/$Cols); ++$PerColumn if(@List/$Cols); # printf "Columns requested: %d, number of calibers in block: %d, per column: %f\n", $Cols, scalar(@List), $PerColumn; my $Lines=0; while(($Lines*$Cols)<@List) { $Buf.=sprintf "\n", ($Lines%2)?'#F0F0F0':'#FFFFFF'; $Buf.=@List[$Lines]; my $Across=1; while($Across<$Cols) { $Buf.=''; $Buf.=@List[($Lines+($PerColumn*$Across))]; ++$Across; } ++$Lines; } $Buf.='
Conversions for %s
CaliberHaveWantDon't Care 
 
'; print $Buf; } } %> <% if($Request->QueryString('go') ne '') { my %PartType=CS::LoadHash($dbh, 'calconv_parttype', 'id,descr'); my (%PartID, %PartDesc, %PartFriendly); { my ($id, $type, $designation); my $sth=CS::SelectRecs($dbh, 'calconv_part', 'id,parttype,designation', '', \$id, \$type, \$designation); while($sth->fetch) { $PartID{$id}=$type; $PartDesc{$id}=$designation; $PartFriendly{$id}=$PartType{$type}.' '.$designation } $sth->finish; } my %SpreadOut; my %TypeColumns; { my ($conversion, $part); my $sth=CS::SelectRecs($dbh, 'calconv_conversion_parts', 'conversion,part', undef, \$conversion, \$part); while($sth->fetch) { next unless($OwnedConversions{$conversion}||$DesiredConversions{$conversion}); $TypeColumns{$PartType{$PartID{$part}}}=1; $SpreadOut{$conversion}{$PartType{$PartID{$part}}}.=','.$part; if($OwnedConversions{$conversion}) { $OwnedParts{$part}=1; } if($DesiredConversions{$conversion}) { $DesiredParts{$part}=1; } } $sth->finish; } if($Request->QueryString('go') eq 'Spreadsheet View') { print "Legend:
"; print "\n"; print "\n"; print "\n"; print "\n"; print "
Have
Don't have, want
N/A

\n"; print "\n"; foreach(sort keys %TypeColumns) { print " \n"; } print "\n"; foreach my $conversion (sort keys %SpreadOut) { next unless($DesiredConversions{$conversion}||$OwnedConversions{$conversion}); my $CellColor=$Green; my ($Missing, $ConvBuf); foreach my $blah (sort keys %TypeColumns) { my $Temp=$SpreadOut{$conversion}{$blah}; $Temp=~s/^,//; my $Cell; my $bgcolor=$Gray; my @List=split (',', $Temp); $Cell.='
MachineCaliber$_
' if(@List gt 1); foreach my $Part (@List) { my $PartDescription="".$PartDesc{$Part}.''; ++$Missing; if($OwnedParts{$Part} ) { $bgcolor='#80FF80'; } elsif($DesiredParts{$Part}) { if($DesiredConversions{$conversion}) { $bgcolor='#FF4040'; } else { $bgcolor='#FFFF80'; } } else { $bgcolor=$Gray; } if(@List gt 1) { $Cell.=''; } else { $Cell=$PartDescription; } } if(@List gt 1) { $ConvBuf.="
'.$PartDescription.'
$Cell
\n"; } else { $ConvBuf.=" $Cell \n"; } } printf "%s%s$ConvBuf\n", $Machines{$MachConv{$conversion}}, 'FFFFFF', $conversion, $Conversion{$conversion}; } print "\n"; } else { my %Manufacturer=CS::LoadHash($dbh, 'calconv_manufacturer', 'id,descr'); my %PartManufacturers=CS::LoadHash($dbh, 'calconv_part', 'id,manufacturer'); my %PartSKUs=CS::LoadHash($dbh, 'calconv_part', 'id,sku'); print "\n

Parts Used For Conversion:
\n\n"; foreach(sort { $PartFriendly{$a} cmp $PartFriendly{$b} } keys %DesiredParts) { my $bgcolor=$OwnedParts{$_}?'#80FF80':'#FF4040'; $bgcolor="\"$bgcolor\""; printf "\n", $OwnedParts{$_}?'HAVE':'NEED', $Manufacturer{$PartManufacturers{$_}}, $PartType{$PartID{$_}}, $PartDesc{$_}, $_, $PartSKUs{$_}; } } } $dbh->disconnect; %>
StatusManufacturerItemSKU
%s%s%s %s%s