Ejemplo n.º 1
0
def test_disable_print_globally():
    stream = io.StringIO()
    timebudget._default_recorder.out_stream = stream
    timebudget.set_quiet()
    assert len(stream.getvalue()) == 0
    with timebudget("nothing much"):
        time.sleep(0.01)
    out = stream.getvalue()
    assert len(out) == 0, "Failed to disable immediate printing"
    timebudget.set_quiet(False)
Ejemplo n.º 2
0
import methodtools
from timebudget import timebudget

from jyotisha.panchaanga.spatio_temporal import daily
from jyotisha.panchaanga.temporal import time, set_constants, ComputationSystem, AngaType
from jyotisha.panchaanga.temporal.festival import FestivalInstance
from jyotisha.panchaanga.temporal.festival.applier import tithi_festival, ecliptic, solar, vaara, rule_repo_based, \
  FestivalAssigner
from jyotisha.panchaanga.temporal.time import Date
from jyotisha.panchaanga.temporal.tithi import ShraddhaTithiAssigner
from jyotisha.panchaanga.temporal.zodiac.angas import Tithi
from jyotisha.util import default_if_none
from sanskrit_data import collection_helper
from sanskrit_data.schema import common

timebudget.set_quiet(True)  # don't show measurements as they happen
# timebudget.report_at_exit()  # Generate report when the program exits

set_constants()


class Panchaanga(common.JsonObject):
    """This class enables the construction of a panchaanga for arbitrary periods, with festival_id_to_instance.
  
    Generally, which days is a given festival associated with (esp pre-sunrise events)? We follow the same conventions as the adyatithi repo.
    """
    LATEST_VERSION = "0.0.4"

    def __init__(self,
                 city,
                 start_date,
Ejemplo n.º 3
0
import types
import logging
import dedupe.variables
import dedupe.variables.base as base
from dedupe.variables.base import MissingDataType
from dedupe.variables.interaction import InteractionType
from timebudget import timebudget

for _, module, _ in pkgutil.iter_modules(dedupe.variables.__path__,
                                         'dedupe.variables.'):
    __import__(module)

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
FIELD_CLASSES = {k: v for k, v in base.allSubclasses(base.FieldType) if k}
timebudget.set_quiet()


class Distances(object):

    def __init__(self, fields):

        primary_fields, variables = typifyFields(fields)
        self.primary_fields = primary_fields
        self._derived_start = len(variables)

        variables += interactions(fields, primary_fields)
        variables += missing(variables)

        self._missing_field_indices = missing_field_indices(variables)
        self._interaction_indices = interaction_indices(variables)
Ejemplo n.º 4
0
def local_spooky(no_full_screen: bool,
                 camera_resolution: str = '640x480',
                 **kwargs):
    timebudget.set_quiet()  # just print reports.
    if not no_full_screen:
        for _ in range(10):
            print("Will run full screen.  Press SPACEBAR key to exit...\n\n")
            time.sleep(0.05)
    spookifier = spooky.RoundRobinSpookifier(**kwargs)

    try:
        camera = cv2.VideoCapture(0)
        camera.set(cv2.CAP_PROP_FPS, 15)
        cam_width, cam_height = [
            int(hw) for hw in camera_resolution.split('x')
        ]
        camera.set(cv2.CAP_PROP_FRAME_WIDTH, cam_width)
        camera.set(cv2.CAP_PROP_FRAME_HEIGHT, cam_height)
        start_time = time.time()
        frame_cnt = 0
        recent_fps_time = None
        show_perf = True
        if no_full_screen:
            display = cv2.namedWindow("Spooky")
        else:
            display = cv2.namedWindow("Spooky", cv2.WND_PROP_FULLSCREEN)
            cv2.setWindowProperty("Spooky", cv2.WND_PROP_FULLSCREEN,
                                  cv2.WINDOW_FULLSCREEN)
        while True:
            frame_cnt += 1
            total_fps = frame_cnt / (time.time() - start_time)
            if (frame_cnt % 3 == 0) and (show_perf):
                if recent_fps_time:
                    current_fps = 3 / (time.time() - recent_fps_time)
                else:
                    current_fps = float("nan")
                recent_fps_time = time.time()
                clear_screen()
                print(
                    f"------------ At frame {frame_cnt} getting {current_fps:.1f}fps. Avg is {total_fps:.2f}fps"
                )
                timebudget.report('process_npimage', reset=True)
            status_code, img = camera.read()
            print(f"Captured image of shape {img.shape}")
            img = spookifier.process_npimage(img, None)
            flipped = flip_img(img)
            cv2.imshow('Spooky', flipped)
            key = cv2.waitKey(1)
            if key == ord('e') or key == ord('E'):  # E = embedding capture
                e = spookifier.get_target_embedding()
                with open("embeddings.txt", "at") as f:
                    f.write(str(e))
                    f.write("\n")
                    print("Recorded embedding")
            elif key == ord('d') or key == ord('D'):  # D = debug
                current_time = time.time()
                import pdb
                pdb.set_trace()
            elif key == ord('p') or key == ord('P'):  # P = perf data
                show_perf = not show_perf
            elif key == 32 or key == ord('Q') or key == ord('q'):
                print(f"Quitting")
                return
            elif key >= 0:
                print(f"Key #{key} pressed.  No action for this key.")
    finally:
        del (camera)