Skip to content

Instantly share code, notes, and snippets.

View jeffbass's full-sized avatar

Jeff Bass jeffbass

View GitHub Profile
@jeffbass
jeffbass / generate_text_files.py
Created February 8, 2021 18:54
Python program to generate text files of various sizes
#!/usr/bin/env python3
""" Generate text files for testing Evernote v10.x
Generates text files of different sizes. The text files have increasing numbers
of lines. The number of words per line is random, between min_words and
max_words. The text that provides the pool of words is The Gettysburg Address.
Text files are named ENtest500.txt, ENtest1000, ENtest1500, ENtest2000, ...
where the number portion represents the number of text lines in the file.
Author: Jeff Bass, https://github.com/jeffbass
@jeffbass
jeffbass / driveway.yaml
Created August 21, 2020 23:44
Yaml file for Driveway imagenode
# Settings for imagenode.py picam motion detector
---
node:
name: Driveway
queuemax: 50
patience: 10
stall_watcher: True
heartbeat: 10
send_type: jpg
print_settings: False
@jeffbass
jeffbass / list_num_images_by_date.py
Created July 31, 2020 21:37
Example of a tiny Python data analysis program to count images by date
# Use subprocess.run() to list the number of imagehub_data images for each date
#
# Copyright (c) 2018 by Jeff Bass.
# License: MIT, see LICENSE for more details.
import os
import subprocess
def n_images(dir):
command = 'ls -l ' + dir + ' | wc -l'
@jeffbass
jeffbass / report temperature.py
Created July 31, 2020 21:06
Example method of ChatBot class that reports current temperature
# this is an example method from the Librarian ChatBot class
# note that this is a simple example with a few hard coded imagenode names
def report_temperature(self, locations):
""" report temperature by location
This is a very awkward test matching of location and temperature.
Needs to be made much more sophistcated than if / else / etc.
Parameters:
@jeffbass
jeffbass / librarian.py
Last active July 31, 2020 21:06
Working draft of Librarian.py main program
"""librarian: answer questions using imagehub event messages, images sensor data
Answers questions about currrent and past observations of imagenodes, including
inputs from PiCameras, USB Webcams, temperature sensors, etc.
Gathers image, sensor and event logs from imagehubs. Does analysis such as
object detection and classification on images. Monitors operational status of
imagenodes and imagehubs. Manages multiple modes of communications for queries
and alerts.
@jeffbass
jeffbass / HubData_class.py
Last active July 31, 2020 21:17
The HubData class of the Librarian
"""data_tools: data tools including classes, methods and attributes
Provides a variety of classes to hold, transfer, analyze, transform and query
the various data in the data library and in the imagehubs accessible to the
librarian.
Copyright (c) 2018 by Jeff Bass.
License: MIT, see LICENSE for more details.
"""
@jeffbass
jeffbass / imagehub.py
Last active April 12, 2020 17:25
An Imagehub code snippet for my PyCon 2020 presentation
#imagehub.py snippet
# (all the imports, logging setup hidden for now)
settings = Settings() # get settings from YAML file
hub = ImageHub(settings) # start ImageWriter, Timers, etc.
# forever event loop: receive & process images and text from imagenodes
while True:
try:
with Patience(hub.patience):
text, image = hub.receive_next()
except Patience.Timeout: # if no timely message from any node
@jeffbass
jeffbass / test_create_image_jpg_buffer.py
Created March 24, 2020 21:36
imageZMQ test program to check jpg_buffer type, size and dimensions
"""test sending a jpg buffer and check type & size of buffer
A simple test program that creates an image, then converts it to a
jpg_buffer and checks the type(), ndim, size and shape of the jpg_buffer.
This program tests some imports and some OpenCV functions, as well.
Open Source Licensed under MIT License (MIT)
Copyright (c) 2020, Jeff Bass, jeff@yin-yang-ranch.com
"""
@jeffbass
jeffbass / badge_fetch.rst
Last active February 13, 2020 06:20
Fetch RST implementation of badges for README.rst from shields.io & DOI

Dependencies and Installation

pyversions pypi

imagezmq: Transporting OpenCV images

imagezmq is a set of Python classes that transport OpenCV images from one computer to another using PyZMQ messaging. For example, here is a screen on a Mac computer showing simultaneous video streams from 8 Raspberry Pi cameras:

image