Skip to content

Commit

Permalink
📷 Added Camera make/model stats
Browse files Browse the repository at this point in the history
It will automatically run after the lens stats.
  • Loading branch information
djotaku committed Mar 23, 2020
1 parent aff2535 commit 76ea7e8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 8 deletions.
2 changes: 2 additions & 0 deletions photostats/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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__':
Expand Down
57 changes: 57 additions & 0 deletions photostats/camera.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion photostats/lenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
37 changes: 30 additions & 7 deletions pypi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -31,28 +34,48 @@ 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:

17 mm : 14

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.
Motorola XT1096 : 96

0 comments on commit 76ea7e8

Please sign in to comment.