diff --git a/photostats/__main__.py b/photostats/__main__.py index 4ff9c4c..174e8ef 100644 --- a/photostats/__main__.py +++ b/photostats/__main__.py @@ -2,6 +2,7 @@ from photostats import get_exif # type: ignore from photostats import lenses # type: ignore +from photostats import camera # type: ignore def parse_args(): @@ -16,6 +17,7 @@ def main(): photos = get_exif.get_photos(args.path) exif = get_exif.get_exif(photos) lenses.main(exif, args.graphpath) + camera.main(exif, args.graphpath) if __name__ == '__main__': diff --git a/photostats/camera.py b/photostats/camera.py new file mode 100644 index 0000000..b1e0f1e --- /dev/null +++ b/photostats/camera.py @@ -0,0 +1,57 @@ +"""Obtain camera information for statistics and graphing.""" + +from collections import Counter +from typing import Tuple + +from photostats import get_exif +from photostats.utils import create_plot + + +def get_camera_make_model(exif_list: list) -> Tuple[Counter, Counter, Counter]: + """Obtain camera make and model for each photo passed in. + + Depending on how complex your photo collection is, there may be no difference in the three values returned.\ + But if you have more than one camera from the same company, then these numbers may diverge. + + :param exif_list: A list of photo exif metadata. + :returns: For maximum flexibility, returns a tuple of lists - one of make, one of model, and one of make/model. + """ + make_list = [] + model_list = [] + make_model_list = [] + for data in exif_list: + make_list.append(data.get('Exif.Image.Make')) + model_list.append(data.get('Exif.Image.Model')) + make_model_list.append(f"{data.get('Exif.Image.Make')} {data.get('Exif.Image.Model')}") + return Counter(make_list), Counter(model_list), Counter(make_model_list) + + +def main(exif, graph_path): + make_count, model_count, make_model_count = get_camera_make_model(exif) + print("\nMake count:") + for make, count in make_count.items(): + print(f'{make} : {count}') + create_plot.create_plot(make_count.keys(), make_count.values(), x_label="Make/Company", y_label="Number of Photos", + title="Number of Photos Taken with a camera per company", graph_path=graph_path, + graph_filename="camera_make") + print("\nModel Count:") + for model, count in model_count.items(): + print(f'{model} : {count}') + create_plot.create_plot(model_count.keys(), model_count.values(), x_label="Camera Model", + y_label="Number of Photos", title="Number of Photos Taken with a camera model per company", + graph_path=graph_path, graph_filename="camera_model") + print("\nMake-Model Count:") + for make_model, count in make_model_count.items(): + print(f'{make_model} : {count}') + create_plot.create_plot(make_model_count.keys(), make_model_count.values(), x_label="Camera Make/Model", + y_label="Number of Photos", + title="Number of Photos Taken with a camera Make/Model per company", + graph_path=graph_path, graph_filename="camera_make_model") + + +if __name__ == '__main__': # pragma: no cover + test_directory = "/media/Photos/My Photos 2005 and on/2020/" + test_graph_path = "/home/ermesa/tmp/photostats" + test_photos = get_exif.get_photos(test_directory) + test_exif = get_exif.get_exif(test_photos) + main(test_exif, test_graph_path) diff --git a/photostats/lenses.py b/photostats/lenses.py index 82360f0..0ba45d9 100644 --- a/photostats/lenses.py +++ b/photostats/lenses.py @@ -24,7 +24,7 @@ def get_lens_make_model(exif_list: list) -> dict: def get_focal_length(exif_list: list) -> dict: """Obtain focal length for each photo passed in. - :param exif_list: A list of photo files. + :param exif_list: A list of photo exif metadata. :returns: A Counter dictionary, counting the focal length of lenses. """ focal_length_list = [] diff --git a/pypi.rst b/pypi.rst index c8d1bd5..7a37e77 100644 --- a/pypi.rst +++ b/pypi.rst @@ -15,6 +15,9 @@ This is a Python package that will eventually have a bunch of utilities for runn your photos based on EXIF data. By using exiv-based library, it can also read data from RAW files. +Currently will print output to the commandline and produce a bar graph for each + category. + usage: __main__.py [-h] [-p PATH] [-g GRAPHPATH] optional arguments: @@ -31,7 +34,9 @@ EF17-40mm f/4L USM : 18 EF28-105mm f/3.5-4.5 USM : 80 -Followed by a graph of the above data. Once you exit the graph window, you will get. +55-200mm : 60 + +35mm : 23 Focal Length Count: @@ -39,20 +44,38 @@ Focal Length Count: 20 mm : 4 +28 mm : 3 + +35 mm : 23 + +55 mm : 12 + +60 mm : 10 + 63 mm : 5 -98 mm : 7 +64 mm : 3 + +65 mm : 4 70 mm : 41 +75 mm : 2 + +82 mm : 1 + +90 mm : 1 + +98 mm : 7 + 105 mm : 17 -28 mm : 3 +200 mm : 34 -82 mm : 1 +Make-Model Count: -65 mm : 4 +Canon Canon EOS Rebel T6s : 181 -75 mm : 2 +Google Pixel : 143 -Followed by another graph. \ No newline at end of file +Motorola XT1096 : 96 \ No newline at end of file