App-PhotoDB

 view release on metacpan or  search on metacpan

lib/App/PhotoDB/funcs.pm  view on Meta::CPAN

		$text =~ s/_/ /g;
		return $text;
	} else {
		print "Could not deduce valid keyword from SQL\n";
		return;
	}
}

=head2 parselensmodel

Parse lens model name to guess some data about the lens. Either specify which parameter you want
to be returned as a string, or expect a hashref of all params to be returned. Currently supports guessing
C<minfocal> (minimum focal length), C<maxfocal> (maximum focal length), C<zoom> (whether this is a zoom lens)
and C<aperture> (maximum aperture of lens).

=head4 Usage

    my $aperture = &parselensmodel($model, 'aperture');
    my $lensparams = &parselensmodel($model);

=head4 Arguments

lib/App/PhotoDB/funcs.pm  view on Meta::CPAN

	my $discontinued = $href->{discontinued} // 2100;

	# Reformat datecode for reliable matching
	$datecode = uc($datecode);
	$datecode =~ s/[^A-Z0-9]//g;

	# Map alphabet to numbers
	my %h;
	@h{'A' .. 'Z'} = (0 .. 25);

	my @guesses;

	# AB1234, B1234A, B123A
	# From 1960-2012, the date code is in the form of "AB1234". "A" indicates the factory. Prior to 1986, "A" is moved to the end.
	# "B" is a year code that indicates the year of manufacture. Canon increments this letter each year starting with A in 1960
	# Of the 4 digits, the first two are the month of manufacture. Sometimes the leading 0 is omitted.
	if ($datecode =~ /^[A-Z]?([A-Z])[0-9]{3,4}[A-Z]?$/ ) {
		my $dateletter = $1;
		my $epochstart = 1960;
		my $epochend = 2012;
		my $datenumber = $h{$dateletter};

		for (my $i=0; ; $i++) {
			my $guess = $epochstart + $datenumber + $i*26;

			# Stop if we go above the end date of the datecode epoch
			last if ($guess > $epochend);

			push(@guesses, $guess);
		}

	# From 2008, the date code is 10 digits. The first two correspond to the year & month of manufacture.
	# From 2008-2012 the month code runs from 38-97. In 2013, it is reset to 01. These are treated as different epochs.
	} elsif ($datecode =~ /^(\d{2})\d{8}$/ ) {
		my $datenumber = $1;

		# First epoch
		if ($datenumber >= 38 and $datenumber <= 97) {
			my $epochstart = 2008;
			my $epochend = 2012;
			my $start = 38;

			my $guess = $epochstart + int(($datenumber - $start) / 12);
			push(@guesses, $guess);
		}

		# Second epoch
		{
			my $epochstart = 2013;
			my $epochend = 2100;
			my $start = 1;

			for (my $i=0; ; $i++) {
				my $guess = $epochstart + int((($datenumber + $i*100) - $start) / 12);
				last if ($guess > $epochend);
				push(@guesses, $guess);
			}
		}
	}

	# Now examine our guesses for plausibility based on when the lens was released & discontinued
	my @plausible;
	foreach my $guess (@guesses) {
		# Skip if our guess is before the lens was introduced
		next if ($guess < $introduced);

		# Stop if our guess is after the lens was discontinued
		next if ($guess > $discontinued);

		push(@plausible, $guess);
	}

	# If we narrowed it down to one year, return that. Otherwise, return nothing.
	if (scalar(@plausible) == 1) {
		return $plausible[0];
	}
	return;
}

=head2 choose_shutterspeed



( run in 0.789 second using v1.01-cache-2.11-cpan-748bfb374f4 )