예제 #1
0
    def __init__(self, args):
        self.test_config = TestConfig.load_from_file(args.tests)
        self.classifier_config = Config.load_from_file(args.classify_config)
        model_file = self.classifier_config.classify.model
        if args.model_file:
            model_file = args.model_file

        path, ext = os.path.splitext(model_file)
        keras_model = False
        if ext == ".pb":
            keras_model = True
        self.clip_classifier = ClipClassifier(
            self.classifier_config,
            self.classifier_config.classify_tracking,
            model_file,
            keras_model,
        )
        # try download missing tests
        if args.user and args.password:
            api = UserAPI(args.server, args.user, args.password)
            out_dir = Path(self.test_config.clip_dir)
            if not out_dir.exists():
                out_dir.mkdir()
            for test in self.test_config.recording_tests:
                filepath = out_dir / test.filename
                if not filepath.exists():
                    if iter_to_file(out_dir / test.filename,
                                    api.download_raw(test.rec_id)):
                        logging.info("Saved %s", filepath)
        self.results = []
예제 #2
0
 def test_scheme(self):
     """Set up the test schema for TestCacophonyClient object."""
     cli = UserAPI(
         baseurl=defaults["apiURL"],
         username=defaults["defaultUsername"],
         password=defaults["defaultuserPassword"],
     )
     self.assertEqual(defaults["apiURL"], cli._baseurl)
예제 #3
0
    def setUp(self):
        """Initialize an instance of TestInfluxDBClient object."""
        # By default, raise exceptions on warnings
        warnings.simplefilter("error", FutureWarning)

        self.cli = UserAPI(
            baseurl=defaults["apiURL"],
            username=defaults["defaultUsername"],
            password=defaults["defaultuserPassword"],
        )
예제 #4
0
 def test_scheme(self):
     """Set up the test schema for mocked CacophonyServer object."""
     with requests_mock.Mocker() as m:
         m.register_uri(
             requests_mock.POST,
             "{apiURL}/authenticate_user".format(apiURL=defaults["apiURL"]),
             status_code=204,
         )
         cli = UserAPI(
             baseurl=defaults["apiURL"],
             username=defaults["defaultUsername"],
             password=defaults["defaultuserPassword"],
         )
         # print(m.last_request.body)
         self.assertEqual(defaults["apiURL"], cli._baseurl)
예제 #5
0
 def setUp(self):
     """Initialize an instance of mocked CacophonyServer object."""
     # By default, raise exceptions on warnings
     warnings.simplefilter("error", FutureWarning)
     with requests_mock.Mocker() as m:
         m.register_uri(
             requests_mock.POST,
             "{apiURL}/authenticate_user".format(apiURL=defaults["apiURL"]),
             status_code=204,
         )
         self.cli = UserAPI(
             baseurl=defaults["apiURL"],
             username=defaults["defaultUsername"],
             password=defaults["defaultuserPassword"],
         )
예제 #6
0
 def __init__(self, args):
     self.test_config = TestConfig.load_from_file(args.tests)
     self.classifier_config = Config.load_from_file(args.classify_config)
     if args.model_file:
         model_file = args.model_file
     self.track_extractor = TrackExtractor(self.classifier_config)
     # try download missing tests
     if args.user and args.password:
         api = UserAPI(args.server, args.user, args.password)
         out_dir = Path(self.test_config.clip_dir)
         if not out_dir.exists():
             out_dir.mkdir()
         for test in self.test_config.recording_tests:
             filepath = out_dir / test.filename
             if not filepath.exists():
                 if iter_to_file(
                     out_dir / test.filename, api.download_raw(test.rec_id)
                 ):
                     logging.info("Saved %s", filepath)
     self.results = []
예제 #7
0
    def test_version(self):
        """Test UserAPI.version"""
        with requests_mock.Mocker() as m:
            m.register_uri(
                requests_mock.POST,
                "{apiURL}/authenticate_user".format(apiURL=defaults["apiURL"]),
                status_code=204,
            )
            cli = UserAPI(
                baseurl=defaults["apiURL"],
                username=defaults["defaultUsername"],
                password=defaults["defaultuserPassword"],
            )
            # print(m.last_request.body)
            self.assertEqual(defaults["apiURL"], cli._baseurl)

            versionResult = cli.version
            print("version:{}".format(versionResult))
            self.assertTrue(isinstance(versionResult, str))
            self.assertTrue(len(versionResult) > 0)
예제 #8
0
def main():
    args = parse_args()
    api = UserAPI(args.server, args.user, args.password)
    out_dir = Path(args.out_folder)
    tests = []
    test_data = TestConfig(recording_tests=tests,
                           server=args.server,
                           clip_dir=args.out_folder)
    for rec_id in args.ids:
        rec_meta = api.get(rec_id)
        tracks = api.get_tracks(rec_id)
        filename = Path(rec_id).with_suffix(".cptv")
        fullpath = out_dir / filename
        tests.append(TestRecording.load_from_meta(rec_meta, tracks, filename))
        if not fullpath.exists():
            if iter_to_file(fullpath, api.download_raw(rec_id)):
                print("Saved {} - {}".format(rec_id, fullpath))
            else:
                print("error saving {}".format(rec_id))
    if os.path.exists(args.test_file):
        os.remove(args.test_file)
    with open(args.test_file, "w") as f:
        yaml.dump(test_data, f)
예제 #9
0
# %%
test = ""
str(test)
# %%
from cacophonyapi.user import UserAPI
from cacophonyapi.config import Config

# %%
config = Config().load_config(
    config_file=os.path.join(os.getcwd(), ".env", "defaultconfig.json"))

# %%

cp_client = UserAPI(
    baseurl=config.api_url,
    username=config.admin_username,
    password=config.admin_password,
)
cp_client.version

# %% [markdown]
# ### SHOW devices and groups

# %%
pd.DataFrame(cp_client.get_devices_as_json())

# %%
pd.DataFrame(cp_client.get_groups_as_json()["groups"])

# %% [markdown]
#