pyrate.repositories package

Submodules

pyrate.repositories.aisdb module

class pyrate.repositories.aisdb.AISExtendedTable(db)[source]

Bases: pyrate.repositories.sql.Table

create()[source]
create_indices()[source]
drop_indices()[source]
class pyrate.repositories.aisdb.AISdb(options, readonly=False)[source]

Bases: pyrate.repositories.sql.PgsqlRepository

action_log_spec = {'cols': [('timestamp', 'timestamp without time zone DEFAULT now()'), ('action', 'TEXT'), ('mmsi', 'integer NOT NULL'), ('ts_from', 'timestamp without time zone'), ('ts_to', 'timestamp without time zone'), ('count', 'integer NULL')], 'constraint': ['CONSTRAINT action_log_pkey PRIMARY KEY (timestamp, action, mmsi)'], 'indices': [('ts_idx', ['timestamp']), ('action_idx', ['action']), ('mmsi_idx', ['mmsi'])]}
clean_db_spec = {'cols': [('MMSI', 'integer'), ('Time', 'timestamp without time zone'), ('Message_ID', 'integer'), ('Navigational_status', 'integer'), ('SOG', 'double precision'), ('Longitude', 'double precision'), ('Latitude', 'double precision'), ('COG', 'double precision'), ('Heading', 'double precision'), ('IMO', 'integer null'), ('Draught', 'double precision'), ('Destination', 'character varying(255)'), ('Vessel_Name', 'character varying(255)'), ('ETA_month', 'integer'), ('ETA_day', 'integer'), ('ETA_hour', 'integer'), ('ETA_minute', 'integer'), ('source', 'smallint'), ('ID', 'BIGSERIAL PRIMARY KEY')], 'indices': [('dt_idx', ['Time']), ('imo_idx', ['IMO']), ('lonlat_idx', ['Longitude', 'Latitude']), ('mmsi_idx', ['MMSI']), ('msg_idx', ['Message_ID']), ('source_idx', ['source']), ('mmsi_imo_idx', ['MMSI', 'IMO'])]}
clean_imo_list = {'cols': [('mmsi', 'integer NOT NULL'), ('imo', 'integer NULL'), ('first_seen', 'timestamp without time zone'), ('last_seen', 'timestamp without time zone')], 'constraint': ['CONSTRAINT imo_list_pkey PRIMARY KEY (mmsi, imo)']}
create()[source]

Create the tables for the AIS data.

dirty_db_spec = {'cols': [('MMSI', 'bigint'), ('Time', 'timestamp without time zone'), ('Message_ID', 'integer'), ('Navigational_status', 'integer'), ('SOG', 'double precision'), ('Longitude', 'double precision'), ('Latitude', 'double precision'), ('COG', 'double precision'), ('Heading', 'double precision'), ('IMO', 'integer null'), ('Draught', 'double precision'), ('Destination', 'character varying(255)'), ('Vessel_Name', 'character varying(255)'), ('ETA_month', 'integer'), ('ETA_day', 'integer'), ('ETA_hour', 'integer'), ('ETA_minute', 'integer'), ('source', 'smallint'), ('ID', 'BIGSERIAL PRIMARY KEY')], 'indices': [('dt_idx', ['Time']), ('imo_idx', ['IMO']), ('lonlat_idx', ['Longitude', 'Latitude']), ('mmsi_idx', ['MMSI']), ('msg_idx', ['Message_ID']), ('source_idx', ['source']), ('mmsi_imo_idx', ['MMSI', 'IMO'])]}
double_type = 'double precision'
get_message_stream(mmsi, from_ts=None, to_ts=None, use_clean_db=False, as_df=False)[source]

Gets the stream of messages for the given mmsi, ordered by timestamp ascending

get_messages_for_vessel(imo, from_ts=None, to_ts=None, use_clean_db=False, as_df=False)[source]
imolist_db_spec = {'cols': [('mmsi', 'integer NOT NULL'), ('imo', 'integer NULL'), ('first_seen', 'timestamp without time zone'), ('last_seen', 'timestamp without time zone')], 'constraint': ['CONSTRAINT imo_list_key UNIQUE (mmsi, imo)']}
ship_info(imo)[source]
sources_db_spec = {'cols': [('ID', 'SERIAL PRIMARY KEY'), ('timestamp', 'timestamp without time zone DEFAULT now()'), ('filename', 'TEXT'), ('ext', 'TEXT'), ('invalid', 'integer'), ('clean', 'integer'), ('dirty', 'integer'), ('source', 'integer')]}
status()[source]
truncate()[source]

Delete all data in the AIS table.

update()[source]

Updates (non-destructively) existing tables to new schema

pyrate.repositories.aisdb.load(options, readonly=False)[source]

pyrate.repositories.file module

class pyrate.repositories.file.FileRepository(path, allowedExtensions=None, recursive=True, unzip=False)[source]

Bases: object

close()[source]
iterfiles()[source]

Iterate files in this file repository. Returns a generator of 3-tuples, containing a handle, filename and file extension of the current opened file.

status()[source]
pyrate.repositories.file.load(options, readonly=False)[source]

pyrate.repositories.sql module

Classes for connection to and management of database tables

PgsqlRepository

Sets up a connection to a pyrate database repository

Table

Used to encapsulate a pyrate database table

class pyrate.repositories.sql.PgsqlRepository(options, readonly=False)[source]

Bases: object

connection()[source]
class pyrate.repositories.sql.Table(db, name, cols, indices=None, constraint=None, foreign_keys=None)[source]

Bases: object

A database table

copy_from_file(fname, columns)[source]
create()[source]

Creates tables in the database

create_indices()[source]
drop_indices()[source]
get_name()[source]
insert_row(data)[source]

Inserts one row into the table

insert_rows_batch(rows)[source]

Inserts a number of rows into the table

Parameters:rows (list) – A list of dicts of (column, value) pairs
status()[source]

Returns the approximate number of records in the table

Returns:
Return type:integer
truncate()[source]

Delete all data in the table.

pyrate.repositories.sql.load(options, readonly=False)[source]

Module contents